SLING-4058 - add someHost dummy node under /etc/map/https in setup, most tests pass on Oak now
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1634887 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/launchpad/testservices/events/EventsCounterImpl.java b/src/main/java/org/apache/sling/launchpad/testservices/events/EventsCounterImpl.java
index fcdba9c..7822545 100644
--- a/src/main/java/org/apache/sling/launchpad/testservices/events/EventsCounterImpl.java
+++ b/src/main/java/org/apache/sling/launchpad/testservices/events/EventsCounterImpl.java
@@ -27,6 +27,7 @@
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
@@ -51,8 +52,8 @@
@Property(
name=org.osgi.service.event.EventConstants.EVENT_TOPIC,
value= {
- org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_ADDED,
- "org/apache/sling/api/resource/ResourceResolverMapping/CHANGED"
+ SlingConstants.TOPIC_RESOURCE_ADDED,
+ SlingConstants.TOPIC_RESOURCE_RESOLVER_MAPPING_CHANGED
})
})
public class EventsCounterImpl extends SlingSafeMethodsServlet implements EventHandler,EventsCounter {
diff --git a/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/MappingsFacade.java b/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/MappingsFacade.java
index 9ee3f6e..d04e3f1 100644
--- a/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/MappingsFacade.java
+++ b/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/MappingsFacade.java
@@ -28,13 +28,17 @@
public static final String MAPPING_EVENT_TOPIC = "org/apache/sling/api/resource/ResourceResolverMapping/CHANGED";
private static final Logger logger = LoggerFactory.getLogger(MappingsFacade.class);
private final EventsCounter eventsCounter;
+ private static boolean firstInstance = true;
// How long to wait for mapping updates
public static final String MAPPING_UPDATE_TIMEOUT_MSEC = "ResourceResolverTest.mapping.update.timeout.msec";
private static final long updateTimeout = Long.valueOf(System.getProperty(MAPPING_UPDATE_TIMEOUT_MSEC, "10000"));
public MappingsFacade(EventsCounter c) {
- logger.info("updateTimeout = {}, use {} system property to change", updateTimeout, MAPPING_UPDATE_TIMEOUT_MSEC);
+ if(firstInstance) {
+ logger.info("updateTimeout = {}, use {} system property to change", updateTimeout, MAPPING_UPDATE_TIMEOUT_MSEC);
+ firstInstance = false;
+ }
eventsCounter = c;
}
@@ -48,9 +52,11 @@
session.save();
final long timeout = System.currentTimeMillis() + updateTimeout;
while(System.currentTimeMillis() < timeout) {
- if(eventsCounter.getEventsCount(MAPPING_EVENT_TOPIC) != oldEventsCount) {
+ final int newCount = eventsCounter.getEventsCount(MAPPING_EVENT_TOPIC);
+ if(newCount != oldEventsCount) {
// Sleeping here shouldn't be needed but it looks
// like mappings are not immediately updated once the event arrives
+ logger.debug("Event counter {} is now {}", MAPPING_EVENT_TOPIC, newCount);
Thread.sleep(updateTimeout / 50);
return null;
}
diff --git a/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java b/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java
index 906573b..c48a811 100644
--- a/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java
+++ b/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java
@@ -47,7 +47,6 @@
import org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest;
import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -88,9 +87,6 @@
}
private void saveMappings(Session s) throws Exception {
- if(mappingsFacade == null) {
- mappingsFacade = new MappingsFacade(eventsCounter);
- }
if(saveMappingsError != null) {
fail(saveMappingsError);
} else {
@@ -107,6 +103,7 @@
resResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
cleanupResolverFactory = resourceResolverFactory;
session = resResolver.adaptTo(Session.class);
+ mappingsFacade = new MappingsFacade(eventsCounter);
// Do the mappings setup only once, and clean it up
// after all tests
@@ -125,11 +122,16 @@
}
mapRoot = session.getNode("/etc");
+ session.save();
// define a vanity path for the rootPath
vanity = new String[] {"testVanity","testV", "testVanityToUpdate"};
rootNode.setProperty("sling:vanityPath", vanity);
rootNode.addMixin("sling:VanityPath");
+
+ // TODO no mappings change event with Oak without this??
+ session.getNode("/etc/map/https").addNode("someHost" + System.currentTimeMillis() + ".443", "sling:Mapping");
+
saveMappings(session);
}
@@ -148,7 +150,6 @@
}
@AfterClass
- @BeforeClass
public static void clearTimeouts() {
saveMappingsError = null;
}
@@ -1580,93 +1581,84 @@
}
@Test public void testResolveVanityPathWithUpdate() throws Exception {
- try {
+ String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+ + "/" + vanity[2] + ".print.html");
- 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());
- 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());
- assertEquals(".print.html",
- res.getResourceMetadata().getResolutionPathInfo());
+ assertNotNull(res.adaptTo(Node.class));
+ assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
- assertNotNull(res.adaptTo(Node.class));
- assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
+ path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/"
+ + vanity[2] + ".print.html/suffix.pdf");
- 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());
- 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());
- 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");
- 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());
- 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());
- assertEquals(".print.html",
- res.getResourceMetadata().getResolutionPathInfo());
+ assertNotNull(res.adaptTo(Node.class));
+ assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
- assertNotNull(res.adaptTo(Node.class));
- assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
+ path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/"
+ + vanityPathUpdated[2] + ".print.html/suffix.pdf");
- 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());
- 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());
- 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");
- 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());
-
- } finally {
- //restore vanityPath
- vanity = new String[] {"testVanity","testV", "testVanityToUpdate"};
- rootNode.setProperty("sling:vanityPath", vanity);
- saveMappings(session);
- }
+ request = new FakeSlingHttpServletRequest(path);
+ res = resResolver.resolve(request, path);
+ assertNotNull(res);
+ assertTrue(res instanceof NonExistingResource);
+ assertEquals("/"+vanity[2]+".print.html", res.getPath());
}
@Test public void testResolveRemovedVanityPath() throws Exception {