Search in sources :

Example 1 with RecipeView

use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView in project microservice_framework by CJSCommonPlatform.

the class RecipeServiceTest method shouldReturnRecipeById.

@Test
public void shouldReturnRecipeById() {
    given(recipeRepository.findBy(RECIPE_ID)).willReturn(new Recipe(RECIPE_ID, NAME, GLUTEN_FREE, PHOTO_ID));
    RecipeView foundPerson = service.findRecipe(RECIPE_ID.toString());
    assertThat(foundPerson.getId(), equalTo(RECIPE_ID));
    assertThat(foundPerson.getName(), equalTo(NAME));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Example 2 with RecipeView

use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView in project microservice_framework by CJSCommonPlatform.

the class RecipesQueryViewTest method shouldReturnResponseWithMetadataWhenQueryingForRecipe.

@Test
public void shouldReturnResponseWithMetadataWhenQueryingForRecipe() {
    final UUID recipeId = randomUUID();
    final String recipeName = "some recipe name";
    when(service.findRecipe(recipeId.toString())).thenReturn(new RecipeView(recipeId, recipeName, false));
    final Envelope<JsonObject> envelope = envelopeFrom(metadataWithDefaults(), createObjectBuilder().add("recipeId", recipeId.toString()).build());
    final Envelope<RecipeView> response = queryView.findRecipe(envelope);
    final RecipeView payload = response.payload();
    assertThat(payload.getName(), is(response.payload().getName()));
    assertThat(payload.getId(), is(response.payload().getId()));
}
Also used : JsonObject(javax.json.JsonObject) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Example 3 with RecipeView

use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView in project microservice_framework by CJSCommonPlatform.

the class RecipesQueryViewTest method shouldReturnRecipesForQuery.

@Test
public void shouldReturnRecipesForQuery() throws Exception {
    final UUID recipeId = randomUUID();
    final UUID recipeId2 = randomUUID();
    final String recipeName = "some recipe name";
    final String recipeName2 = "some other recipe name";
    final int pagesize = 5;
    when(service.getRecipes(pagesize, Optional.of(recipeName), Optional.of(false))).thenReturn(new RecipesView(asList(new RecipeView(recipeId, recipeName, false), new RecipeView(recipeId2, recipeName2, false))));
    final SearchRecipes searchRecipes = new SearchRecipes(pagesize);
    searchRecipes.setName(recipeName);
    searchRecipes.setGlutenFree(false);
    final Envelope<SearchRecipes> envelope = envelopeFrom(metadataWithDefaults(), searchRecipes);
    final Envelope<RecipesView> response = queryView.queryRecipes(envelope);
    final RecipesView payload = response.payload();
    assertThat(payload.getRecipes().get(0).getName(), is(searchRecipes.getName()));
}
Also used : SearchRecipes(uk.gov.justice.services.example.cakeshop.query.view.request.SearchRecipes) RecipesView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Example 4 with RecipeView

use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView in project microservice_framework by CJSCommonPlatform.

the class RecipeServiceTest method shouldGetRecipes2.

@Test
public void shouldGetRecipes2() {
    int pageSize = 10;
    Optional<String> nameQueryParam = Optional.of("other name");
    Optional<Boolean> glutenFreeQueryParam = Optional.empty();
    given(recipeRepository.findBy(pageSize, nameQueryParam, glutenFreeQueryParam)).willReturn(singletonList(new Recipe(RECIPE_ID, NAME, GLUTEN_FREE, PHOTO_ID)));
    RecipesView recipes = service.getRecipes(pageSize, nameQueryParam, glutenFreeQueryParam);
    List<RecipeView> firstRecipe = recipes.getRecipes();
    assertThat(firstRecipe, hasSize(1));
    assertThat(firstRecipe.get(0).getId(), equalTo(RECIPE_ID));
    assertThat(firstRecipe.get(0).getName(), equalTo(NAME));
    assertThat(firstRecipe.get(0).isGlutenFree(), is(GLUTEN_FREE));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) RecipesView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Example 5 with RecipeView

use of uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView in project microservice_framework by CJSCommonPlatform.

the class RecipeServiceTest method shouldGetRecipes.

@Test
public void shouldGetRecipes() {
    int pageSize = 20;
    Optional<String> nameQueryParam = Optional.of("name123");
    Optional<Boolean> glutenFreeQueryParam = Optional.of(false);
    given(recipeRepository.findBy(pageSize, nameQueryParam, glutenFreeQueryParam)).willReturn(singletonList(new Recipe(RECIPE_ID, NAME, GLUTEN_FREE, PHOTO_ID)));
    RecipesView recipes = service.getRecipes(pageSize, nameQueryParam, glutenFreeQueryParam);
    List<RecipeView> firstRecipe = recipes.getRecipes();
    assertThat(firstRecipe, hasSize(1));
    assertThat(firstRecipe.get(0).getId(), equalTo(RECIPE_ID));
    assertThat(firstRecipe.get(0).getName(), equalTo(NAME));
    assertThat(firstRecipe.get(0).isGlutenFree(), is(GLUTEN_FREE));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) RecipesView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView) RecipeView(uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 RecipeView (uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView)9 UUID (java.util.UUID)6 UUID.randomUUID (java.util.UUID.randomUUID)6 RecipesView (uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView)6 JsonObject (javax.json.JsonObject)5 Recipe (uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe)3 SearchRecipes (uk.gov.justice.services.example.cakeshop.query.view.request.SearchRecipes)1