Search in sources :

Example 6 with JsonObject

use of jakarta.json.JsonObject in project resteasy by resteasy.

the class JsonpResource method object.

@Path("structure")
@POST
@Produces("application/json")
@Consumes("application/json")
public JsonStructure object(JsonStructure struct) {
    JsonObject obj = (JsonObject) struct;
    Assert.assertTrue("The field 'name' didn't propagated correctly from the request", obj.containsKey("name"));
    Assert.assertEquals("The value of field 'name' didn't propagated correctly from the request", obj.getJsonString("name").getString(), "Bill");
    return obj;
}
Also used : JsonObject(jakarta.json.JsonObject) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Produces(jakarta.ws.rs.Produces) Consumes(jakarta.ws.rs.Consumes)

Example 7 with JsonObject

use of jakarta.json.JsonObject in project resteasy by resteasy.

the class JsonpResource method array.

@Path("array")
@POST
@Produces("application/json")
@Consumes("application/json")
public JsonArray array(JsonArray array) {
    Assert.assertEquals("The request didn't contain 2 json elements", 2, array.size());
    JsonObject obj = array.getJsonObject(0);
    Assert.assertTrue("The field 'name' didn't propagated correctly from the request for object[0]", obj.containsKey("name"));
    Assert.assertEquals("The value of field 'name' didn't propagated correctly from the request for object[0]", obj.getJsonString("name").getString(), "Bill");
    obj = array.getJsonObject(1);
    Assert.assertTrue("The field 'name' didn't propagated correctly from the request for object[1]", obj.containsKey("name"));
    Assert.assertEquals("The value of field 'name' didn't propagated correctly from the request for object[1]", obj.getJsonString("name").getString(), "Monica");
    return array;
}
Also used : JsonObject(jakarta.json.JsonObject) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Produces(jakarta.ws.rs.Produces) Consumes(jakarta.ws.rs.Consumes)

Example 8 with JsonObject

use of jakarta.json.JsonObject in project resteasy by resteasy.

the class AbstractDigestAuthenticationTest method digestAuthMultipleRequestsNoCache.

@Test
public void digestAuthMultipleRequestsNoCache() throws Exception {
    try (Client client = ClientBuilder.newBuilder().register(HttpAuthenticators.digest(-1, CREDENTIALS_USER_1)).build()) {
        Response response = client.target(TestUtil.generateUri(url, "user")).request(MediaType.APPLICATION_JSON_TYPE).get();
        Assert.assertEquals(Response.Status.OK, response.getStatusInfo());
        JsonObject json = response.readEntity(JsonObject.class);
        validate(json, 1);
        response = client.target(TestUtil.generateUri(url, "user")).request(MediaType.APPLICATION_JSON_TYPE).get();
        Assert.assertEquals(Response.Status.OK, response.getStatusInfo());
        json = response.readEntity(JsonObject.class);
        validate(json, 1);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) JsonObject(jakarta.json.JsonObject) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Example 9 with JsonObject

use of jakarta.json.JsonObject in project resteasy by resteasy.

the class AbstractDigestAuthenticationTest method digestAuth.

@Test
public void digestAuth() throws Exception {
    try (Client client = ClientBuilder.newBuilder().register(HttpAuthenticators.digest(CREDENTIALS_USER_1)).build()) {
        final Response response = client.target(TestUtil.generateUri(url, "user")).request(MediaType.APPLICATION_JSON_TYPE).get();
        Assert.assertEquals(Response.Status.OK, response.getStatusInfo());
        final JsonObject json = response.readEntity(JsonObject.class);
        validate(json);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) JsonObject(jakarta.json.JsonObject) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Example 10 with JsonObject

use of jakarta.json.JsonObject in project resteasy by resteasy.

the class AbstractDigestAuthenticationTest method digestAuthUser2.

@Test
public void digestAuthUser2() throws Exception {
    try (Client client = ClientBuilder.newBuilder().register(HttpAuthenticators.digest(CREDENTIALS_USER_2)).build()) {
        final Response response = client.target(TestUtil.generateUri(url, "user")).request(MediaType.APPLICATION_JSON_TYPE).get();
        Assert.assertEquals(Response.Status.OK, response.getStatusInfo());
        final JsonObject json = response.readEntity(JsonObject.class);
        validate(USER_2, json, 1);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) JsonObject(jakarta.json.JsonObject) Client(jakarta.ws.rs.client.Client) Test(org.junit.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