use of jakarta.json.JsonObject in project helidon by oracle.
the class MainTest method testDefaultGreeting.
@Test
@Order(1)
void testDefaultGreeting() {
JsonObject jsonObject = get();
Assertions.assertEquals("Hello World!", jsonObject.getString("greeting"));
}
use of jakarta.json.JsonObject in project helidon by oracle.
the class MainTest method testNamedGreeting.
@Test
@Order(2)
void testNamedGreeting() {
JsonObject jsonObject = personalizedGet("Joe");
Assertions.assertEquals("Hello Joe!", jsonObject.getString("greeting"));
}
use of jakarta.json.JsonObject in project helidon by oracle.
the class MicrostreamExampleGreetingsMpTest method testGreeting.
@Test
void testGreeting() {
JsonObject response = webTarget.path("/greet").request().get(JsonObject.class);
assertEquals("Hello World!", response.getString("message"), "response should be 'Hello World' ");
}
use of jakarta.json.JsonObject in project helidon by oracle.
the class GreetingService method processErrors.
private static <T> T processErrors(Throwable ex, ServerRequest request, ServerResponse response) {
ex.printStackTrace();
if (ex.getCause() instanceof JsonException) {
LOGGER.log(Level.FINE, "Invalid JSON", ex);
JsonObject jsonErrorObject = JSON.createObjectBuilder().add("error", "Invalid JSON").build();
response.status(Http.Status.BAD_REQUEST_400).send(jsonErrorObject);
} else {
LOGGER.log(Level.FINE, "Internal error", ex);
JsonObject jsonErrorObject = JSON.createObjectBuilder().add("error", "Internal error").build();
response.status(Http.Status.INTERNAL_SERVER_ERROR_500).send(jsonErrorObject);
}
return null;
}
use of jakarta.json.JsonObject in project helidon by oracle.
the class MainTest method testHelloWorld.
@Test
public void testHelloWorld() {
JsonObject jsonObject;
WebClientResponse response;
jsonObject = webClient.get().path("/greet").request(JsonObject.class).await();
assertEquals("Hello World!", jsonObject.getString("message"));
jsonObject = webClient.get().path("/greet/Joe").request(JsonObject.class).await();
assertEquals("Hello Joe!", jsonObject.getString("message"));
response = webClient.put().path("/greet/greeting").submit(TEST_JSON_OBJECT).await();
assertEquals(204, response.status().code());
jsonObject = webClient.get().path("/greet/Joe").request(JsonObject.class).await();
assertEquals("Hola Joe!", jsonObject.getString("message"));
response = webClient.get().path("/metrics").request().await();
assertEquals(200, response.status().code());
}
Aggregations