use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveVirtualHostHttp80MultipleRoot.
@Test
public void testResolveVirtualHostHttp80MultipleRoot() throws Exception {
final String de = "de";
final String en = "en";
final String fr = "fr";
final String hostDE = de + ".host.com";
final String hostEN = en + ".host.com";
final String hostFR = fr + ".host.com";
Node virtualhost80a = mapRoot.getNode("map/http").addNode(hostDE + ".80", "sling:Mapping");
virtualhost80a.setProperty(PROP_REDIRECT_INTERNAL, "/");
Node virtualhost80 = mapRoot.getNode("map/http").addNode(hostEN + ".80", "sling:Mapping");
virtualhost80.setProperty(PROP_REDIRECT_INTERNAL, "/");
try {
saveMappings(session);
// de content mapping
final HttpServletRequest requestDE = new FakeSlingHttpServletRequest(null, hostDE, -1, rootPath);
final Resource resDE0 = resResolver.resolve(requestDE, "/playground.html");
assertNotNull(resDE0);
assertEquals("/playground.html", resDE0.getPath());
final Resource resDE1 = resResolver.resolve(requestDE, "/playground/index.html");
assertNotNull(resDE1);
assertEquals("/playground/index.html", resDE1.getPath());
final String mappedDE00 = resResolver.map(resDE0.getPath());
assertEquals("http://" + hostDE + "/playground.html", mappedDE00);
final String mappedDE01 = resResolver.map(requestDE, resDE0.getPath());
assertEquals("/playground.html", mappedDE01);
final String mappedDE10 = resResolver.map(resDE1.getPath());
assertEquals("http://" + hostDE + "/playground/index.html", mappedDE10);
final String mappedDE11 = resResolver.map(requestDE, resDE1.getPath());
assertEquals("/playground/index.html", mappedDE11);
// en content mapping
final HttpServletRequest requestEN = new FakeSlingHttpServletRequest(null, hostEN, -1, rootPath);
final Resource resEN0 = resResolver.resolve(requestEN, "/playground.html");
assertNotNull(resEN0);
assertEquals("/playground.html", resEN0.getPath());
final Resource resEN1 = resResolver.resolve(requestEN, "/playground/index.html");
assertNotNull(resEN1);
assertEquals("/playground/index.html", resEN1.getPath());
// here we get back the hostDE, since this is the first configured
// and we have no request information to map the correct of the
// duplicate entries !
final String mappedEN00 = resResolver.map(resEN0.getPath());
assertEquals("http://" + hostDE + "/playground.html", mappedEN00);
// here we expect the path without scheme/host/port since we have
// the request and can select the right mapping
final String mappedEN01 = resResolver.map(requestEN, resEN0.getPath());
assertEquals("/playground.html", mappedEN01);
// here we get back the hostDE, since this is the first configured
// and we have no request information to map the correct of the
// duplicate entries !
final String mappedEN10 = resResolver.map(resEN1.getPath());
assertEquals("http://" + hostDE + "/playground/index.html", mappedEN10);
// here we expect the path without scheme/host/port since we have
// the request and can select the right mapping
final String mappedEN11 = resResolver.map(requestEN, resEN1.getPath());
assertEquals("/playground/index.html", mappedEN11);
final HttpServletRequest requestFR = new FakeSlingHttpServletRequest(null, hostFR, -1, rootPath);
final Resource resFR1 = resResolver.resolve(requestFR, "/playground/index.html");
assertNotNull(resFR1);
assertEquals("/playground/index.html", resFR1.getPath());
// here we get back the hostDE, since this is the first configured
// and we have no request information to map the correct of the
// duplicate entries !
final String mappedFR10 = resResolver.map(resFR1.getPath());
assertEquals("http://" + hostDE + "/playground/index.html", mappedFR10);
// here we get back the hostDE, since this is the first configured
// and we have request information which does not map any of the
// configured duplicate entries !
final String mappedFR11 = resResolver.map(requestFR, resFR1.getPath());
assertEquals("http://" + hostDE + "/playground/index.html", mappedFR11);
} finally {
virtualhost80a.remove();
virtualhost80.remove();
session.save();
}
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveVanityPath.
@Test
public void testResolveVanityPath() 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)));
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + vanity[0] + ".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[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) + "/" + vanity[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)));
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveVirtualHostHttp8080.
@Test
public void testResolveVirtualHostHttp8080() throws Exception {
HttpServletRequest request = new FakeSlingHttpServletRequest(null, "virtual.host.com", 8080, rootPath);
Node virtualhost80 = mapRoot.getNode("map/http").addNode("virtual.host.com.8080", "sling:Mapping");
virtualhost80.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("http://virtual.host.com:8080/playground.html", mapped00);
final String mapped01 = resResolver.map(request, res0.getPath());
assertEquals("/playground.html", mapped01);
final String mapped10 = resResolver.map(res1.getPath());
assertEquals("http://virtual.host.com:8080/playground/en.html", mapped10);
final String mapped11 = resResolver.map(request, res1.getPath());
assertEquals("/playground/en.html", mapped11);
} finally {
virtualhost80.remove();
session.save();
}
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveRemovedMixinVanityPath.
//see SLING-3558
@Ignore
@Test
public void testResolveRemovedMixinVanityPath() throws Exception {
Node childNode = null;
try {
//create new child with vanity path without mixin
childNode = maybeCreateNode(rootNode, "rootChild", "nt:unstructured");
childNode.setProperty("sling:vanityPath", "childVanity");
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);
assertTrue(res instanceof NonExistingResource);
assertEquals("/childVanity.print.html", res.getPath());
//add mixin
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 mixin
childNode.removeMixin("sling:VanityPath");
saveMappings(session);
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/childVanity.print.html");
request = new FakeSlingHttpServletRequest(path);
res = resResolver.resolve(request, path);
assertNotNull(res);
assertTrue(res instanceof NonExistingResource);
assertEquals("/childVanity.print.html", res.getPath());
} finally {
if (childNode != null) {
childNode.remove();
saveMappings(session);
}
}
}
use of org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest in project sling by apache.
the class ResourceResolverWithVanityBloomFilterTest method testResolveResource.
@Test
public void testResolveResource() throws Exception {
// existing resource
HttpServletRequest request = new FakeSlingHttpServletRequest(rootPath);
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)));
// missing resource below root should resolve "missing resource"
String path = rootPath + "/missing";
res = resResolver.resolve(new FakeSlingHttpServletRequest(path), path);
assertNotNull(res);
assertEquals(path, res.getPath());
assertEquals(Resource.RESOURCE_TYPE_NON_EXISTING, res.getResourceType());
assertNull(res.adaptTo(Node.class));
// root with selectors/ext should resolve root
path = rootPath + ".print.a4.html";
res = resResolver.resolve(new FakeSlingHttpServletRequest(path), path);
assertNotNull(res);
assertEquals(rootPath, res.getPath());
assertEquals(rootNode.getPrimaryNodeType().getName(), res.getResourceType());
assertNotNull(res.adaptTo(Node.class));
assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
// missing resource should return NON_EXISTING Resource
path = rootPath + System.currentTimeMillis();
res = resResolver.resolve(new FakeSlingHttpServletRequest(path), path);
assertNotNull(res);
assertTrue(ResourceUtil.isNonExistingResource(res));
assertEquals(path, res.getPath());
assertEquals(Resource.RESOURCE_TYPE_NON_EXISTING, res.getResourceType());
}
Aggregations