use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveResourceInternalRedirectPathAndVanityPath.
@Test
public void testResolveResourceInternalRedirectPathAndVanityPath() throws Exception {
HttpServletRequest request = new FakeSlingHttpServletRequest("https", null, -1, rootPath);
Node localhost443 = mapRoot.getNode("map/https/localhost.443");
localhost443.setProperty(PROP_REDIRECT_INTERNAL, "/example");
try {
saveMappings(session);
Resource res = resResolver.resolve(request, vanity[0]);
assertNotNull(res);
assertEquals(rootPath, res.getPath());
//see SLING-3428
res = resResolver.resolve(request, vanity[1]);
assertNotNull(res);
assertEquals("/example/" + vanity[1], res.getPath());
} finally {
localhost443.getProperty(PROP_REDIRECT_INTERNAL).remove();
session.save();
}
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveResourceInternalRedirectUrl.
@Test
public void testResolveResourceInternalRedirectUrl() throws Exception {
HttpServletRequest request = new FakeSlingHttpServletRequest("https", null, -1, rootPath);
Node localhost443 = mapRoot.getNode("map/https/localhost.443");
localhost443.setProperty(PROP_REDIRECT_INTERNAL, "http://localhost");
try {
saveMappings(session);
Resource res = resResolver.resolve(request, rootPath);
assertNotNull(res);
assertEquals(rootPath, res.getPath());
assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
assertNotNull(res.adaptTo(Node.class));
assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
} finally {
localhost443.getProperty(PROP_REDIRECT_INTERNAL).remove();
session.save();
}
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverTest method testResolveResourceAliasJcrContentWithUpdate.
@Test
public void testResolveResourceAliasJcrContentWithUpdate() throws Exception {
// define an alias for the rootPath in the jcr:content child node
String[] alias = { "testAlias", "testAliasToUpdate" };
Node content = rootNode.addNode("jcr:content", "nt:unstructured");
content.setProperty("sling:alias", alias);
try {
saveMappings(session);
String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias[1] + ".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[1] + ".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 alias
String[] aliasUpdated = { "testAlias", "testAliasUpdated" };
content.setProperty("sling:alias", aliasUpdated);
saveMappings(session);
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + aliasUpdated[1] + ".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) + "/" + aliasUpdated[1] + ".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 {
content.remove();
session.save();
}
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverTest method testResolveResourceInternalRedirectUrl.
@Test
public void testResolveResourceInternalRedirectUrl() throws Exception {
HttpServletRequest request = new FakeSlingHttpServletRequest("https", null, -1, rootPath);
Node localhost443 = mapRoot.getNode("map/https/localhost.443");
localhost443.setProperty(PROP_REDIRECT_INTERNAL, "http://localhost");
try {
saveMappings(session);
Resource res = resResolver.resolve(request, rootPath);
assertNotNull(res);
assertEquals(rootPath, res.getPath());
assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
assertNotNull(res.adaptTo(Node.class));
assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
} finally {
localhost443.getProperty(PROP_REDIRECT_INTERNAL).remove();
session.save();
}
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverTest method testResolveResourceAliasWithUpdate.
@Test
public void testResolveResourceAliasWithUpdate() throws Exception {
// define an alias for the rootPath
String[] alias = { "testAlias", "testAliasToUpdate" };
rootNode.setProperty("sling:alias", alias);
try {
saveMappings(session);
String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias[1] + ".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[1] + ".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 alias
String[] aliasUpdated = { "testAlias", "testAliasUpdated" };
rootNode.setProperty("sling:alias", aliasUpdated);
saveMappings(session);
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + aliasUpdated[1] + ".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) + "/" + aliasUpdated[1] + ".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();
}
}
Aggregations