use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method shouldRecoverAfterException.
@Test
public void shouldRecoverAfterException() throws Exception {
// This triggers 4 exceptions to exhaust the connection pool if there's a connection leak
for (int i = 0; i < 2; i++) {
sendTo(RECIPES_RESOURCE_URI + randomUUID()).request().post(recipeEntity("Exceptional cake"));
}
final String recipeId = "163af847-effb-46a9-96bc-32a0f7526f78";
final String recipeName = "Non exceptional cake";
addRecipe(recipeId, recipeName);
await().until(() -> queryForRecipe(recipeId).httpCode() == OK);
final ApiResponse response = queryForRecipe(recipeId);
with(response.body()).assertThat("$.id", equalTo(recipeId)).assertThat("$.name", equalTo(recipeName));
}
use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method shouldReturn404IfRecipeDoesNotExist.
@Test
public void shouldReturn404IfRecipeDoesNotExist() {
final ApiResponse response = queryForRecipe("163af847-effb-46a9-96bc-32a0f7526f00");
assertThat(response.httpCode(), is(NOT_FOUND));
}
use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method shouldReturn400WhenInvalidNumericParamPassed.
@Test
public void shouldReturn400WhenInvalidNumericParamPassed() {
final ApiResponse response = recipesQueryResult(asList(new BasicNameValuePair("pagesize", "invalid")));
assertThat(response.httpCode(), is(BAD_REQUEST));
}
use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method cakesQueryResult.
private ApiResponse cakesQueryResult() {
final Response jaxrsResponse = sendTo(CAKES_RESOURCE_QUERY_URI).request().accept(QUERY_CAKES_MEDIA_TYPE).get();
assertThat(jaxrsResponse.getStatus(), is(200));
return ApiResponse.from(jaxrsResponse);
}
use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method shouldReturnRecipeFromOtherEventListener.
@Test
public void shouldReturnRecipeFromOtherEventListener() throws Exception {
// adding 1 recipe as normal
final UUID recipeId = UUID.randomUUID();
addRecipe(recipeId.toString(), "Cheesy cheese cake");
// adding 1 recipe as other event
final UUID recipeId2 = UUID.randomUUID();
try (final Session jmsSession = jmsSession()) {
final Topic topic = jmsSession.createTopic("other.event");
try (final MessageProducer producer = jmsSession.createProducer(topic)) {
final JsonObject jsonObject = jsonObject().add("recipeId", recipeId2.toString()).add("name", "Chocolate muffin").add("glutenFree", true).add("ingredients", createArrayBuilder().add(createObjectBuilder().add("name", "someIngredient").add("quantity", 1)).build()).build();
final JsonEnvelope jsonEnvelope = envelopeFrom(metadataBuilder().withId(UUID.randomUUID()).withName("other.recipe-added").withStreamId(recipeId2).withVersion(1L).build(), jsonObject);
@SuppressWarnings("deprecation") final String json = jsonEnvelope.toDebugStringPrettyPrint();
final TextMessage message = jmsSession.createTextMessage();
message.setText(json);
message.setStringProperty("CPPNAME", "other.recipe-added");
producer.send(message);
}
}
await().until(() -> {
final String responseBody = recipesQueryResult(singletonList(new BasicNameValuePair("pagesize", "30"))).body();
return responseBody.contains(recipeId.toString()) && responseBody.contains(recipeId2.toString());
});
final ApiResponse response = recipesQueryResult();
assertThat(response.httpCode(), is(OK));
with(response.body()).assertThat("$.recipes[?(@.id=='" + recipeId + "')].name", hasItem("Cheesy cheese cake")).assertThat("$.recipes[?(@.id=='" + recipeId2 + "')].name", hasItem("Chocolate muffin"));
}
Aggregations