Java Code Examples for net.sf.json.JSONArray#optJSONObject()
The following examples show how to use
net.sf.json.JSONArray#optJSONObject() .
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: PolicyRestTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void getPoliciesTest() { Response response = target().path("policies").request().get(); assertEquals(response.getStatus(), 200); verify(policyManager).getPolicies(any(PolicyQueryParams.class)); try { JSONArray result = JSONArray.fromObject(response.readEntity(String.class)); assertEquals(result.size(), 1); JSONObject policyObj = result.optJSONObject(0); assertNotNull(policyObj); String id = policyObj.optString("PolicyId"); assertNotNull(id); assertEquals(id, policyId.stringValue()); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
Example 2
Source File: StateRestTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void getStatesWithoutFiltersTest() { Response response = target().path("states").request().get(); assertEquals(response.getStatus(), 200); verify(stateManager).getStates(anyString(), anyString(), anySetOf(Resource.class)); try { String str = response.readEntity(String.class); JSONArray arr = JSONArray.fromObject(str); assertEquals(results.size(), arr.size()); for (int i = 0; i < arr.size(); i++) { JSONObject object = arr.optJSONObject(i); assertNotNull(object); assertTrue(results.keySet().contains(vf.createIRI(object.get("id").toString()))); } } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
Example 3
Source File: StateRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void getStatesWithFiltersTest() { // Setup: Set<Resource> subjects = IntStream.range(0, 2) .mapToObj(i -> "http://mobi.com/subjects/" + i) .map(vf::createIRI) .collect(Collectors.toSet()); WebTarget webTarget = target().path("states").queryParam("application", "app"); for (Resource subject : subjects) { webTarget = webTarget.queryParam("subjects", subject.stringValue()); } Response response = webTarget.request().get(); assertEquals(response.getStatus(), 200); verify(stateManager).getStates(anyString(), eq("app"), eq(subjects)); try { String str = response.readEntity(String.class); JSONArray arr = JSONArray.fromObject(str); assertEquals(results.size(), arr.size()); for (int i = 0; i < arr.size(); i++) { JSONObject object = arr.optJSONObject(i); assertNotNull(object); assertTrue(results.keySet().contains(vf.createIRI(object.get("id").toString()))); } } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
Example 4
Source File: ProvRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
private List<String> getResources(JSONArray array) { List<String> resources = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject obj = array.optJSONObject(i); assertNotNull(obj); String iri = obj.optString("@id"); assertNotNull(iri); resources.add(iri); } return resources; }