Search in sources :

Example 1 with CalculateException

use of net.morimekta.test.providence.jax.rs.calculator.CalculateException in project providence by morimekta.

the class DropWizardIT method testProvidenceJson_exception.

@Test
public void testProvidenceJson_exception() throws IOException {
    Client client = new JerseyClientBuilder(drop_wizard.getEnvironment()).build("test-json-exception");
    Response response = client.target(uri("calculator/calculate")).register(DefaultProvidenceMessageBodyWriter.class).register(DefaultProvidenceMessageBodyReader.class).request().accept(JsonSerializer.MEDIA_TYPE).post(Entity.entity(new Operation(Operator.MULTIPLY, list(withNumber(52d), withImaginary(new Imaginary(1d, -1d)), withNumber(15d))), // same problem as with accept.
    JsonSerializer.MEDIA_TYPE));
    assertThat(response.getStatus(), is(equalTo(400)));
    assertThat(response.getHeaders().getFirst("Content-Type"), is(equalTo(JsonSerializer.MEDIA_TYPE)));
    CalculateException ex = response.readEntity(CalculateException.class);
    assertEquals("{\n" + "  message = \"Unsupported operation: MULTIPLY\"\n" + "  operation = {\n" + "    operator = MULTIPLY\n" + "    operands = [\n" + "      {\n" + "        number = 52\n" + "      },\n" + "      {\n" + "        imaginary = {\n" + "          v = 1\n" + "          i = -1\n" + "        }\n" + "      },\n" + "      {\n" + "        number = 15\n" + "      }\n" + "    ]\n" + "  }\n" + "}", debugString(ex));
}
Also used : Response(javax.ws.rs.core.Response) CalculateException(net.morimekta.test.providence.jax.rs.calculator.CalculateException) Operand.withImaginary(net.morimekta.test.providence.jax.rs.calculator.Operand.withImaginary) Imaginary(net.morimekta.test.providence.jax.rs.number.Imaginary) Operation(net.morimekta.test.providence.jax.rs.calculator.Operation) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Aggregations

JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)1 Client (javax.ws.rs.client.Client)1 Response (javax.ws.rs.core.Response)1 CalculateException (net.morimekta.test.providence.jax.rs.calculator.CalculateException)1 Operand.withImaginary (net.morimekta.test.providence.jax.rs.calculator.Operand.withImaginary)1 Operation (net.morimekta.test.providence.jax.rs.calculator.Operation)1 Imaginary (net.morimekta.test.providence.jax.rs.number.Imaginary)1 Test (org.junit.Test)1