Search in sources :

Example 16 with Handles

use of uk.gov.justice.services.core.annotation.Handles in project microservice_framework by CJSCommonPlatform.

the class RestClientGenerator_CodeStructureTest method shouldGenerateMethodAnnotatedWithHandlesAnnotationForPOST.

@Test
public void shouldGenerateMethodAnnotatedWithHandlesAnnotationForPOST() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path/{recipeId}").with(httpAction(POST, "application/vnd.cakeshop.command.create-recipe+json").withDescription(POST_MAPPING_ANNOTATION))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withServiceComponentOf("CUSTOM_COMPONENT")));
    final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "RemoteCustomComponent2ServiceCommandApi");
    final List<Method> methods = methodsOf(clazz);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    final Handles handlesAnnotation = method.getAnnotation(Handles.class);
    assertThat(method.getName(), equalTo("postSomePathRecipeIdCakeshopCommandCreateRecipe"));
    assertThat(handlesAnnotation, not(nullValue()));
    assertThat(handlesAnnotation.value(), is("cakeshop.create-recipe"));
}
Also used : Handles(uk.gov.justice.services.core.annotation.Handles) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 17 with Handles

use of uk.gov.justice.services.core.annotation.Handles in project microservice_framework by CJSCommonPlatform.

the class RestClientGenerator_CodeStructureTest method shouldGenerateMethodAnnotatedWithHandlesAnnotationForPATCH.

@Test
public void shouldGenerateMethodAnnotatedWithHandlesAnnotationForPATCH() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path/{recipeId}").with(httpAction(PATCH, "application/vnd.cakeshop.command.patch-recipe+json").withDescription(PATCH_MAPPING_ANNOTATION))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withServiceComponentOf("CUSTOM_COMPONENT")));
    final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "RemoteCustomComponent2ServiceCommandApi");
    final List<Method> methods = methodsOf(clazz);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    assertThat(method.getName(), equalTo("patchSomePathRecipeIdCakeshopCommandPatchRecipe"));
    final Handles handlesAnnotation = method.getAnnotation(Handles.class);
    assertThat(handlesAnnotation, not(nullValue()));
    assertThat(handlesAnnotation.value(), is("cakeshop.patch-recipe"));
}
Also used : Handles(uk.gov.justice.services.core.annotation.Handles) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 18 with Handles

use of uk.gov.justice.services.core.annotation.Handles in project microservice_framework by CJSCommonPlatform.

the class MessagingClientGenerator_CodeStructureTest method shouldGenerateMethodAnnotatedWithHandlesAnnotationForGET.

@Test
public void shouldGenerateMethodAnnotatedWithHandlesAnnotationForGET() throws Exception {
    generator.run(messagingRamlWithDefaults().with(resource().withRelativeUri("/cakeshop.handler.command").with(httpActionWithDefaultMapping(GET).withResponseTypes("application/vnd.cakeshop.actionabc+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withServiceComponentOf("COMMAND_CONTROLLER")));
    final Class<?> generatedClass = compiler.compiledClassOf(BASE_PACKAGE, "RemoteCommandController2EventProcessorMessageContextCakeshopHandlerCommand");
    List<Method> methods = methodsOf(generatedClass);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    final Handles handlesAnnotation = method.getAnnotation(Handles.class);
    assertThat(handlesAnnotation, not(nullValue()));
    assertThat(handlesAnnotation.value(), is("cakeshop.actionabc"));
}
Also used : Handles(uk.gov.justice.services.core.annotation.Handles) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 19 with Handles

use of uk.gov.justice.services.core.annotation.Handles in project microservice_framework by CJSCommonPlatform.

the class MessagingClientGenerator_CodeStructureTest method shouldGenerateMethodAnnotatedWithHandlesAnnotation.

@Test
public void shouldGenerateMethodAnnotatedWithHandlesAnnotation() throws Exception {
    generator.run(messagingRamlWithDefaults().with(resource().withRelativeUri("/cakeshop.controller.command").with(httpActionWithDefaultMapping(POST, "application/vnd.cakeshop.actionabc+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withServiceComponentOf("COMMAND_CONTROLLER")));
    final Class<?> generatedClass = compiler.compiledClassOf(BASE_PACKAGE, "RemoteCommandController2EventProcessorMessageContextCakeshopControllerCommand");
    List<Method> methods = methodsOf(generatedClass);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    final Handles handlesAnnotation = method.getAnnotation(Handles.class);
    assertThat(handlesAnnotation, not(nullValue()));
    assertThat(handlesAnnotation.value(), is("cakeshop.actionabc"));
}
Also used : Handles(uk.gov.justice.services.core.annotation.Handles) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 20 with Handles

use of uk.gov.justice.services.core.annotation.Handles 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)));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) UUID(java.util.UUID) JsonObjects.getUUID(uk.gov.justice.services.messaging.JsonObjects.getUUID) Handles(uk.gov.justice.services.core.annotation.Handles)

Aggregations

Handles (uk.gov.justice.services.core.annotation.Handles)20 Method (java.lang.reflect.Method)9 Test (org.junit.Test)9 UUID (java.util.UUID)6 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)5 Recipe (uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe)5 JsonObjects.getUUID (uk.gov.justice.services.messaging.JsonObjects.getUUID)5 Recipe (uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe)3 RecipeAdded (uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded)2 Ingredient (uk.gov.justice.services.example.cakeshop.persistence.entity.Ingredient)2 JsonObjects.getString (uk.gov.justice.services.messaging.JsonObjects.getString)2 Ingredient (uk.gov.justice.services.example.cakeshop.domain.Ingredient)1 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)1 JsonObjects.getBoolean (uk.gov.justice.services.messaging.JsonObjects.getBoolean)1