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));
}
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()));
}
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);
}
}
}
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());
}
}
}
Aggregations