clientNodeProperties.add("propOne", "propOneValue2");
clientNodeProperties.add("propTwo", "propTwoValue");
String testNodeUrl = H.getTestClient().createNode(createTestNodeUrl, clientNodeProperties, null, false);
String content = H.getContent(testNodeUrl + ".json", HttpTest.CONTENT_TYPE_JSON);
JSONObject json = new JSONObject(content);
Object propOneObj = json.opt("propOne");
assertTrue(propOneObj instanceof JSONArray);
assertEquals(2, ((JSONArray)propOneObj).length());
assertEquals("propOneValue1", ((JSONArray)propOneObj).get(0));
assertEquals("propOneValue2", ((JSONArray)propOneObj).get(1));
Object propTwoObj = json.opt("propTwo");
assertTrue(propTwoObj instanceof String);
assertEquals("propTwoValue", propTwoObj);
//3. Attempt to update property of node as testUser (500: javax.jcr.AccessDeniedException: /test/node/propOne: not allowed to add or modify item)
// curl -FpropOne=propOneValueChanged -FpropTwo=propTwoValueChanged1 -FpropTwo=propTwoValueChanged2 http://myuser:password@localhost:8080/test/node
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("propOne", "propOneValueChanged"));
postParams.add(new NameValuePair("propTwo", "propTwoValueChanged1"));
postParams.add(new NameValuePair("propTwo", "propTwoValueChanged2"));
Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");
String expectedMessage = "Expected javax.jcr.AccessDeniedException";
H.assertAuthenticatedPostStatus(testUserCreds, testNodeUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, expectedMessage);
//4. Grant jcr:modifyProperties rights to testUser as admin (OK)
// curl -FprincipalId=myuser -Fprivilege@jcr:modifyProperties=granted http://admin:admin@localhost:8080/test/node.modifyAce.html
Map<String, String> nodeAceProperties = new HashMap<String, String>();
nodeAceProperties.put("principalId", testUserId);
nodeAceProperties.put("privilege@jcr:modifyProperties", "granted");
H.getTestClient().createNode(testNodeUrl + ".modifyAce.html", nodeAceProperties);
//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));