use of net.morimekta.test.providence.jax.rs.calculator.Operation in project providence by morimekta.
the class DropWizardIT method testProvidenceJson.
@Test
public void testProvidenceJson() throws IOException {
Client client = new JerseyClientBuilder(drop_wizard.getEnvironment()).build("test-json");
Response response = client.target(uri("calculator/calculate")).register(DefaultProvidenceMessageBodyWriter.class).register(DefaultProvidenceMessageBodyReader.class).request().accept(JsonSerializer.MEDIA_TYPE).post(Entity.entity(new Operation(Operator.ADD, list(withNumber(52d), withImaginary(new Imaginary(1d, -1d)), withNumber(15d))), // same problem as with accept.
JsonSerializer.MEDIA_TYPE));
assertThat(response.getStatus(), is(equalTo(200)));
assertThat(response.getHeaders().getFirst("Content-Type"), is(equalTo(JsonSerializer.MEDIA_TYPE)));
Operand op = response.readEntity(Operand.class);
assertThat(debugString(op), is(equalTo("{\n" + " imaginary = {\n" + " v = 68\n" + " i = -1\n" + " }\n" + "}")));
}
use of net.morimekta.test.providence.jax.rs.calculator.Operation 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));
}
use of net.morimekta.test.providence.jax.rs.calculator.Operation in project providence by morimekta.
the class DropWizardIT method testProvidenceServlet.
@Test
public void testProvidenceServlet() throws IOException, CalculateException {
// This test is just to prove that the providence servlet can be used in dropwizard too.
Calculator.Iface client = new Calculator.Client(new HttpClientHandler(() -> new GenericUrl(uri("test")), factory(), new DefaultSerializerProvider()));
Operand result = client.calculate(new Operation(Operator.ADD, list(withNumber(52d), withImaginary(new Imaginary(1d, -1d)), withNumber(15d))));
assertThat(debugString(result), is(equalTo("{\n" + " imaginary = {\n" + " v = 68\n" + " i = -1\n" + " }\n" + "}")));
}
use of net.morimekta.test.providence.jax.rs.calculator.Operation in project providence by morimekta.
the class DropWizardIT method testProvidenceBinary.
@Test
public void testProvidenceBinary() throws IOException {
Client client = new JerseyClientBuilder(drop_wizard.getEnvironment()).build("test-binary");
Response response = client.target(uri("calculator/calculate")).register(DefaultProvidenceMessageBodyWriter.class).register(DefaultProvidenceMessageBodyReader.class).request().accept(BinarySerializer.MEDIA_TYPE).post(Entity.entity(new Operation(Operator.ADD, list(withNumber(52d), withImaginary(new Imaginary(1d, -1d)), withNumber(15d))), BinarySerializer.MEDIA_TYPE));
assertThat(response.getStatus(), is(equalTo(200)));
assertThat(response.getHeaders().getFirst("Content-Type"), is(equalTo(BinarySerializer.MEDIA_TYPE)));
Operand op = response.readEntity(Operand.class);
assertThat(debugString(op), is(equalTo("{\n" + " imaginary = {\n" + " v = 68\n" + " i = -1\n" + " }\n" + "}")));
}
Aggregations