Search in sources :

Example 21 with NonExistingResource

use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.

the class ResourceResolverTest method testResolveRemovedVanityPath.

@Test
public void testResolveRemovedVanityPath() throws Exception {
    String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanity[0] + ".print.html");
    HttpServletRequest request = new FakeSlingHttpServletRequest(path);
    Resource res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    //remove vanityPath property
    rootNode.getProperty("sling:vanityPath").remove();
    saveMappings(session);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertTrue(res instanceof NonExistingResource);
    assertEquals("/" + vanity[0] + ".print.html", res.getPath());
    //restore vanityPath
    rootNode.setProperty("sling:vanityPath", vanity);
    saveMappings(session);
    //create new child with vanity path
    Node childNode = maybeCreateNode(rootNode, "rootChild", "nt:unstructured");
    childNode.setProperty("sling:vanityPath", "childVanity");
    childNode.addMixin("sling:VanityPath");
    saveMappings(session);
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/childVanity.print.html");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(childNode.getPath(), res.getPath());
    assertEquals(childNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(childNode.isSame(res.adaptTo(Node.class)));
    //remove node with vanity path
    childNode.remove();
    saveMappings(session);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertTrue(res instanceof NonExistingResource);
    assertEquals("/childVanity.print.html", res.getPath());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Node(javax.jcr.Node) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 22 with NonExistingResource

use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.

the class ResourceResolverTest method testResolveVanityPathWithUpdate.

@Test
public void testResolveVanityPathWithUpdate() throws Exception {
    String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanity[2] + ".print.html");
    HttpServletRequest request = new FakeSlingHttpServletRequest(path);
    Resource res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanity[2] + ".print.html/suffix.pdf");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html/suffix.pdf", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    //update vanityPath
    String[] vanityPathUpdated = new String[] { "testVanity", "testV", "testVanityUpdated" };
    rootNode.setProperty("sling:vanityPath", vanityPathUpdated);
    saveMappings(session);
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanityPathUpdated[2] + ".print.html");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanityPathUpdated[2] + ".print.html/suffix.pdf");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html/suffix.pdf", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanity[2] + ".print.html");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertTrue(res instanceof NonExistingResource);
    assertEquals("/" + vanity[2] + ".print.html", res.getPath());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Node(javax.jcr.Node) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 23 with NonExistingResource

use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.

the class ResourceResolverWithVanityBloomFilterTest method testResolveVanityPathWithUpdate.

@Test
public void testResolveVanityPathWithUpdate() throws Exception {
    String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanity[2] + ".print.html");
    HttpServletRequest request = new FakeSlingHttpServletRequest(path);
    Resource res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanity[2] + ".print.html/suffix.pdf");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html/suffix.pdf", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    //update vanityPath
    String[] vanityPathUpdated = new String[] { "testVanity", "testV", "testVanityUpdated" };
    rootNode.setProperty("sling:vanityPath", vanityPathUpdated);
    saveMappings(session);
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanityPathUpdated[2] + ".print.html");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanityPathUpdated[2] + ".print.html/suffix.pdf");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html/suffix.pdf", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanity[2] + ".print.html");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertTrue(res instanceof NonExistingResource);
    assertEquals("/" + vanity[2] + ".print.html", res.getPath());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Node(javax.jcr.Node) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 24 with NonExistingResource

use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.

the class ResourceResolverTest method testResolveRemovedResourceAlias.

@Test
public void testResolveRemovedResourceAlias() throws Exception {
    // define an alias for the rootPath
    String alias = "testAlias";
    rootNode.setProperty("sling:alias", alias);
    saveMappings(session);
    String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias + ".print.html");
    HttpServletRequest request = new FakeSlingHttpServletRequest(path);
    Resource res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias + ".print.html/suffix.pdf");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath, res.getPath());
    assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html/suffix.pdf", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
    //remove alias property
    rootNode.getProperty("sling:alias").remove();
    saveMappings(session);
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias + ".print.html");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertTrue(res instanceof NonExistingResource);
    assertEquals("/" + alias + ".print.html", res.getPath());
    //create new child with alias
    String childNodeName = "rootChildAlias";
    Node childNode = maybeCreateNode(rootNode, childNodeName, "nt:unstructured");
    childNode.setProperty("sling:alias", "childAlias");
    saveMappings(session);
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + rootPath + "/childAlias.print.html");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath + "/" + childNodeName, res.getPath());
    assertEquals(childNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(childNode.isSame(res.adaptTo(Node.class)));
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + rootPath + "/childAlias" + ".print.html/suffix.pdf");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertEquals(rootPath + "/" + childNodeName, res.getPath());
    assertEquals(childNode.getPrimaryNodeType().getName(), res.getResourceType());
    assertEquals(".print.html/suffix.pdf", res.getResourceMetadata().getResolutionPathInfo());
    assertNotNull(res.adaptTo(Node.class));
    assertTrue(childNode.isSame(res.adaptTo(Node.class)));
    //remove the child node with the alias
    childNode.remove();
    saveMappings(session);
    path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + rootPath + "/childAlias" + ".print.html");
    request = new FakeSlingHttpServletRequest(path);
    res = resResolver.resolve(request, path);
    assertNotNull(res);
    assertTrue(res instanceof NonExistingResource);
    assertEquals(rootPath + "/childAlias.print.html", res.getPath());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Node(javax.jcr.Node) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Aggregations

NonExistingResource (org.apache.sling.api.resource.NonExistingResource)24 Resource (org.apache.sling.api.resource.Resource)22 Test (org.junit.Test)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Node (javax.jcr.Node)10 FakeSlingHttpServletRequest (org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest)8 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)6 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)6 ValidationResult (org.apache.sling.validation.ValidationResult)3 ChildResource (org.apache.sling.validation.model.ChildResource)3 DefaultValidationResult (org.apache.sling.validation.spi.support.DefaultValidationResult)3 MergedResource (org.apache.sling.resourcemerger.impl.MergedResource)2 ChildResourceImpl (org.apache.sling.validation.impl.model.ChildResourceImpl)2 ResourceProperty (org.apache.sling.validation.model.ResourceProperty)2 ValidationModel (org.apache.sling.validation.model.ValidationModel)2 DefaultValidationFailure (org.apache.sling.validation.spi.support.DefaultValidationFailure)2 Expectations (org.jmock.Expectations)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1