Search in sources :

Example 1 with JsonArray

use of javax.json.JsonArray in project visualee by Thomas-S-B.

the class GraphCreatorTest method testBuildJSONNodes.

@Test
public void testBuildJSONNodes() {
    JavaSourceContainer.getInstance().clear();
    int count = 10;
    String namePrefix = "Testclass ";
    for (int i = 0; i < count; i++) {
        String name = namePrefix + i;
        JavaSource javaSource = JavaSourceFactory.getInstance().newJavaSource(name);
        JavaSourceContainer.getInstance().add(javaSource);
    }
    JsonArray nodes = GraphCreator.buildJSONNodes(null).build();
    assertEquals(count, nodes.size());
}
Also used : JsonArray(javax.json.JsonArray) JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Test(org.junit.Test)

Example 2 with JsonArray

use of javax.json.JsonArray in project visualee by Thomas-S-B.

the class GraphCreatorTest method testBuildJSONLinks.

@Test
public void testBuildJSONLinks() {
    TestDataProvider.createSampleDependencies();
    JsonArray links = GraphCreator.buildJSONLinks(null).build();
    assertEquals(12, links.size());
    DependencyFilter filter = new DependencyFilter().addType(DependencyType.PRODUCES).addType(DependencyType.INSTANCE).setDirectlyConnected(true);
    links = GraphCreator.buildJSONLinks(filter).build();
    assertEquals(8, links.size());
}
Also used : JsonArray(javax.json.JsonArray) DependencyFilter(de.strullerbaumann.visualee.dependency.boundary.DependencyFilter) Test(org.junit.Test)

Example 3 with JsonArray

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

the class MyResourceTest method test5ClientSideNegotiation.

@Test
public void test5ClientSideNegotiation() {
    String json = target.request().accept(MediaType.APPLICATION_JSON).get(String.class);
    JsonReader reader = Json.createReader(new StringReader(json));
    JsonArray jsonArray = reader.readArray();
    assertEquals(1, jsonArray.getJsonObject(0).getInt("age"));
    assertEquals("Penny", jsonArray.getJsonObject(0).getString("name"));
    assertEquals(2, jsonArray.getJsonObject(1).getInt("age"));
    assertEquals("Leonard", jsonArray.getJsonObject(1).getString("name"));
    assertEquals(3, jsonArray.getJsonObject(2).getInt("age"));
    assertEquals("Sheldon", jsonArray.getJsonObject(2).getString("name"));
}
Also used : JsonArray(javax.json.JsonArray) StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) Test(org.junit.Test)

Example 4 with JsonArray

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

the class MyResourceTest method testEchoArray.

@Test
public void testEchoArray() {
    JsonArray jsonArray = Json.createArrayBuilder().add(Json.createObjectBuilder().add("apple", "red")).add(Json.createObjectBuilder().add("banana", "yellow")).build();
    JsonArray json = targetArray.request().post(Entity.entity(jsonArray, MediaType.APPLICATION_JSON), JsonArray.class);
    assertNotNull(json);
    assertEquals(2, json.size());
    assertTrue(json.getJsonObject(0).containsKey("apple"));
    assertEquals("red", json.getJsonObject(0).getString("apple"));
    assertTrue(json.getJsonObject(1).containsKey("banana"));
    assertEquals("yellow", json.getJsonObject(1).getString("banana"));
}
Also used : JsonArray(javax.json.JsonArray) Test(org.junit.Test)

Example 5 with JsonArray

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

the class JsonProcessingTest method testJsonArray.

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

Aggregations

JsonArray (javax.json.JsonArray)80 JsonObject (javax.json.JsonObject)58 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)24 NameValuePair (org.apache.commons.httpclient.NameValuePair)20 Credentials (org.apache.commons.httpclient.Credentials)19 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)19 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)17 StringReader (java.io.StringReader)15 HashSet (java.util.HashSet)15 JsonReader (javax.json.JsonReader)14 HashMap (java.util.HashMap)12 JsonString (javax.json.JsonString)12 JsonValue (javax.json.JsonValue)7 JerseyTest (org.glassfish.jersey.test.JerseyTest)7 JsonException (javax.json.JsonException)6 Map (java.util.Map)5 Response (javax.ws.rs.core.Response)5 File (java.io.File)4 JsonArrayBuilder (javax.json.JsonArrayBuilder)4