Search in sources :

Example 1 with Ingredient

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

the class IngredientRepositoryTest method shouldFindIngredientById.

@Test
public void shouldFindIngredientById() {
    Ingredient ingredient = ingredientRepository.findBy(INGREDIENT);
    assertThat(ingredient, is(notNullValue()));
    assertThat(ingredient.getId(), equalTo(INGREDIENT));
    assertThat(ingredient.getName(), equalTo(INGREDIENT_NAME_A));
}
Also used : Ingredient(uk.gov.justice.services.example.cakeshop.persistence.entity.Ingredient) Test(org.junit.Test) BaseTransactionalTest(uk.gov.justice.services.test.utils.persistence.BaseTransactionalTest)

Example 2 with Ingredient

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

the class IngredientRepositoryTest method shouldReturnNullIfIngredientNotFound.

@Test
public void shouldReturnNullIfIngredientNotFound() {
    Ingredient ingredient = ingredientRepository.findBy(UUID.randomUUID());
    assertThat(ingredient, is(nullValue()));
}
Also used : Ingredient(uk.gov.justice.services.example.cakeshop.persistence.entity.Ingredient) Test(org.junit.Test) BaseTransactionalTest(uk.gov.justice.services.test.utils.persistence.BaseTransactionalTest)

Example 3 with Ingredient

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

the class OtherRecipeEventListener method recipeAdded.

@Handles("other.recipe-added")
public void recipeAdded(final JsonEnvelope event) {
    final RecipeAdded recipeAdded = jsonObjectConverter.convert(event.payloadAsJsonObject(), RecipeAdded.class);
    recipeRepository.save(otherRecipeAddedToRecipeConverter.convert(recipeAdded));
    for (final Ingredient ingredient : recipeAddedToIngredientsConverter.convert(recipeAdded)) {
        if (ingredientRepository.findByNameIgnoreCase(ingredient.getName()).isEmpty()) {
            ingredientRepository.save(ingredient);
        }
    }
}
Also used : RecipeAdded(uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded) Ingredient(uk.gov.justice.services.example.cakeshop.persistence.entity.Ingredient) Handles(uk.gov.justice.services.core.annotation.Handles)

Example 4 with Ingredient

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

the class RecipeEventListener method recipeAdded.

@Handles("example.recipe-added")
public void recipeAdded(final JsonEnvelope event) {
    final String recipeId = event.payloadAsJsonObject().getString(FIELD_RECIPE_ID);
    LOGGER.trace("=============> Inside add-recipe Event Listener. RecipeId: " + recipeId);
    final RecipeAdded recipeAdded = jsonObjectConverter.convert(event.payloadAsJsonObject(), RecipeAdded.class);
    recipeRepository.save(recipeAddedToRecipeConverter.convert(recipeAdded));
    LOGGER.trace("=====================================================> Recipe saved, RecipeId: " + recipeId);
    for (final Ingredient ingredient : recipeAddedToIngredientsConverter.convert(recipeAdded)) {
        if (ingredientRepository.findByNameIgnoreCase(ingredient.getName()).isEmpty()) {
            LOGGER.trace("=============> Inside add-recipe Event Listener about to save Ingredient Id: " + ingredient.getId());
            ingredientRepository.save(ingredient);
            LOGGER.trace("=====================================================> Ingredient saved, Ingredient Id: " + ingredient.getId());
        } else {
            LOGGER.trace("=====================================================> Skipped adding ingredient as it already exists, Ingredient Name: " + ingredient.getName());
        }
    }
}
Also used : RecipeAdded(uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded) Ingredient(uk.gov.justice.services.example.cakeshop.persistence.entity.Ingredient) Handles(uk.gov.justice.services.core.annotation.Handles)

Aggregations

Ingredient (uk.gov.justice.services.example.cakeshop.persistence.entity.Ingredient)4 Test (org.junit.Test)2 Handles (uk.gov.justice.services.core.annotation.Handles)2 RecipeAdded (uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded)2 BaseTransactionalTest (uk.gov.justice.services.test.utils.persistence.BaseTransactionalTest)2