Java Code Examples for javax.json.JsonArray#getValuesAs()
The following examples show how to use
javax.json.JsonArray#getValuesAs() .
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: SmallRyeHealthReporterTest.java From smallrye-health with Apache License 2.0 | 6 votes |
public void testGetHealthWithMixedChecksAndStyleDefault(String expectedCheckName, Supplier<SmallRyeHealth> supplier) { SmallRyeHealth health = supplier.get(); assertThat(health.isDown(), is(true)); assertThat(health.getPayload().getString("status"), is("DOWN")); JsonArray checks = health.getPayload().getJsonArray("checks"); assertThat(checks.size(), is(3)); for (JsonObject check : checks.getValuesAs(JsonObject.class)) { if (check.getString("name").equals("down")) { assertThat(check.getString("status"), is("DOWN")); } else if (check.getString("name").equals("up")) { assertThat(check.getString("status"), is("UP")); } else if (check.getString("name").equals(expectedCheckName)) { assertThat(check.getString("status"), is("DOWN")); assertThat(check.getJsonObject("data").getString("rootCause"), is("this health check has failed")); } else { Assert.fail("Health returned unexpected health check: " + check.toString()); } } }
Example 2
Source File: SmallRyeHealthReporterTest.java From smallrye-health with Apache License 2.0 | 6 votes |
public void testGetHealthWithMixedChecksAndStyleNone(String expectedCheckName, Supplier<SmallRyeHealth> supplier) { reporter.setUncheckedExceptionDataStyle("NONE"); SmallRyeHealth health = supplier.get(); assertThat(health.isDown(), is(true)); assertThat(health.getPayload().getString("status"), is("DOWN")); JsonArray checks = health.getPayload().getJsonArray("checks"); assertThat(checks.size(), is(3)); for (JsonObject check : checks.getValuesAs(JsonObject.class)) { if (check.getString("name").equals("down")) { assertThat(check.getString("status"), is("DOWN")); } else if (check.getString("name").equals("up")) { assertThat(check.getString("status"), is("UP")); } else if (check.getString("name").equals(expectedCheckName)) { assertThat(check.getString("status"), is("DOWN")); assertThat(check.getJsonObject("data"), is(nullValue())); } else { Assert.fail("Health returned unexpected health check: " + check.toString()); } } }
Example 3
Source File: SmallRyeHealthReporterTest.java From smallrye-health with Apache License 2.0 | 6 votes |
public void testGetHealthWithMixedChecksAndStyleStackTrace(String expectedCheckName, Supplier<SmallRyeHealth> supplier) { reporter.setUncheckedExceptionDataStyle("stackTrace"); SmallRyeHealth health = supplier.get(); assertThat(health.isDown(), is(true)); assertThat(health.getPayload().getString("status"), is("DOWN")); JsonArray checks = health.getPayload().getJsonArray("checks"); assertThat(checks.size(), is(3)); for (JsonObject check : checks.getValuesAs(JsonObject.class)) { if (check.getString("name").equals("down")) { assertThat(check.getString("status"), is("DOWN")); } else if (check.getString("name").equals("up")) { assertThat(check.getString("status"), is("UP")); } else if (check.getString("name").equals(expectedCheckName)) { assertThat(check.getString("status"), is("DOWN")); assertThat(check.getJsonObject("data").getString("stackTrace"), is(notNullValue())); } } }
Example 4
Source File: CamundaModelApiOrderEventHandler.java From flowing-retail-old with Apache License 2.0 | 6 votes |
private Order parseOrder(JsonObject orderJson) { Order order = new Order(); // Order Service is NOT interested in customer id - ignore: JsonObject customerJson = orderJson.getJsonObject("customer"); orderJson.getString("customerId"); Customer customer = new Customer() // .setName(customerJson.getString("name")) // .setAddress(customerJson.getString("address")); order.setCustomer(customer); JsonArray jsonArray = orderJson.getJsonArray("items"); for (JsonObject itemJson : jsonArray.getValuesAs(JsonObject.class)) { order.addItem( // new OrderItem() // .setArticleId(itemJson.getString("articleId")) // .setAmount(itemJson.getInt("amount"))); } return order; }
Example 5
Source File: CamundaBpmnOrderEventHandler.java From flowing-retail-old with Apache License 2.0 | 6 votes |
private Order parseOrder(JsonObject orderJson) { Order order = new Order(); // Order Service is NOT interested in customer id - ignore: JsonObject customerJson = orderJson.getJsonObject("customer"); orderJson.getString("customerId"); Customer customer = new Customer() // .setName(customerJson.getString("name")) // .setAddress(customerJson.getString("address")); order.setCustomer(customer); JsonArray jsonArray = orderJson.getJsonArray("items"); for (JsonObject itemJson : jsonArray.getValuesAs(JsonObject.class)) { order.addItem( // new OrderItem() // .setArticleId(itemJson.getString("articleId")) // .setAmount(itemJson.getInt("amount"))); } return order; }
Example 6
Source File: ExecutionDynamicTest.java From microprofile-graphql with Apache License 2.0 | 6 votes |
private void validateResponseStructure(){ JsonObject received = getJsonObject(new StringReader(this.currentOutput)); JsonArray errors = received.getJsonArray("errors"); validatePart(received,"root","data","errors"); if(errors!=null){ for(JsonObject errorJsonObject: errors.getValuesAs(JsonObject.class)){ JsonArray locations = errorJsonObject.getJsonArray("locations"); validatePart(errorJsonObject, "errors", "message","locations","path","extensions"); if(locations!=null){ for(JsonObject locationJsonObject: locations.getValuesAs(JsonObject.class)){ validatePart(locationJsonObject, "errors/locations", "line", "column"); } } } } }
Example 7
Source File: EntityStateOrderEventHandler.java From flowing-retail-old with Apache License 2.0 | 6 votes |
private Order parseOrder(JsonObject orderJson) { Order order = new Order(); // Order Service is NOT interested in customer id - ignore: JsonObject customerJson = orderJson.getJsonObject("customer"); orderJson.getString("customerId"); Customer customer = new Customer() // .setName(customerJson.getString("name")) // .setAddress(customerJson.getString("address")); order.setCustomer(customer); JsonArray jsonArray = orderJson.getJsonArray("items"); for (JsonObject itemJson : jsonArray.getValuesAs(JsonObject.class)) { order.addItem( // new OrderItem() // .setArticleId(itemJson.getString("articleId")) // .setAmount(itemJson.getInt("amount"))); } return order; }
Example 8
Source File: InvokeWithJsonPProviderTest.java From microprofile-rest-client with Apache License 2.0 | 6 votes |
private void testGet(JsonPClient client, String clientType) { reset(); stubFor(get(urlEqualTo("/")) .willReturn(aResponse() .withHeader("Content-Type", "application/json") .withBody("[{\"key\": \"value\"}, {\"key\": \"anotherValue\"}]")) ); JsonArray jsonArray = client.get(); assertEquals(jsonArray.size(), 2, "Expected 2 values in the array for client "+clientType); List<JsonObject> jsonObjects = jsonArray.getValuesAs(JsonObject.class); JsonObject one = jsonObjects.get(0); assertEquals(one.keySet().size(), 1, "There should only be one key in object 1 for client "+clientType); assertEquals(one.getString("key"), "value", "The value of 'key' on object 1 should be 'value' in client "+clientType); JsonObject two = jsonObjects.get(1); assertEquals(two.keySet().size(), 1, "There should only be one key in object 2 for client "+clientType); assertEquals(two.getString("key"), "anotherValue", "The value of 'key' on object 2 should be 'anotherValue' in client "+clientType); }
Example 9
Source File: MultipleLivenessFailedTest.java From microprofile-health with Apache License 2.0 | 5 votes |
/** * Verifies the liveness health integration with CDI at the scope of a server runtime */ @Test @RunAsClient public void testFailureLivenessResponsePayload() { Response response = getUrlLiveContents(); // status code Assert.assertEquals(response.getStatus(),503); JsonObject json = readJson(response); // response size JsonArray checks = json.getJsonArray("checks"); Assert.assertEquals(checks.size(), 2, "Expected two check responses"); for (JsonObject check : checks.getValuesAs(JsonObject.class)) { String id = check.getString("name"); switch (id) { case "successful-check": verifySuccessStatus(check); break; case "failed-check": verifyFailureStatus(check); break; default: Assert.fail("Unexpected response payload structure"); } } assertOverallFailure(json); }
Example 10
Source File: BookJsonStore.java From cxf with Apache License 2.0 | 5 votes |
private Book bookFromJson(JsonObject obj) { final Book book = new Book(obj.getString("name"), obj.getInt("id")); final JsonArray chapters = (JsonArray)obj.get("chapters"); if (chapters != null && !chapters.isEmpty()) { for (final JsonObject chapter: chapters.getValuesAs(JsonObject.class)) { book.addChapter(chapter.getInt("id"), chapter.getString("title")); } } return book; }
Example 11
Source File: InventoryEventHandler.java From flowing-retail-old with Apache License 2.0 | 5 votes |
private ArrayList<Item> parseItems(JsonArray jsonArray) { ArrayList<Item> items = new ArrayList<Item>(); for (JsonObject itemJson : jsonArray.getValuesAs(JsonObject.class)) { items.add(new Item() // .setArticleId(itemJson.getString("articleId")) // .setAmount(itemJson.getInt("amount"))); } return items; }
Example 12
Source File: License.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
public static List<License> fromString(String serializedLicensesString) { if (serializedLicensesString == null) { return new ArrayList<>(); } if (serializedLicensesString.startsWith("[")) { List<License> licenses = new ArrayList<>(); try (JsonReader jsonReader = Json.createReader(new StringReader(serializedLicensesString))) { JsonArray licensesJson = jsonReader.readArray(); for (JsonObject licenseJson : licensesJson.getValuesAs(JsonObject.class)) { licenses.add(new License(licenseJson.getString("name"), licenseJson.getString("identifier"), licenseJson.getString("status"))); } } return licenses; } else if (serializedLicensesString.startsWith("{")) { return readLegacyJson(serializedLicensesString); } else { return readLegacySeparated(serializedLicensesString); } }
Example 13
Source File: MultipleReadinessFailedTest.java From microprofile-health with Apache License 2.0 | 5 votes |
/** * Verifies the readiness health integration with CDI at the scope of a server runtime */ @Test @RunAsClient public void testFailureResponsePayload() { Response response = getUrlReadyContents(); // status code Assert.assertEquals(response.getStatus(),503); JsonObject json = readJson(response); // response size JsonArray checks = json.getJsonArray("checks"); Assert.assertEquals(checks.size(), 2, "Expected two check responses"); for (JsonObject check : checks.getValuesAs(JsonObject.class)) { String id = check.getString("name"); switch (id) { case "successful-check": verifySuccessStatus(check); break; case "failed-check": verifyFailureStatus(check); break; default: Assert.fail("Unexpected response payload structure"); } } assertOverallFailure(json); }
Example 14
Source File: MultipleProceduresFailedTest.java From microprofile-health with Apache License 2.0 | 5 votes |
/** * Verifies the /health endpoint with the liveness and readiness integration with CDI at the scope of a server runtime */ @Test @RunAsClient public void testFailureResponsePayload() { Response response = getUrlHealthContents(); // status code Assert.assertEquals(response.getStatus(),503); JsonObject json = readJson(response); // response size JsonArray checks = json.getJsonArray("checks"); Assert.assertEquals(checks.size(), 3, "Expected four check responses"); // verify that all 3 procedures are present for (JsonObject check : checks.getValuesAs(JsonObject.class)) { String id = check.getString("name"); switch (id) { case "successful-check": verifySuccessStatus(check); break; case "failed-check": verifyFailureStatus(check); break; default: Assert.fail("Unexpected response payload structure"); } } assertOverallFailure(json); }
Example 15
Source File: SpringCloudRelease.java From spring-cloud-release-tools with Apache License 2.0 | 5 votes |
@Override @Cacheable("springCloudVersions") public Collection<String> getSpringCloudVersions() throws IOException { List<String> releaseVersions = new ArrayList<>(); JsonReader reader = github.entry().uri().path(SPRING_CLOUD_RELEASE_TAGS_PATH) .back().fetch().as(JsonResponse.class).json(); JsonArray tags = reader.readArray(); reader.close(); List<JsonObject> tagsList = tags.getValuesAs(JsonObject.class); for (JsonObject obj : tagsList) { releaseVersions.add(obj.getString("name").replaceFirst("v", "")); } return releaseVersions; }
Example 16
Source File: AllCustomFailedTest.java From smallrye-health with Apache License 2.0 | 5 votes |
/** * Verifies the custom health integration with CDI at the scope of a server runtime, by retrieving all the custom checks. */ @Test @RunAsClient public void testFailureResponsePayload() { Response response = getUrlAllCustomHealthContents(); // status code Assert.assertEquals(response.getStatus(), 503); JsonObject json = readJson(response); // response size JsonArray checks = json.getJsonArray("checks"); Assert.assertEquals(checks.size(), 2, "Expected two check responses"); for (JsonObject check : checks.getValuesAs(JsonObject.class)) { String id = check.getString("name"); switch (id) { case "successful-check": verifySuccessStatus(check); break; case "failed-check": verifyFailureStatus(check); break; default: Assert.fail("Unexpected response payload structure"); } } assertOverallFailure(json); }
Example 17
Source File: MultipleCustomFailedTest.java From smallrye-health with Apache License 2.0 | 5 votes |
/** * Verifies the custom health integration with CDI at the scope of a server runtime */ @Test @RunAsClient public void testFailureResponsePayload() { Response response = getUrlCustomHealthContents("group2"); // status code Assert.assertEquals(response.getStatus(), 503); JsonObject json = readJson(response); // response size JsonArray checks = json.getJsonArray("checks"); Assert.assertEquals(checks.size(), 2, "Expected two check responses"); for (JsonObject check : checks.getValuesAs(JsonObject.class)) { String id = check.getString("name"); switch (id) { case "successful-check": verifySuccessStatus(check); break; case "failed-check": verifyFailureStatus(check); break; default: Assert.fail("Unexpected response payload structure"); } } assertOverallFailure(json); }