Search in sources :

Example 1 with ApiResponse

use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.

the class CakeShopIT method shouldReturnOrderWithUTCOrderDate.

@Test
public void shouldReturnOrderWithUTCOrderDate() {
    final UUID orderId = randomUUID();
    final Response commandResponse = sendTo(ORDERS_RESOURCE_URI + orderId.toString()).request().post(entity(jsonObject().add("recipeId", randomUUID().toString()).add("deliveryDate", "2016-01-21T23:42:03.522+07:00").build().toString(), ORDER_CAKE_MEDIA_TYPE));
    assertThat(commandResponse.getStatus(), is(ACCEPTED));
    await().until(() -> queryForOrder(orderId.toString()).httpCode() == OK);
    final ApiResponse queryResponse = queryForOrder(orderId.toString());
    with(queryResponse.body()).assertThat("$.orderId", equalTo(orderId.toString())).assertThat("$.deliveryDate", equalTo("2016-01-21T16:42:03.522Z"));
}
Also used : HttpResponse(org.apache.http.HttpResponse) Response(javax.ws.rs.core.Response) ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse) Test(org.junit.Test)

Example 2 with ApiResponse

use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.

the class CakeShopIT method shouldReturnRecipeOfGivenId.

@Test
public void shouldReturnRecipeOfGivenId() {
    final String recipeId = "163af847-effb-46a9-96bc-32a0f7526f22";
    final String recipeName = "Cheesy cheese 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 3 with ApiResponse

use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.

the class CakeShopIT method shouldFilterGlutenFreeRecipes.

@Test
public void shouldFilterGlutenFreeRecipes() {
    // adding 2 recipes
    final String recipeId = "163af847-effb-46a9-96bc-32a0f7526e66";
    sendTo(RECIPES_RESOURCE_URI + recipeId).request().post(recipeEntity("Muffin", false));
    final String recipeId2 = "163af847-effb-46a9-96bc-32a0f7526e77";
    sendTo(RECIPES_RESOURCE_URI + recipeId2).request().post(recipeEntity("Oat cake", true));
    await().until(() -> recipesQueryResult().body().contains(recipeId2));
    final ApiResponse response = recipesQueryResult(asList(new BasicNameValuePair("pagesize", "30"), new BasicNameValuePair("glutenFree", "true")));
    assertThat(response.httpCode(), is(OK));
    with(response.body()).assertThat("$.recipes[?(@.id=='" + recipeId + "')]", emptyCollection()).assertThat("$.recipes[?(@.id=='" + recipeId2 + "')].name", hasItem("Oat cake"));
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse) Test(org.junit.Test)

Example 4 with ApiResponse

use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.

the class CakeShopIT method shouldReturnRecipes.

@Test
public void shouldReturnRecipes() {
    // adding 2 recipes
    final String recipeId = "163af847-effb-46a9-96bc-32a0f7526e14";
    addRecipe(recipeId, "Cheesy cheese cake");
    final String recipeId2 = "163af847-effb-46a9-96bc-32a0f7526e15";
    addRecipe(recipeId2, "Chocolate muffin");
    await().until(() -> {
        final String responseBody = recipesQueryResult(singletonList(new BasicNameValuePair("pagesize", "30"))).body();
        return responseBody.contains(recipeId) && responseBody.contains(recipeId2);
    });
    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) ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse) Test(org.junit.Test)

Example 5 with ApiResponse

use of uk.gov.justice.services.example.cakeshop.it.util.ApiResponse in project microservice_framework by CJSCommonPlatform.

the class CakeShopIT method recipesQueryResult.

private ApiResponse recipesQueryResult(final List<NameValuePair> queryParams) {
    try {
        final URIBuilder uri = new URIBuilder(RECIPES_RESOURCE_QUERY_URI);
        uri.addParameters(queryParams);
        final Response jaxrRsResponse = sendTo(uri.toString()).request().accept(QUERY_RECIPES_MEDIA_TYPE).get();
        return ApiResponse.from(jaxrRsResponse);
    } catch (URISyntaxException e) {
        fail(e.getMessage());
        return null;
    }
}
Also used : HttpResponse(org.apache.http.HttpResponse) Response(javax.ws.rs.core.Response) ApiResponse(uk.gov.justice.services.example.cakeshop.it.util.ApiResponse) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder)

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