/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xindice.webadmin;
import org.apache.xindice.webadmin.webdav.components.Delete;
import org.apache.xindice.webadmin.webdav.WebdavStatus;
import org.apache.xindice.xml.dom.DOMParser;
import org.apache.xindice.util.Configuration;
import org.apache.xindice.core.Collection;
public class DeleteTest extends MethodSetup {
public void setUp() throws Exception {
super.setUp();
method = new Delete();
}
public void testDeleteNullCollection() throws Exception {
// collection was not found: one or more intermediate collections do not exist
method.execute(request, response, new Location("/unknown"));
assertEquals(WebdavStatus.SC_NOT_FOUND, httpResponse.getStatus());
}
public void testDeleteNotExistingResource() throws Exception {
method.execute(request, response, new Location(collection.getCanonicalName() + "/doesnotexist"));
assertEquals(WebdavStatus.SC_NOT_FOUND, httpResponse.getStatus());
}
public void testDeleteExistingResource() throws Exception {
String name = "resource";
collection.setDocument(name, DOMParser.toDocument("<test/>"));
method.execute(request, response, new Location(collection.getCanonicalDocumentName(name)));
assertEquals(WebdavStatus.SC_NO_CONTENT, httpResponse.getStatus());
assertNull(collection.getDocument(name));
}
public void testDeleteCollectionWithDepth() throws Exception {
httpRequest.addHeader("Depth", "0");
method.execute(request, response, new Location(collection.getCanonicalName()));
assertEquals(WebdavStatus.SC_BAD_REQUEST, httpResponse.getStatus());
}
public void testDeleteCollection() throws Exception {
String name = "new";
Collection child = collection.createCollection(name, new Configuration(
DOMParser.toDocument(
"<collection compressed='true' name='" + name + "' inline-metadata='true'>" +
"<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
"</collection>"), false
));
method.execute(request, response, new Location(child.getCanonicalName()));
assertEquals(WebdavStatus.SC_NO_CONTENT, httpResponse.getStatus());
assertNull(collection.getCollection(name));
}
//TODO: test SC_FORBIDDEN
}