connection.setDoOutput(true);
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);
JSONObject body = new JSONObject(getResponseFor(connection));
assertThat(body.length(), is(1));
JSONObject properties = body.getJSONObject("properties");
assertThat(properties, is(notNullValue()));
assertThat(properties.length(), is(3));
assertThat(properties.getString("jcr:primaryType"), is("nt:unstructured"));
assertThat(properties.getString("testProperty"), is("testValue"));
assertThat(properties.get("multiValuedProperty"), instanceOf(JSONArray.class));
JSONArray values = properties.getJSONArray("multiValuedProperty");
assertThat(values, is(notNullValue()));
assertThat(values.length(), is(2));
assertThat(values.getString(0), is("value1"));
assertThat(values.getString(1), is("value2"));
assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
connection.disconnect();
// Delete the property
postUrl = new URL(SERVER_URL + "/dna%3arepository/default/items/propertyForDeletion/multiValuedProperty");
connection = (HttpURLConnection)postUrl.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("DELETE");
connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);
assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
connection.disconnect();
// Confirm that it no longer exists
postUrl = new URL(SERVER_URL + "/dna%3arepository/default/items/propertyForDeletion");
connection = (HttpURLConnection)postUrl.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);
body = new JSONObject(getResponseFor(connection));
assertThat(body.length(), is(1));
properties = body.getJSONObject("properties");
assertThat(properties, is(notNullValue()));
assertThat(properties.length(), is(2));
assertThat(properties.getString("jcr:primaryType"), is("nt:unstructured"));
assertThat(properties.getString("testProperty"), is("testValue"));
assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
connection.disconnect();
}