use of javax.ws.rs.core.Response in project druid by druid-io.
the class ExceptionalAbstractListenerHandler method testAbstractPostHandlerEmptyList.
@Test
public void testAbstractPostHandlerEmptyList() throws Exception {
final AbstractListenerHandler handler = new ExceptionalAbstractListenerHandler() {
@Override
public String post(Map<String, SomeBeanClass> inputObject) throws Exception {
return mapper.writeValueAsString(inputObject);
}
};
final ListenerResource resource = new ListenerResource(mapper, mapper, handler) {
};
final Response response = resource.serviceAnnouncementPOSTAll(EMPTY_JSON_MAP.openStream(), req);
Assert.assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
Assert.assertEquals("{}", response.getEntity());
}
use of javax.ws.rs.core.Response in project druid by druid-io.
the class SqlResourceTest method doPost.
// Returns either an error or a result.
private Pair<QueryInterruptedException, List<Map<String, Object>>> doPost(final SqlQuery query) throws Exception {
final Response response = resource.doPost(query);
if (response.getStatus() == 200) {
final StreamingOutput output = (StreamingOutput) response.getEntity();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
output.write(baos);
return Pair.of(null, JSON_MAPPER.<List<Map<String, Object>>>readValue(baos.toByteArray(), new TypeReference<List<Map<String, Object>>>() {
}));
} else {
return Pair.of(JSON_MAPPER.readValue((byte[]) response.getEntity(), QueryInterruptedException.class), null);
}
}
use of javax.ws.rs.core.Response in project dropwizard by dropwizard.
the class OptionalFormParamResourceTest method shouldReturnDefaultMessageWhenMessageIsNotPresent.
@Test
public void shouldReturnDefaultMessageWhenMessageIsNotPresent() throws IOException {
final String defaultMessage = "Default Message";
final Response response = target("/optional/message").request().post(Entity.form(new MultivaluedStringMap()));
assertThat(response.readEntity(String.class)).isEqualTo(defaultMessage);
}
use of javax.ws.rs.core.Response in project dropwizard by dropwizard.
the class OptionalFormParamResourceTest method shouldReturnMessageWhenMessageIsPresent.
@Test
public void shouldReturnMessageWhenMessageIsPresent() throws IOException {
final String customMessage = "Custom Message";
final Form form = new Form("message", customMessage);
final Response response = target("/optional/message").request().post(Entity.form(form));
assertThat(response.readEntity(String.class)).isEqualTo(customMessage);
}
use of javax.ws.rs.core.Response in project dropwizard by dropwizard.
the class OptionalFormParamResourceTest method shouldReturnDefaultMessageWhenMyMessageIsNotPresent.
@Test
public void shouldReturnDefaultMessageWhenMyMessageIsNotPresent() throws IOException {
final String defaultMessage = "My Default Message";
final Response response = target("/optional/my-message").request().post(Entity.form(new MultivaluedStringMap()));
assertThat(response.readEntity(String.class)).isEqualTo(defaultMessage);
}
Aggregations