Search in sources :

Example 26 with FakeSlingHttpServletRequest

use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.

the class ResourceResolverWithVanityBloomFilterTest method testResolveVirtualHostHttps443.

@Test
public void testResolveVirtualHostHttps443() throws Exception {
    HttpServletRequest request = new FakeSlingHttpServletRequest("https", "virtual.host.com", -1, rootPath);
    Node virtualhost443 = mapRoot.getNode("map/https").addNode("virtual.host.com.443", "sling:Mapping");
    virtualhost443.setProperty(PROP_REDIRECT_INTERNAL, "/content/virtual");
    try {
        saveMappings(session);
        final Resource res0 = resResolver.resolve(request, "/playground.html");
        assertNotNull(res0);
        assertEquals("/content/virtual/playground.html", res0.getPath());
        final Resource res1 = resResolver.resolve(request, "/playground/en.html");
        assertNotNull(res1);
        assertEquals("/content/virtual/playground/en.html", res1.getPath());
        final String mapped00 = resResolver.map(res0.getPath());
        assertEquals("https://virtual.host.com/playground.html", mapped00);
        final String mapped01 = resResolver.map(request, res0.getPath());
        assertEquals("/playground.html", mapped01);
        final String mapped10 = resResolver.map(res1.getPath());
        assertEquals("https://virtual.host.com/playground/en.html", mapped10);
        final String mapped11 = resResolver.map(request, res1.getPath());
        assertEquals("/playground/en.html", mapped11);
    } finally {
        virtualhost443.remove();
        session.save();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) Node(javax.jcr.Node) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 27 with FakeSlingHttpServletRequest

use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.

the class ResourceResolverWithVanityBloomFilterTest method testResolveVanityPathWithVanityOrder.

@Test
public void testResolveVanityPathWithVanityOrder() throws Exception {
    Node childNode = null;
    Node childNode2 = null;
    try {
        //create new child with vanity path
        childNode = maybeCreateNode(rootNode, "rootChild", "nt:unstructured");
        childNode.setProperty("sling:vanityPath", "childVanity");
        childNode.addMixin("sling:VanityPath");
        saveMappings(session);
        String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/childVanity.print.html");
        HttpServletRequest request = new FakeSlingHttpServletRequest(path);
        Resource 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)));
        //create another child with the same vanity path
        childNode2 = maybeCreateNode(rootNode, "rootChild2", "nt:unstructured");
        childNode2.setProperty("sling:vanityPath", "childVanity");
        childNode2.addMixin("sling:VanityPath");
        saveMappings(session);
        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)));
        //add vanityOrder to childNode2
        childNode2.setProperty("sling:vanityOrder", 100);
        saveMappings(session);
        path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/childVanity.print.html");
        request = new FakeSlingHttpServletRequest(path);
        res = resResolver.resolve(request, path);
        assertNotNull(res);
        assertEquals(childNode2.getPath(), res.getPath());
        assertEquals(childNode2.getPrimaryNodeType().getName(), res.getResourceType());
        assertEquals(".print.html", res.getResourceMetadata().getResolutionPathInfo());
        assertNotNull(res.adaptTo(Node.class));
        assertTrue(childNode2.isSame(res.adaptTo(Node.class)));
        //add vanityOrder to childNode higher than childNode2
        childNode.setProperty("sling:vanityOrder", 1000);
        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)));
    } finally {
        if (childNode != null) {
            childNode.remove();
        }
        if (childNode2 != null) {
            childNode2.remove();
        }
        session.save();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) Node(javax.jcr.Node) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 28 with FakeSlingHttpServletRequest

use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.

the class ResourceResolverWithVanityBloomFilterTest method testResolveResourceAliasJcrContent.

@Test
public void testResolveResourceAliasJcrContent() throws Exception {
    // define an alias for the rootPath in the jcr:content child node
    String alias = "testAlias";
    Node content = rootNode.addNode("jcr:content", "nt:unstructured");
    content.setProperty("sling:alias", alias);
    try {
        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)));
        path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias + "/" + alias + ".print.html");
        res = resResolver.resolve(request, path);
        assertEquals("GET request resolution does not go up the path", Resource.RESOURCE_TYPE_NON_EXISTING, res.getResourceType());
        Node child = rootNode.addNode("child", "nt:unstructured");
        child.setProperty("sling:alias", alias);
        try {
            saveMappings(session);
            res = resResolver.resolve(request, path);
            assertEquals(child.getPath(), res.getPath());
        } finally {
            child.remove();
            session.save();
        }
    } finally {
        content.remove();
        session.save();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) Node(javax.jcr.Node) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 29 with FakeSlingHttpServletRequest

use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.

the class ResourceResolverWithVanityBloomFilterTest method testResolveResourceInternalRedirectDepthFirst.

@Test
public void testResolveResourceInternalRedirectDepthFirst() throws Exception {
    HttpServletRequest request = new FakeSlingHttpServletRequest("https", null, -1, rootPath);
    // map anything
    Node localhost443 = mapRoot.getNode("map/https/localhost.443");
    localhost443.setProperty(PROP_REDIRECT_INTERNAL, "/content2");
    // map only ../virtual
    Node toContent = localhost443.addNode("virtual", "sling:Mapping");
    toContent.setProperty("sling:match", "virtual$");
    toContent.setProperty(PROP_REDIRECT_INTERNAL, "/content2/virtual.html");
    try {
        saveMappings(session);
        Resource res = resResolver.resolve(request, "/virtual");
        assertNotNull(res);
        assertEquals("/content2/virtual.html", res.getPath());
        res = resResolver.resolve(request, "/virtual.html");
        assertNotNull(res);
        assertEquals("/content2/virtual.html", res.getPath());
        res = resResolver.resolve(request, "/virtual/child.html");
        assertNotNull(res);
        assertEquals("/content2/virtual/child.html", res.getPath());
    } finally {
        localhost443.getProperty(PROP_REDIRECT_INTERNAL).remove();
        toContent.remove();
        session.save();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) Node(javax.jcr.Node) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 30 with FakeSlingHttpServletRequest

use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.

the class ResourceResolverWithVanityBloomFilterTest method testResolveVirtualHostHttpVsHttps.

@Test
public void testResolveVirtualHostHttpVsHttps() throws Exception {
    final String host0 = "www.host.com";
    final String host1 = "secure.host.com";
    final String content = "/content/page";
    Node virtualhost80 = mapRoot.getNode("map/http").addNode(host0 + ".80", "sling:Mapping");
    virtualhost80.setProperty(PROP_REDIRECT_INTERNAL, content);
    Node virtualhost443 = mapRoot.getNode("map/https").addNode(host0 + ".443", "sling:Mapping");
    virtualhost443.setProperty(PROP_REDIRECT_INTERNAL, content);
    // HTTP request
    try {
        saveMappings(session);
        final HttpServletRequest requestHttp0 = new FakeSlingHttpServletRequest(null, host0, -1, rootPath);
        final Resource resHttp0 = resResolver.resolve(requestHttp0, "/playground.html");
        assertNotNull(resHttp0);
        assertEquals(content + "/playground.html", resHttp0.getPath());
        final Resource resHttp1 = resResolver.resolve(requestHttp0, "/playground/index.html");
        assertNotNull(resHttp1);
        assertEquals(content + "/playground/index.html", resHttp1.getPath());
        // HTTPS request
        final HttpServletRequest requestHttps0 = new FakeSlingHttpServletRequest("https", host0, -1, rootPath);
        final Resource resHttps0 = resResolver.resolve(requestHttps0, "/playground.html");
        assertNotNull(resHttps0);
        assertEquals(content + "/playground.html", resHttps0.getPath());
        final Resource resHttps1 = resResolver.resolve(requestHttps0, "/playground/index.html");
        assertNotNull(resHttps1);
        assertEquals(content + "/playground/index.html", resHttps1.getPath());
        // HTTP Mapping
        final String mappedHttp00 = resResolver.map(resHttp0.getPath());
        assertEquals("http://" + host0 + "/playground.html", mappedHttp00);
        final String mappedHttp01 = resResolver.map(requestHttp0, resHttp0.getPath());
        assertEquals("/playground.html", mappedHttp01);
        final String mappedHttp10 = resResolver.map(resHttp1.getPath());
        assertEquals("http://" + host0 + "/playground/index.html", mappedHttp10);
        final String mappedHttp11 = resResolver.map(requestHttp0, resHttp1.getPath());
        assertEquals("/playground/index.html", mappedHttp11);
        // HTTPS Mapping
        final HttpServletRequest requestHttp1 = new FakeSlingHttpServletRequest(null, host1, -1, rootPath);
        final HttpServletRequest requestHttps1 = new FakeSlingHttpServletRequest("https", host1, -1, rootPath);
        final String mappedHttps00 = resResolver.map(resHttps0.getPath());
        assertEquals("http://" + host0 + "/playground.html", mappedHttps00);
        final String mappedHttps01 = resResolver.map(requestHttps0, resHttps0.getPath());
        assertEquals("/playground.html", mappedHttps01);
        final String mappedHttps02 = resResolver.map(requestHttp1, resHttps0.getPath());
        assertEquals("http://" + host0 + "/playground.html", mappedHttps02);
        final String mappedHttps03 = resResolver.map(requestHttps1, resHttps0.getPath());
        assertEquals("https://" + host0 + "/playground.html", mappedHttps03);
        final String mappedHttps10 = resResolver.map(resHttps1.getPath());
        assertEquals("http://" + host0 + "/playground/index.html", mappedHttps10);
        final String mappedHttps11 = resResolver.map(requestHttps0, resHttps1.getPath());
        assertEquals("/playground/index.html", mappedHttps11);
        final String mappedHttps12 = resResolver.map(requestHttp1, resHttps1.getPath());
        assertEquals("http://" + host0 + "/playground/index.html", mappedHttps12);
        final String mappedHttps13 = resResolver.map(requestHttps1, resHttps1.getPath());
        assertEquals("https://" + host0 + "/playground/index.html", mappedHttps13);
    } finally {
        virtualhost80.remove();
        virtualhost443.remove();
        session.save();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) FakeSlingHttpServletRequest(org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest) Node(javax.jcr.Node) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Aggregations

FakeSlingHttpServletRequest (org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest)63 Test (org.junit.Test)61 Resource (org.apache.sling.api.resource.Resource)59 Node (javax.jcr.Node)57 HttpServletRequest (javax.servlet.http.HttpServletRequest)57 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)57 ValueMap (org.apache.sling.api.resource.ValueMap)2 Ignore (org.junit.Ignore)1