Search in sources :

Example 81 with JsonObject

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"));
}
Also used : JsonObject(jakarta.json.JsonObject) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 82 with JsonObject

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"));
}
Also used : JsonObject(jakarta.json.JsonObject) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 83 with JsonObject

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' ");
}
Also used : JsonObject(jakarta.json.JsonObject) Test(org.junit.jupiter.api.Test) HelidonTest(io.helidon.microprofile.tests.junit5.HelidonTest)

Example 84 with JsonObject

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;
}
Also used : JsonException(jakarta.json.JsonException) JsonObject(jakarta.json.JsonObject)

Example 85 with JsonObject

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());
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) JsonObject(jakarta.json.JsonObject) Test(org.junit.jupiter.api.Test)

Aggregations

JsonObject (jakarta.json.JsonObject)356 Test (org.junit.Test)125 Test (org.junit.jupiter.api.Test)92 JsonArray (jakarta.json.JsonArray)29 Response (jakarta.ws.rs.core.Response)29 JsonObjectBuilder (jakarta.json.JsonObjectBuilder)24 JsonString (jakarta.json.JsonString)24 JsonValue (jakarta.json.JsonValue)20 WebClientResponse (io.helidon.webclient.WebClientResponse)19 Client (jakarta.ws.rs.client.Client)18 StringReader (java.io.StringReader)17 HelidonTest (io.helidon.microprofile.tests.junit5.HelidonTest)15 JsonReader (jakarta.json.JsonReader)14 List (java.util.List)14 JsonException (jakarta.json.JsonException)13 Map (java.util.Map)13 Logger (java.util.logging.Logger)13 Routing (io.helidon.webserver.Routing)11 Json (jakarta.json.Json)11 Produces (jakarta.ws.rs.Produces)11