use of uk.gov.justice.services.example.cakeshop.domain.Ingredient in project microservice_framework by CJSCommonPlatform.
the class RecipeCommandHandler method addRecipe.
@Handles("example.command.add-recipe")
public void addRecipe(final JsonEnvelope command) throws EventStreamException {
LOGGER.trace("=============> Inside add-recipe Command Handler. RecipeId: " + command.payloadAsJsonObject().getString(FIELD_RECIPE_ID));
final UUID recipeId = getUUID(command.payloadAsJsonObject(), FIELD_RECIPE_ID).get();
final String name = getString(command.payloadAsJsonObject(), FIELD_NAME).get();
final Boolean glutenFree = getBoolean(command.payloadAsJsonObject(), FIELD_GLUTEN_FREE).get();
final List<Ingredient> ingredients = ingredientsFrom(command.payloadAsJsonObject());
final EventStream eventStream = eventSource.getStreamById(recipeId);
final Recipe recipe = aggregateService.get(eventStream, Recipe.class);
eventStream.append(recipe.addRecipe(recipeId, name, glutenFree, ingredients).map(toEnvelopeWithMetadataFrom(command)));
}
use of uk.gov.justice.services.example.cakeshop.domain.Ingredient in project microservice_framework by CJSCommonPlatform.
the class RecipeAddedToRecipeConverterTest method shouldConvertRecipeAddedEvent.
@Test
public void shouldConvertRecipeAddedEvent() {
final String name = "someName123";
final UUID recipeId = UUID.randomUUID();
final boolean glutenFree = true;
final List<Ingredient> ingredients = Collections.singletonList(new Ingredient("sugar", 2));
Recipe recipe = converter.convert(new RecipeAdded(recipeId, name, glutenFree, ingredients));
assertThat(recipe.getName(), equalTo(name));
assertThat(recipe.getId(), equalTo(recipeId));
assertThat(recipe.isGlutenFree(), equalTo(glutenFree));
}
Aggregations