Search in sources :

Example 1 with Handles

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

the class DirectClientGeneratorCodeStructureTest method shouldGenerateTwoMethodsAnnotatedWithHandlesAnnotationForGET.

@Test
public void shouldGenerateTwoMethodsAnnotatedWithHandlesAnnotationForGET() throws Exception {
    generator.run(raml().withBaseUri("http://localhost:8080/warname/query/api/service").with(resource().with(httpAction(GET).withResponseTypes("application/vnd.ctx.query2+json", "application/vnd.ctx.query1+json").with(mapping().withName("actionABC").withResponseType("application/vnd.ctx.query1+json")).with(mapping().withName("actionBCD").withResponseType("application/vnd.ctx.query2+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withServiceComponentOf("SOME_COMPONENT")));
    final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "DirectSomeComponent2QueryApiServiceClient");
    final List<Method> methods = methodsOf(clazz);
    assertThat(methods, hasSize(2));
    final Method method1 = methods.get(0);
    final Handles handlesAnnotation1 = method1.getAnnotation(Handles.class);
    assertThat(handlesAnnotation1, not(nullValue()));
    assertThat(handlesAnnotation1.value(), is("actionABC"));
    final Method method2 = methods.get(1);
    final Handles handlesAnnotation2 = method2.getAnnotation(Handles.class);
    assertThat(handlesAnnotation2, not(nullValue()));
    assertThat(handlesAnnotation2.value(), is("actionBCD"));
}
Also used : Handles(uk.gov.justice.services.core.annotation.Handles) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with Handles

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

the class AbstractClientGeneratorTest method shouldGenerateAnnotatedMethod.

@Test
public void shouldGenerateAnnotatedMethod() throws Exception {
    generator.run(messagingRamlWithDefaults().withDefaultMessagingResource().build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withDefaultServiceComponent()));
    final Class<?> generatedClass = compiler.compiledClassOf(BASE_PACKAGE, "RemoteABCController");
    final 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("some.action"));
    assertThat(method.getParameterCount(), is(1));
    assertThat(method.getParameters()[0].getType(), equalTo(JsonEnvelope.class));
}
Also used : Handles(uk.gov.justice.services.core.annotation.Handles) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 3 with Handles

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

the class RestClientGenerator_CodeStructureTest method shouldGenerateMethodAnnotatedWithHandlesAnnotationForPUT.

@Test
public void shouldGenerateMethodAnnotatedWithHandlesAnnotationForPUT() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path/{recipeId}").with(httpAction(PUT, "application/vnd.cakeshop.command.update-recipe+json").withDescription(PUT_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("putSomePathRecipeIdCakeshopCommandUpdateRecipe"));
    final Handles handlesAnnotation = method.getAnnotation(Handles.class);
    assertThat(handlesAnnotation, not(nullValue()));
    assertThat(handlesAnnotation.value(), is("cakeshop.update-recipe"));
}
Also used : Handles(uk.gov.justice.services.core.annotation.Handles) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 4 with Handles

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

the class RestClientGenerator_CodeStructureTest method shouldGenerateMethodAnnotatedWithHandlesAnnotationForDELETE.

@Test
public void shouldGenerateMethodAnnotatedWithHandlesAnnotationForDELETE() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path/{recipeId}").with(httpAction(DELETE, "application/vnd.cakeshop.command.delete-recipe+json").withDescription(DELETE_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("deleteSomePathRecipeIdCakeshopCommandDeleteRecipe"));
    final Handles handlesAnnotation = method.getAnnotation(Handles.class);
    assertThat(handlesAnnotation, not(nullValue()));
    assertThat(handlesAnnotation.value(), is("cakeshop.delete-recipe"));
}
Also used : Handles(uk.gov.justice.services.core.annotation.Handles) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 5 with Handles

use of uk.gov.justice.services.core.annotation.Handles 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);
        }
    }
}
Also used : RecipeAdded(uk.gov.justice.services.example.cakeshop.domain.event.RecipeAdded) Ingredient(uk.gov.justice.services.example.cakeshop.persistence.entity.Ingredient) 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