public void testResolveVanityPathWithUpdate()

in src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverWithVanityBloomFilterTest.java [1476:1542]


    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());
    }