Search in sources :

Example 6 with Recipe

use of uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe in project microservice_framework by CJSCommonPlatform.

the class RecipeEventListener method recipeRenamed.

@Handles("example.recipe-renamed")
public void recipeRenamed(final JsonEnvelope event) {
    final String recipeId = event.payloadAsJsonObject().getString(FIELD_RECIPE_ID);
    final String recipeName = event.payloadAsJsonObject().getString("name");
    LOGGER.trace("=============> Inside rename-recipe Event Listener. RecipeId: " + recipeId);
    final Recipe recipe = recipeRepository.findBy(UUID.fromString(recipeId));
    recipe.setName(recipeName);
    recipeRepository.save(recipe);
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 7 with Recipe

use of uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe in project microservice_framework by CJSCommonPlatform.

the class RecipeServiceTest method shouldReturnNullWhenPhotoIdNull.

@Test
public void shouldReturnNullWhenPhotoIdNull() {
    given(recipeRepository.findBy(RECIPE_ID)).willReturn(new Recipe(RECIPE_ID, NAME, GLUTEN_FREE, null));
    assertNull(service.findRecipePhoto(RECIPE_ID.toString()));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe) Test(org.junit.Test)

Example 8 with Recipe

use of uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe 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 9 with Recipe

use of uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe 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)

Example 10 with Recipe

use of uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe in project microservice_framework by CJSCommonPlatform.

the class RecipeRepositoryTest method removeAndAssertRecipe.

private void removeAndAssertRecipe(UUID recipeId) {
    Recipe foundRecipe = recipeRepository.findBy(recipeId);
    recipeRepository.remove(foundRecipe);
    Recipe recipeFound = recipeRepository.findBy(recipeId);
    Assert.assertNull(recipeFound);
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe)

Aggregations

Recipe (uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe)12 Test (org.junit.Test)8 Handles (uk.gov.justice.services.core.annotation.Handles)3 RecipeView (uk.gov.justice.services.example.cakeshop.query.view.response.RecipeView)3 RecipesView (uk.gov.justice.services.example.cakeshop.query.view.response.RecipesView)2 BaseTransactionalTest (uk.gov.justice.services.test.utils.persistence.BaseTransactionalTest)2 UUID (java.util.UUID)1 Ingredient (uk.gov.justice.services.example.cakeshop.domain.Ingredient)1 RecipeAdded (uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded)1 PhotoView (uk.gov.justice.services.example.cakeshop.query.view.response.PhotoView)1