Java Code Examples for net.sf.json.JSONArray#forEach()

The following examples show how to use net.sf.json.JSONArray#forEach() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommitRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getCommitHistoryTest() {
    Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/history")
            .request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getCommitChain(vf.createIRI(COMMIT_IRIS[1]));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + COMMIT_IRIS.length);
    assertEquals(response.getLinks().size(), 0);
    try {
        JSONArray array = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(array.size(), COMMIT_IRIS.length);
        array.forEach(result -> {
            JSONObject commitObj = JSONObject.fromObject(result);
            assertTrue(commitObj.containsKey("id"));
            assertTrue(Arrays.asList(COMMIT_IRIS).contains(commitObj.getString("id")));
        });
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 2
Source File: CommitRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getCommitHistoryWithPaginationTest() {
    Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/history")
            .queryParam("offset", 0)
            .queryParam("limit", 10)
            .request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getCommitChain(vf.createIRI(COMMIT_IRIS[1]));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + COMMIT_IRIS.length);
    assertEquals(response.getLinks().size(), 0);
    try {
        JSONArray array = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(array.size(), COMMIT_IRIS.length);
        array.forEach(result -> {
            JSONObject commitObj = JSONObject.fromObject(result);
            assertTrue(commitObj.containsKey("id"));
            assertTrue(Arrays.asList(COMMIT_IRIS).contains(commitObj.getString("id")));
        });
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 3
Source File: CatalogRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getCommitChainTest() {
    Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI)
            + "/branches/" + encode(BRANCH_IRI) + "/commits")
            .request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getCommitChain(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI), vf.createIRI(BRANCH_IRI));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + COMMIT_IRIS.length);
    assertEquals(response.getLinks().size(), 0);
    try {
        JSONArray array = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(array.size(), COMMIT_IRIS.length);
        array.forEach(result -> {
            JSONObject commitObj = JSONObject.fromObject(result);
            assertTrue(commitObj.containsKey("id"));
            assertTrue(Arrays.asList(COMMIT_IRIS).contains(commitObj.getString("id")));
        });
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 4
Source File: CatalogRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getCommitChainWithPaginationTest() {
    Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI)
            + "/branches/" + encode(BRANCH_IRI) + "/commits").queryParam("offset", 0).queryParam("limit", 10)
            .request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getCommitChain(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI), vf.createIRI(BRANCH_IRI));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + COMMIT_IRIS.length);
    assertEquals(response.getLinks().size(), 0);
    try {
        JSONArray array = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(array.size(), COMMIT_IRIS.length);
        array.forEach(result -> {
            JSONObject commitObj = JSONObject.fromObject(result);
            assertTrue(commitObj.containsKey("id"));
            assertTrue(Arrays.asList(COMMIT_IRIS).contains(commitObj.getString("id")));
        });
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 5
Source File: CatalogRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getCommitChainWithTargetIdTest() {
    Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI)
            + "/branches/" + encode(BRANCH_IRI) + "/commits")
            .queryParam("targetId", BRANCH_IRI)
            .request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getCommitChain(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI), vf.createIRI(BRANCH_IRI), vf.createIRI(BRANCH_IRI));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + COMMIT_IRIS.length);
    assertEquals(response.getLinks().size(), 0);
    try {
        JSONArray array = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(array.size(), COMMIT_IRIS.length);
        array.forEach(result -> {
            JSONObject commitObj = JSONObject.fromObject(result);
            assertTrue(commitObj.containsKey("id"));
            assertTrue(Arrays.asList(COMMIT_IRIS).contains(commitObj.getString("id")));
        });
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}