use of uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded 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.domain.event.RecipeAdded in project microservice_framework by CJSCommonPlatform.
the class RecipeTest method shouldReturnEventWhenApplied.
@Test
public void shouldReturnEventWhenApplied() {
RecipeAdded event = mock(RecipeAdded.class);
assertThat(recipe.apply(event), equalTo(event));
}
use of uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded in project microservice_framework by CJSCommonPlatform.
the class RecipeTest method shouldReturnRecipeAddedEvent.
@Test
public void shouldReturnRecipeAddedEvent() {
final Stream<Object> events = recipe.addRecipe(RECIPE_ID, NAME, true, INGREDIENTS);
final List<Object> eventList = events.collect(toList());
assertThat(eventList, hasSize(1));
final Object event = eventList.get(0);
assertThat(event, instanceOf(RecipeAdded.class));
final RecipeAdded recipeAdded = (RecipeAdded) event;
assertThat(recipeAdded.getRecipeId(), equalTo(RECIPE_ID));
assertThat(recipeAdded.getName(), equalTo(NAME));
assertThat(recipeAdded.getIngredients(), equalTo(INGREDIENTS));
assertThat(recipeAdded.isGlutenFree(), is(true));
}
use of uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded 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());
}
}
}
use of uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded in project microservice_framework by CJSCommonPlatform.
the class MakeCakeCommandHandlerTest method shouldHandleMakeCakeCommand.
@SuppressWarnings("unchecked")
@Test
public void shouldHandleMakeCakeCommand() throws Exception {
final Recipe recipe = new Recipe();
final String cakeName = "Chocolate cake";
recipe.apply(new RecipeAdded(RECIPE_ID, cakeName, false, EMPTY_LIST));
when(eventSource.getStreamById(RECIPE_ID)).thenReturn(eventStream);
when(aggregateService.get(eventStream, Recipe.class)).thenReturn(recipe);
final JsonEnvelope command = envelopeFrom(metadataWithRandomUUID(COMMAND_NAME), createObjectBuilder().add("recipeId", RECIPE_ID.toString()).add("cakeId", CAKE_ID.toString()).build());
makeCakeCommandHandler.makeCake(command);
assertThat(eventStream, eventStreamAppendedWith(streamContaining(jsonEnvelope(withMetadataEnvelopedFrom(command).withName(EVENT_NAME), payloadIsJson(allOf(withJsonPath("$.cakeId", equalTo(CAKE_ID.toString())), withJsonPath("$.name", equalTo(cakeName))))).thatMatchesSchema())).withToleranceOf(CONSECUTIVE));
}
Aggregations