//use a davex session to verify the correct JCR events are delivered
Repository repository = JcrUtils.getRepository(HttpTest.HTTP_BASE_URL + "/server/");
Session jcrSession = null;
TestEventListener listener = new TestEventListener();
ObservationManager observationManager = null;
try {
jcrSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
observationManager = jcrSession.getWorkspace().getObservationManager();
String testNodePath = testNodeUrl.substring(HttpTest.HTTP_BASE_URL.length());
observationManager.addEventListener(listener,
Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED, //event types
testNodePath, //absPath
true, //isDeep
null, //uuid
null, //nodeTypeName
false); //noLocal
//5. Attempt to update properties of node (OK)
// curl -FpropOne=propOneValueChanged -FpropTwo=propTwoValueChanged1 -FpropTwo=propTwoValueChanged2 http://myuser:password@localhost:8080/test/node
H.assertAuthenticatedPostStatus(testUserCreds, testNodeUrl, HttpServletResponse.SC_OK, postParams, expectedMessage);
//verify the change happened
String afterUpdateContent = H.getContent(testNodeUrl + ".json", HttpTest.CONTENT_TYPE_JSON);
JSONObject afterUpdateJson = new JSONObject(afterUpdateContent);
Object afterUpdatePropOneObj = afterUpdateJson.opt("propOne");
assertTrue(afterUpdatePropOneObj instanceof JSONArray);
assertEquals(1, ((JSONArray)afterUpdatePropOneObj).length());
assertEquals("propOneValueChanged", ((JSONArray)afterUpdatePropOneObj).get(0));
Object afterUpdatePropTwoObj = afterUpdateJson.opt("propTwo");
assertTrue(afterUpdatePropTwoObj instanceof JSONArray);
assertEquals(2, ((JSONArray)afterUpdatePropTwoObj).length());
assertEquals("propTwoValueChanged1", ((JSONArray)afterUpdatePropTwoObj).get(0));
assertEquals("propTwoValueChanged2", ((JSONArray)afterUpdatePropTwoObj).get(1));
//wait for the expected JCR events to be delivered
for (int second = 0; second < 15; second++) {
if (listener.getEventBundlesProcessed() > 0) {
break;
}
Thread.sleep(1000);
}
assertEquals("One property added event was expected: " + listener.toString(),
1, listener.addedProperties.size());
assertEquals(testNodePath + "/propTwo", listener.addedProperties.get(0));
assertEquals("One property removed event was expected: " + listener.toString(),
1, listener.removedProperties.size());
assertEquals(testNodePath + "/propTwo", listener.removedProperties.get(0));
assertEquals("One property changed event was expected: " + listener.toString(),
1, listener.changedProperties.size());
assertEquals(testNodePath + "/propOne", listener.changedProperties.get(0));
} finally {
//cleanup
if (observationManager != null) {
observationManager.removeEventListener(listener);
}
jcrSession.logout();
repository = null;
}
}