use of uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe in project microservice_framework by CJSCommonPlatform.
the class RecipeCommandHandler method removeRecipe.
@Handles("example.command.remove-recipe")
public void removeRecipe(final JsonEnvelope command) throws EventStreamException {
LOGGER.trace("=============> Inside remove-recipe Command Handler. RecipeId: " + command.payloadAsJsonObject().getString(FIELD_RECIPE_ID));
final UUID recipeId = getUUID(command.payloadAsJsonObject(), FIELD_RECIPE_ID).get();
final EventStream eventStream = eventSource.getStreamById(recipeId);
final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
eventStream.append(recipe.removeRecipe().map(toEnvelopeWithMetadataFrom(command)));
}
use of uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe 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));
}
use of uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe in project microservice_framework by CJSCommonPlatform.
the class RecipeCommandHandlerTest method shouldHandleAddRecipeCommand.
@Test
public void shouldHandleAddRecipeCommand() throws Exception {
final Recipe recipe = new Recipe();
final UUID commandId = randomUUID();
final JsonEnvelope command = envelopeFrom(metadataOf(commandId, ADD_RECIPE_COMMAND_NAME), createObjectBuilder().add("recipeId", RECIPE_ID.toString()).add("name", RECIPE_NAME).add("glutenFree", GULTEN_FREE).add("ingredients", createArrayBuilder().add(createObjectBuilder().add("name", "Flour").add("quantity", 200))).build());
when(eventSource.getStreamById(RECIPE_ID)).thenReturn(eventStream);
when(aggregateService.get(eventStream, Recipe.class)).thenReturn(recipe);
recipeCommandHandler.addRecipe(command);
assertThat(eventStream, eventStreamAppendedWith(streamContaining(jsonEnvelope(withMetadataEnvelopedFrom(command).withName(ADD_RECIPE_EVENT_NAME), payloadIsJson(allOf(withJsonPath("$.recipeId", equalTo(RECIPE_ID.toString())), withJsonPath("$.name", equalTo(RECIPE_NAME)), withJsonPath("$.glutenFree", equalTo(GULTEN_FREE)), withJsonPath("$.ingredients.length()", equalTo(1)), withJsonPath("$.ingredients[0].name", equalTo("Flour")), withJsonPath("$.ingredients[0].quantity", equalTo(200))))).thatMatchesSchema())));
}
use of uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe in project microservice_framework by CJSCommonPlatform.
the class RecipeCommandHandlerTest method existingRecipe.
private Recipe existingRecipe() {
final Recipe recipe = new Recipe();
recipe.apply(new RecipeAdded(RECIPE_ID, RECIPE_NAME, GULTEN_FREE, emptyList()));
return recipe;
}
Aggregations