Search in sources :

Example 6 with JsonObject

use of javax.json.JsonObject in project javaee7-samples by javaee-samples.

the class NameAddResourceTest method shouldFailAtLastNameNullValidation.

@Test
public void shouldFailAtLastNameNullValidation() throws Exception {
    JsonObject name = startValidName().addNull("lastName").build();
    Response response = postName(name);
    assertFailedValidation(response);
}
Also used : Response(javax.ws.rs.core.Response) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 7 with JsonObject

use of javax.json.JsonObject in project jersey by jersey.

the class JsonProcessingTest method testJsonObject.

@Test
public void testJsonObject() throws Exception {
    final Response response = target("jsonObject").request(MediaType.APPLICATION_JSON).post(Entity.json(JSON_OBJECT));
    assertEquals(JSON_OBJECT, response.readEntity(JsonObject.class));
}
Also used : Response(javax.ws.rs.core.Response) JsonObject(javax.json.JsonObject) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 8 with JsonObject

use of javax.json.JsonObject in project javaee7-samples by javaee-samples.

the class DOMGeneratorTest method testNestedStructure.

@Test
public void testNestedStructure() throws JSONException {
    JsonObject jsonObject = Json.createObjectBuilder().add("title", "The Matrix").add("year", 1999).add("cast", Json.createArrayBuilder().add("Keanu Reaves").add("Laurence Fishburne").add("Carrie-Anne Moss")).build();
    StringWriter w = new StringWriter();
    try (JsonWriter writer = Json.createWriter(w)) {
        writer.write(jsonObject);
    }
    JSONAssert.assertEquals("{\"title\":\"The Matrix\",\"year\":1999,\"cast\":[\"Keanu Reaves\",\"Laurence Fishburne\",\"Carrie-Anne Moss\"]}", w.toString(), JSONCompareMode.STRICT);
}
Also used : StringWriter(java.io.StringWriter) JsonObject(javax.json.JsonObject) JsonWriter(javax.json.JsonWriter) Test(org.junit.Test)

Example 9 with JsonObject

use of javax.json.JsonObject in project javaee7-samples by javaee-samples.

the class JsonReaderFromReaderTest method testEmptyObject.

@Test
public void testEmptyObject() throws JSONException {
    JsonReader jsonReader = Json.createReader(new StringReader("{}"));
    JsonObject json = jsonReader.readObject();
    assertNotNull(json);
    assertTrue(json.isEmpty());
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 10 with JsonObject

use of javax.json.JsonObject in project javaee7-samples by javaee-samples.

the class JsonReaderFromReaderTest method testSimpleObjectWithTwoElements.

@Test
public void testSimpleObjectWithTwoElements() throws JSONException {
    JsonReader jsonReader = Json.createReader(new StringReader("{" + "  \"apple\":\"red\"," + "  \"banana\":\"yellow\"" + "}"));
    JsonObject json = jsonReader.readObject();
    assertNotNull(json);
    assertFalse(json.isEmpty());
    assertTrue(json.containsKey("apple"));
    assertEquals("red", json.getString("apple"));
    assertTrue(json.containsKey("banana"));
    assertEquals("yellow", json.getString("banana"));
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Aggregations

JsonObject (javax.json.JsonObject)214 Test (org.junit.Test)101 JsonArray (javax.json.JsonArray)58 StringReader (java.io.StringReader)52 Credentials (org.apache.commons.httpclient.Credentials)52 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)52 ArrayList (java.util.ArrayList)51 HashMap (java.util.HashMap)47 NameValuePair (org.apache.commons.httpclient.NameValuePair)43 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)41 JsonString (javax.json.JsonString)31 JsonReader (javax.json.JsonReader)25 HashSet (java.util.HashSet)16 Map (java.util.Map)12 Response (javax.ws.rs.core.Response)12 JsonObjectBuilder (javax.json.JsonObjectBuilder)11 NameValuePairList (org.apache.sling.commons.testing.integration.NameValuePairList)11 StringWriter (java.io.StringWriter)10 JsonException (javax.json.JsonException)10 JsonArrayBuilder (javax.json.JsonArrayBuilder)9