Package org.codehaus.jettison.json

Examples of org.codehaus.jettison.json.JSONObject


        HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();

        connection.setDoOutput(true);
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);
        JSONObject body = new JSONObject(getResponseFor(connection));
        assertThat(body.length(), is(2));

        JSONObject properties = body.getJSONObject("properties");
        assertThat(properties, is(notNullValue()));
        assertThat(properties.length(), is(1));
        assertThat(properties.getString("jcr:primaryType"), is("dna:system"));

        JSONObject children = body.getJSONObject("children");
        assertThat(children.length(), is(1));

        JSONObject namespaces = children.getJSONObject("dna:namespaces");
        assertThat(namespaces.length(), is(2));

        properties = namespaces.getJSONObject("properties");
        assertThat(properties.length(), is(1));
        assertThat(properties.getString("jcr:primaryType"), is("dna:namespaces"));

        JSONArray namespace = namespaces.getJSONArray("children");
        assertThat(namespace.length(), is(10));
        Set<String> prefixes = new HashSet<String>(namespace.length());

        for (int i = 0; i < namespace.length(); i++) {
            prefixes.add(namespace.getString(i));
View Full Code Here


        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);

        String payload = "{ \"properties\": {\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\": \"testValue\", \"multiValuedProperty\": [\"value1\", \"value2\"]}}";
        connection.getOutputStream().write(payload.getBytes());

        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"));
View Full Code Here

        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);

        String payload = "{}";
        connection.getOutputStream().write(payload.getBytes());

        JSONObject body = new JSONObject(getResponseFor(connection));
        assertThat(body.length(), is(1));

        JSONObject properties = body.getJSONObject("properties");
        assertThat(properties, is(notNullValue()));
        assertThat(properties.length(), is(1));
        assertThat(properties.getString("jcr:primaryType"), is("nt:unstructured"));

        assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
        connection.disconnect();
    }
View Full Code Here

        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);

        String payload = "{ \"properties\": {\"jcr:mixinTypes\": \"mix:referenceable\"}}";
        connection.getOutputStream().write(payload.getBytes());

        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("jcr:uuid"), is(notNullValue()));

        JSONArray values = properties.getJSONArray("jcr:mixinTypes");
        assertThat(values, is(notNullValue()));
        assertThat(values.length(), is(1));
        assertThat(values.getString(0), is("mix:referenceable"));

        assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
        connection.disconnect();

        postUrl = new URL(SERVER_URL + "/dna%3arepository/default/items/withMixinType");
        connection = (HttpURLConnection)postUrl.openConnection();

        // Make sure that we can retrieve the node with a GET
        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(3));
        assertThat(properties.getString("jcr:primaryType"), is("nt:unstructured"));
        assertThat(properties.getString("jcr:uuid"), is(notNullValue()));

        values = properties.getJSONArray("jcr:mixinTypes");
        assertThat(values, is(notNullValue()));
        assertThat(values.length(), is(1));
        assertThat(values.getString(0), is("mix:referenceable"));

        assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
View Full Code Here

        // Make sure that we can retrieve the node with a GET
        connection.setDoOutput(true);
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);
        JSONObject body = new JSONObject(getResponseFor(connection));

        assertThat(body.length(), is(2));

        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"));

        JSONObject children = body.getJSONObject("children");
        assertThat(children, is(notNullValue()));
        assertThat(children.length(), is(1));

        JSONObject child = children.getJSONObject("childNode");
        assertThat(child, is(notNullValue()));
        assertThat(child.length(), is(1));

        properties = child.getJSONObject("properties");
        assertThat(properties, is(notNullValue()));
        assertThat(properties.length(), is(2));
        // Parent primary type is nt:unstructured, so this should default to nt:unstructured primary type
        assertThat(properties.getString("jcr:primaryType"), is("nt:unstructured"));
        assertThat(properties.getString("nestedProperty"), is("nestedValue"));
View Full Code Here

        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);

        String payload = "{ \"properties\": {\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\": \"testValue\", \"multiValuedProperty\": [\"value1\", \"value2\"]}}";
        connection.getOutputStream().write(payload.getBytes());

        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"));
View Full Code Here

        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();

    }
View Full Code Here

        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);

        payload = "{\"testProperty\":\"someOtherValue\"}";
        connection.getOutputStream().write(payload.getBytes());

        JSONObject body = new JSONObject(getResponseFor(connection));
        assertThat(body.length(), is(1));

        JSONObject 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("someOtherValue"));

        assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
        connection.disconnect();

    }
View Full Code Here

        String otherValue = "someOtherValue";
        payload = "{\"testProperty/base64/\":\"" + Base64.encodeBytes(otherValue.getBytes("UTF-8")) + "\"}";
        connection.getOutputStream().write(payload.getBytes());

        JSONObject body = new JSONObject(getResponseFor(connection));
        assertThat(body.length(), is(1));

        JSONObject properties = body.getJSONObject("properties");
        assertThat(properties, is(notNullValue()));
        assertThat(properties.length(), is(2));
        assertThat(properties.getString("jcr:primaryType"), is("nt:unstructured"));
        String responseEncodedValue = properties.getString("testProperty/base64/");
        String decodedValue = new String(Base64.decode(responseEncodedValue), "UTF-8");
        assertThat(decodedValue, is(otherValue));

        assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
        connection.disconnect();

        // Try putting a non-binary value ...
        connection = (HttpURLConnection)putUrl.openConnection();

        connection.setDoOutput(true);
        connection.setRequestMethod("PUT");
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);

        String anotherValue = "yetAnotherValue";
        payload = "{\"testProperty\":\"" + anotherValue + "\"}";
        connection.getOutputStream().write(payload.getBytes());

        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(anotherValue));

        assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
        connection.disconnect();
    }
View Full Code Here

        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);

        payload = "{\"testProperty\": \"testValue\", \"multiValuedProperty\": [\"value1\", \"value2\"]}";
        connection.getOutputStream().write(payload.getBytes());

        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"));
View Full Code Here

TOP

Related Classes of org.codehaus.jettison.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.