Search in sources :

Example 86 with Response

use of javax.ws.rs.core.Response in project dropwizard by dropwizard.

the class ConstraintViolationExceptionMapperTest method invalidMapRequestEntities.

@Test
public void invalidMapRequestEntities() {
    final Response response = target("/valid/validExampleMap").request().post(Entity.json("{\"one\": {\"id\":-1}, \"two\": {\"id\":-2}}"));
    assertThat(response.getStatus()).isEqualTo(422);
    assertThat(response.readEntity(String.class)).isEqualTo("{\"errors\":[\"id must be greater than or equal to 0\"," + "\"id must be greater than or equal to 0\"]}");
}
Also used : Response(javax.ws.rs.core.Response) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Example 87 with Response

use of javax.ws.rs.core.Response in project dropwizard by dropwizard.

the class ConstraintViolationExceptionMapperTest method getInvalidHeaderParamsIs400.

@Test
public void getInvalidHeaderParamsIs400() throws Exception {
    final Response response = target("/valid/head").request().get();
    assertThat(response.getStatus()).isEqualTo(400);
    String ret = "{\"errors\":[\"header cheese may not be empty\"]}";
    assertThat(response.readEntity(String.class)).isEqualTo(ret);
}
Also used : Response(javax.ws.rs.core.Response) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Example 88 with Response

use of javax.ws.rs.core.Response in project dropwizard by dropwizard.

the class ConstraintViolationExceptionMapperTest method invalidEntityExceptionForPartialValidatedRequestEntities.

@Test
public void invalidEntityExceptionForPartialValidatedRequestEntities() {
    final Response response = target("/valid/validatedPartialExampleBoth").request().post(Entity.json("{\"id\":1}"));
    assertThat(response.getStatus()).isEqualTo(422);
    assertThat(response.readEntity(String.class)).isEqualTo("{\"errors\":[\"text may not be null\"]}");
}
Also used : Response(javax.ws.rs.core.Response) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Example 89 with Response

use of javax.ws.rs.core.Response in project dropwizard by dropwizard.

the class ConstraintViolationExceptionMapperTest method getInvalidCustomTypeIs400.

@Test
public void getInvalidCustomTypeIs400() throws Exception {
    // query parameter is too short and so will fail validation
    final Response response = target("/valid/barter").queryParam("name", "hi").request().get();
    assertThat(response.getStatus()).isEqualTo(400);
    String ret = "{\"errors\":[\"query param name length must be between 3 and 2147483647\"]}";
    assertThat(response.readEntity(String.class)).isEqualTo(ret);
}
Also used : Response(javax.ws.rs.core.Response) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Example 90 with Response

use of javax.ws.rs.core.Response in project dropwizard by dropwizard.

the class ConstraintViolationExceptionMapperTest method returnsValidatedMapRequestEntities.

@Test
public void returnsValidatedMapRequestEntities() {
    final Response response = target("/valid/validExampleMap").request().post(Entity.json("{\"one\": {\"id\":1}, \"two\": {\"id\":2}}"));
    assertThat(response.getStatus()).isEqualTo(200);
    Map<String, Example> map = response.readEntity(new GenericType<Map<String, Example>>() {
    });
    assertThat(map.get("one").id).isEqualTo(1);
    assertThat(map.get("two").id).isEqualTo(2);
}
Also used : Response(javax.ws.rs.core.Response) Example(io.dropwizard.jersey.jackson.JacksonMessageBodyProviderTest.Example) PartialExample(io.dropwizard.jersey.jackson.JacksonMessageBodyProviderTest.PartialExample) ListExample(io.dropwizard.jersey.jackson.JacksonMessageBodyProviderTest.ListExample) Map(java.util.Map) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Aggregations

Response (javax.ws.rs.core.Response)3808 Test (org.junit.Test)2883 JerseyTest (org.glassfish.jersey.test.JerseyTest)849 Test (org.testng.annotations.Test)342 Builder (javax.ws.rs.client.Invocation.Builder)298 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)287 WebTarget (javax.ws.rs.client.WebTarget)278 BaseTest (org.xdi.oxauth.BaseTest)274 Parameters (org.testng.annotations.Parameters)271 DBUnitTest (org.orcid.test.DBUnitTest)270 JSONException (org.codehaus.jettison.json.JSONException)253 URI (java.net.URI)230 JSONObject (org.codehaus.jettison.json.JSONObject)181 Path (javax.ws.rs.Path)153 Matchers.containsString (org.hamcrest.Matchers.containsString)142 URISyntaxException (java.net.URISyntaxException)124 ResponseType (org.xdi.oxauth.model.common.ResponseType)120 Produces (javax.ws.rs.Produces)113 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)105 GET (javax.ws.rs.GET)104