use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest 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());
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testGetRemovesExtensionInResolution.
@Test
public void testGetRemovesExtensionInResolution() throws Exception {
final String path = rootPath + ".whatever";
final Resource res = resResolver.resolve(new FakeSlingHttpServletRequest(path, "GET"), path);
assertNotNull(res);
assertEquals(rootPath, res.getPath());
assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveResourceInternalRedirectPath.
@Test
public void testResolveResourceInternalRedirectPath() throws Exception {
HttpServletRequest request = new FakeSlingHttpServletRequest("https", null, -1, rootPath);
Node localhost443 = mapRoot.getNode("map/https/localhost.443");
Node toContent = localhost443.addNode("_playground_designground_", "sling:Mapping");
toContent.setProperty("sling:match", "(playground|designground)");
toContent.setProperty(PROP_REDIRECT_INTERNAL, "/content/$1");
try {
saveMappings(session);
Resource res = resResolver.resolve(request, "/playground.html");
assertNotNull(res);
assertEquals("/content/playground.html", res.getPath());
res = resResolver.resolve(request, "/playground/en.html");
assertNotNull(res);
assertEquals("/content/playground/en.html", res.getPath());
res = resResolver.resolve(request, "/libs/nt/folder.html");
assertNotNull(res);
assertEquals("/libs/nt/folder.html", res.getPath());
} finally {
toContent.remove();
session.save();
}
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveResourceAlias.
@Test
public void testResolveResourceAlias() throws Exception {
// define an alias for the rootPath
String alias = "testAlias";
rootNode.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)));
} finally {
rootNode.getProperty("sling:alias").remove();
session.save();
}
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveResourceInternalRedirectPathUpdate.
@Test
public void testResolveResourceInternalRedirectPathUpdate() throws Exception {
HttpServletRequest request = new FakeSlingHttpServletRequest("https", null, -1, rootPath);
Node localhost443 = mapRoot.getNode("map/https/localhost.443");
Node toContent = localhost443.addNode("_playground_designground_", "sling:Mapping");
toContent.setProperty("sling:match", "(playground|designground)");
toContent.setProperty(PROP_REDIRECT_INTERNAL, "/content/$1");
try {
saveMappings(session);
Resource res = resResolver.resolve(request, "/playground.html");
assertNotNull(res);
assertEquals("/content/playground.html", res.getPath());
res = resResolver.resolve(request, "/playground/en.html");
assertNotNull(res);
assertEquals("/content/playground/en.html", res.getPath());
res = resResolver.resolve(request, "/libs/nt/folder.html");
assertNotNull(res);
assertEquals("/libs/nt/folder.html", res.getPath());
// update the match
toContent.setProperty("sling:match", "(homeground|foreignground)");
saveMappings(session);
res = resResolver.resolve(request, "/homeground.html");
assertNotNull(res);
assertEquals("/content/homeground.html", res.getPath());
res = resResolver.resolve(request, "/foreignground/en.html");
assertNotNull(res);
assertEquals("/content/foreignground/en.html", res.getPath());
res = resResolver.resolve(request, "/libs/nt/folder.html");
assertNotNull(res);
assertEquals("/libs/nt/folder.html", res.getPath());
} finally {
toContent.remove();
session.save();
}
}
Aggregations