Search in sources :

Example 6 with ApiResponse

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));
}
Also used : ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse) Test(org.junit.Test)

Example 7 with ApiResponse

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));
}
Also used : ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse) Test(org.junit.Test)

Example 8 with ApiResponse

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));
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse) Test(org.junit.Test)

Example 9 with ApiResponse

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);
}
Also used : HttpResponse(org.apache.http.HttpResponse) Response(javax.ws.rs.core.Response) ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse)

Example 10 with ApiResponse

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"));
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) JsonObject(javax.json.JsonObject) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) MessageProducer(javax.jms.MessageProducer) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

ApiResponse (uk.gov.justice.services.example.cakeshop.it.util.ApiResponse)12 Test (org.junit.Test)10 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)6 Response (javax.ws.rs.core.Response)3 HttpResponse (org.apache.http.HttpResponse)3 UUID (java.util.UUID)2 UUID.randomUUID (java.util.UUID.randomUUID)2 URISyntaxException (java.net.URISyntaxException)1 MessageProducer (javax.jms.MessageProducer)1 Session (javax.jms.Session)1 TextMessage (javax.jms.TextMessage)1 Topic (javax.jms.Topic)1 JsonObject (javax.json.JsonObject)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)1