forked from apache/sling-old-svn-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLING-4825:Add ability to handle webdav based DELETE requests
* Added tests
- Loading branch information
Satya Deep Maheshwari
committed
Jul 7, 2015
1 parent
81fc98d
commit 918466c
Showing
5 changed files
with
222 additions
and
1 deletion.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...sts/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavDeleteTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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.sling.launchpad.webapp.integrationtest; | ||
|
||
import junitx.framework.Assert; | ||
import org.apache.sling.commons.testing.integration.HttpTestBase; | ||
import org.junit.Test; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class WebdavDeleteTest extends HttpTestBase{ | ||
private final String testDir = "/sling-test/" + getClass().getSimpleName() + System.currentTimeMillis(); | ||
private final String testDirUrl = HTTP_BASE_URL + "/dav/" + testDir; | ||
|
||
private final String DEFAULT_HANDLER = "default-delete-handler"; | ||
private final String HANDLER_1 = "test-delete-handler-1"; | ||
private final String HANDLER_2 = "test-delete-handler-2"; | ||
|
||
private final String HANDLER_1_BKP = "backed-up-by-" + HANDLER_1; | ||
private final String HANDLER_2_BKP = "backed-up-by-" + HANDLER_2; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
testClient.mkdirs(HTTP_BASE_URL, testDir); | ||
|
||
Map<String, String> map = new HashMap<String, String>(); | ||
map.put("jcr:primaryType", "nt:unstructured"); | ||
testClient.createNode(HTTP_BASE_URL + testDir + "/" + HANDLER_1, map); | ||
testClient.createNode(HTTP_BASE_URL + testDir + "/" + HANDLER_2, map); | ||
testClient.createNode(HTTP_BASE_URL + testDir + "/" + DEFAULT_HANDLER, map); | ||
} | ||
|
||
@Override | ||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
testClient.delete(testDirUrl); | ||
} | ||
|
||
@Test | ||
public void testDelete() { | ||
try { | ||
testClient.delete(HTTP_BASE_URL + testDir + "/" + HANDLER_1); | ||
testClient.delete(HTTP_BASE_URL + testDir + "/" + HANDLER_2); | ||
testClient.delete(HTTP_BASE_URL + testDir + "/" + DEFAULT_HANDLER); | ||
|
||
Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, testClient.get(HTTP_BASE_URL + testDir + "/" + HANDLER_1)); | ||
Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, testClient.get(HTTP_BASE_URL + testDir + "/" + HANDLER_2)); | ||
Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, testClient.get(HTTP_BASE_URL + testDir + "/" + DEFAULT_HANDLER)); | ||
|
||
Assert.assertEquals(HttpServletResponse.SC_OK, testClient.get(HTTP_BASE_URL + testDir + "/" + HANDLER_1 + HANDLER_1_BKP + ".json")); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, testClient.get(HTTP_BASE_URL + testDir + "/" + HANDLER_2 + HANDLER_2_BKP + ".json")); | ||
|
||
} catch (IOException e) { | ||
Assert.fail(e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...src/main/java/org/apache/sling/launchpad/testservices/handlers/AbstractDeleteHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.sling.launchpad.testservices.handlers; | ||
|
||
import org.apache.jackrabbit.server.io.DeleteContext; | ||
import org.apache.jackrabbit.server.io.DeleteHandler; | ||
import org.apache.jackrabbit.webdav.DavException; | ||
import org.apache.jackrabbit.webdav.DavResource; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
|
||
public abstract class AbstractDeleteHandler implements DeleteHandler { | ||
|
||
protected String HANDLER_NAME = ""; | ||
protected String HANDLER_BKP; | ||
|
||
@Override | ||
public boolean delete(DeleteContext deleteContext, | ||
DavResource resource) throws DavException { | ||
try { | ||
deleteContext.getSession().getWorkspace().move(resource.getResourcePath(), resource.getResourcePath() + HANDLER_BKP); | ||
return true; | ||
} catch (RepositoryException e) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canDelete(DeleteContext deleteContext, | ||
DavResource resource) { | ||
try { | ||
Node nodeToDelete = deleteContext.getSession().getNode(resource.getResourcePath()); | ||
return HANDLER_NAME.equals(nodeToDelete.getName()); | ||
} catch (RepositoryException e) { | ||
return false; | ||
} | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...es/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.sling.launchpad.testservices.handlers; | ||
|
||
import org.apache.felix.scr.annotations.Component; | ||
import org.apache.felix.scr.annotations.Property; | ||
import org.apache.felix.scr.annotations.Service; | ||
import org.apache.jackrabbit.server.io.DeleteContext; | ||
import org.apache.jackrabbit.server.io.DeleteHandler; | ||
import org.apache.jackrabbit.webdav.DavException; | ||
import org.apache.jackrabbit.webdav.DavResource; | ||
import org.osgi.framework.Constants; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
|
||
@Component(metatype = true) | ||
@Property(name = Constants.SERVICE_RANKING, intValue = 2, propertyPrivate = false) | ||
@Service(value = { DeleteHandler.class }) | ||
public class TestDeleteHandler1 extends AbstractDeleteHandler{ | ||
|
||
public TestDeleteHandler1() { | ||
this.HANDLER_NAME = "test-delete-handler-1"; | ||
this.HANDLER_BKP = "backed-up-by-" + HANDLER_NAME; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...es/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.sling.launchpad.testservices.handlers; | ||
|
||
import org.apache.felix.scr.annotations.Component; | ||
import org.apache.felix.scr.annotations.Property; | ||
import org.apache.felix.scr.annotations.Service; | ||
import org.apache.jackrabbit.server.io.DeleteContext; | ||
import org.apache.jackrabbit.server.io.DeleteHandler; | ||
import org.apache.jackrabbit.webdav.DavException; | ||
import org.apache.jackrabbit.webdav.DavResource; | ||
import org.osgi.framework.Constants; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
|
||
@Component(metatype = true) | ||
@Property(name = Constants.SERVICE_RANKING, intValue = 2, propertyPrivate = false) | ||
@Service(value = { DeleteHandler.class }) | ||
public class TestDeleteHandler2 extends AbstractDeleteHandler { | ||
|
||
public TestDeleteHandler2() { | ||
this.HANDLER_NAME = "test-delete-handler-2"; | ||
this.HANDLER_BKP = "backed-up-by-" + HANDLER_NAME; | ||
} | ||
|
||
} |