Search in sources :

Example 1 with GeneratorPropertiesFactory

use of uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory in project microservice_framework by CJSCommonPlatform.

the class MessageListenerCodeGeneratorTest method shouldGenerateMDBForTopic.

@Test
public void shouldGenerateMDBForTopic() throws Exception {
    final String basePackageName = "uk.gov.moj.base.package.name";
    final String serviceName = "my-context";
    final String componentName = "EVENT_LISTENER";
    final String jmsUri = "jms:topic:my-context.handler.command";
    final Event event_1 = event().withName("my-context.events.something-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-happened.json").build();
    final Event event_2 = event().withName("my-context.events.something-else-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-else-happened.json").build();
    final Subscription subscription = subscription().withName("subscription").withEvent(event_1).withEvent(event_2).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(jmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
    final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
    final ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
    GeneratorProperties generatorProperties = new GeneratorPropertiesFactory().withCustomMDBPool();
    final TypeSpec typeSpec = messageListenerCodeGenerator.generate(subscriptionDescriptor, subscription, (CommonGeneratorProperties) generatorProperties, classNameFactory);
    assertThat(typeSpec.toString(), is("@uk.gov.justice.services.core.annotation.Adapter(\"EVENT_LISTENER\")\n" + "@javax.ejb.MessageDriven(\n" + "    activationConfig = {\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Topic\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"my-context.handler.command\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"shareSubscriptions\", propertyValue = \"true\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"subscriptionDurability\", propertyValue = \"Durable\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"clientId\", propertyValue = \"my-context.event.listener\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"subscriptionName\", propertyValue = \"my-context.event.listener.my-context.handler.command\")\n" + "    }\n" + ")\n" + "@javax.interceptor.Interceptors({\n" + "    uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor.class,\n" + "    uk.gov.moj.base.package.name.MyContextEventListenerMyContextHandlerCommandEventValidationInterceptor.class\n" + "})\n" + "@org.jboss.ejb3.annotation.Pool(\"my-context-handler-command-event-listener-pool\")\n" + "public class MyContextEventListenerMyContextHandlerCommandJmsListener implements javax.jms.MessageListener {\n" + "  private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(uk.gov.moj.base.package.name.MyContextEventListenerMyContextHandlerCommandJmsListener.class);\n" + "\n" + "  @javax.inject.Inject\n" + "  uk.gov.justice.services.core.interceptor.InterceptorChainProcessor interceptorChainProcessor;\n" + "\n" + "  @javax.inject.Inject\n" + "  uk.gov.justice.services.adapter.messaging.JmsProcessor jmsProcessor;\n" + "\n" + "  @java.lang.Override\n" + "  public void onMessage(javax.jms.Message message) {\n" + "    uk.gov.justice.services.messaging.logging.LoggerUtils.trace(LOGGER, () -> \"Received JMS message\");\n" + "    jmsProcessor.process(interceptorChainProcessor::process, message);\n" + "  }\n" + "}\n"));
}
Also used : GeneratorProperties(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Event(uk.gov.justice.subscription.domain.Event) GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) TypeSpec(com.squareup.javapoet.TypeSpec) Test(org.junit.Test)

Example 2 with GeneratorPropertiesFactory

use of uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory in project microservice_framework by CJSCommonPlatform.

the class MessageListenerCodeGeneratorTest method shouldGenerateMDBForCommandHandlerQueue.

@Test
public void shouldGenerateMDBForCommandHandlerQueue() throws Exception {
    final String basePackageName = "uk.gov.moj.base.package.name";
    final String serviceName = "my-context";
    final String componentName = "COMMAND_HANDLER";
    final String jmsUri = "jms:topic:my-context.handler.command";
    final Event event_1 = event().withName("my-context.events.something-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-happened.json").build();
    final Event event_2 = event().withName("my-context.events.something-else-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-else-happened.json").build();
    final Subscription subscription = subscription().withName("subscription").withEvent(event_1).withEvent(event_2).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(jmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
    final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
    final ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
    GeneratorProperties generatorProperties = new GeneratorPropertiesFactory().withServiceComponentOf(componentName);
    final TypeSpec typeSpec = messageListenerCodeGenerator.generate(subscriptionDescriptor, subscription, (CommonGeneratorProperties) generatorProperties, classNameFactory);
    assertThat(typeSpec.toString(), is("@uk.gov.justice.services.core.annotation.Adapter(\"COMMAND_HANDLER\")\n" + "@javax.ejb.MessageDriven(\n" + "    activationConfig = {\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Queue\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"my-context.handler.command\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"shareSubscriptions\", propertyValue = \"true\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"messageSelector\", propertyValue = \"CPPNAME in('my-context.events.something-happened','my-context.events.something-else-happened')\")\n" + "    }\n" + ")\n" + "@javax.interceptor.Interceptors({\n" + "    uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor.class,\n" + "    uk.gov.justice.services.adapter.messaging.JsonSchemaValidationInterceptor.class\n" + "})\n" + "public class MyContextCommandHandlerMyContextHandlerCommandJmsListener implements javax.jms.MessageListener {\n" + "  private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(uk.gov.moj.base.package.name.MyContextCommandHandlerMyContextHandlerCommandJmsListener.class);\n" + "\n" + "  @javax.inject.Inject\n" + "  uk.gov.justice.services.core.interceptor.InterceptorChainProcessor interceptorChainProcessor;\n" + "\n" + "  @javax.inject.Inject\n" + "  uk.gov.justice.services.adapter.messaging.JmsProcessor jmsProcessor;\n" + "\n" + "  @java.lang.Override\n" + "  public void onMessage(javax.jms.Message message) {\n" + "    uk.gov.justice.services.messaging.logging.LoggerUtils.trace(LOGGER, () -> \"Received JMS message\");\n" + "    jmsProcessor.process(interceptorChainProcessor::process, message);\n" + "  }\n" + "}\n"));
}
Also used : GeneratorProperties(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Event(uk.gov.justice.subscription.domain.Event) GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) TypeSpec(com.squareup.javapoet.TypeSpec) Test(org.junit.Test)

Example 3 with GeneratorPropertiesFactory

use of uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory in project microservice_framework by CJSCommonPlatform.

the class MessageListenerCodeGeneratorTest method shouldGenerateMDBForQueue.

@Test
public void shouldGenerateMDBForQueue() throws Exception {
    final String basePackageName = "uk.gov.moj.base.package.name";
    final String serviceName = "my-context";
    final String componentName = "COMMAND_API";
    final String jmsUri = "jms:queue:my-context.handler.command";
    final Event event_1 = event().withName("my-context.events.something-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-happened.json").build();
    final Event event_2 = event().withName("my-context.events.something-else-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-else-happened.json").build();
    final Subscription subscription = subscription().withName("subscription").withEvent(event_1).withEvent(event_2).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(jmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
    final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
    final ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
    GeneratorProperties generatorProperties = new GeneratorPropertiesFactory().withServiceComponentOf("COMMAND_API");
    final TypeSpec typeSpec = messageListenerCodeGenerator.generate(subscriptionDescriptor, subscription, (CommonGeneratorProperties) generatorProperties, classNameFactory);
    assertThat(typeSpec.toString(), is("@uk.gov.justice.services.core.annotation.Adapter(\"COMMAND_API\")\n" + "@javax.ejb.MessageDriven(\n" + "    activationConfig = {\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Queue\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"my-context.handler.command\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"shareSubscriptions\", propertyValue = \"true\"),\n" + "        @javax.ejb.ActivationConfigProperty(propertyName = \"messageSelector\", propertyValue = \"CPPNAME in('my-context.events.something-happened','my-context.events.something-else-happened')\")\n" + "    }\n" + ")\n" + "@javax.interceptor.Interceptors({\n" + "    uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor.class,\n" + "    uk.gov.justice.services.adapter.messaging.JsonSchemaValidationInterceptor.class\n" + "})\n" + "public class MyContextCommandApiMyContextHandlerCommandJmsListener implements javax.jms.MessageListener {\n" + "  private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(uk.gov.moj.base.package.name.MyContextCommandApiMyContextHandlerCommandJmsListener.class);\n" + "\n" + "  @javax.inject.Inject\n" + "  uk.gov.justice.services.core.interceptor.InterceptorChainProcessor interceptorChainProcessor;\n" + "\n" + "  @javax.inject.Inject\n" + "  uk.gov.justice.services.adapter.messaging.JmsProcessor jmsProcessor;\n" + "\n" + "  @java.lang.Override\n" + "  public void onMessage(javax.jms.Message message) {\n" + "    uk.gov.justice.services.messaging.logging.LoggerUtils.trace(LOGGER, () -> \"Received JMS message\");\n" + "    jmsProcessor.process(interceptorChainProcessor::process, message);\n" + "  }\n" + "}\n"));
}
Also used : GeneratorProperties(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Event(uk.gov.justice.subscription.domain.Event) GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) TypeSpec(com.squareup.javapoet.TypeSpec) Test(org.junit.Test)

Example 4 with GeneratorPropertiesFactory

use of uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory in project microservice_framework by CJSCommonPlatform.

the class SubscriptionJmsEndpointGeneratorTest method setup.

@Before
public void setup() throws Exception {
    generator = new JmsEndpointGenerationObjects().subscriptionJmsEndpointGenerator();
    compiler = new JavaCompilerUtil(outputFolder.getRoot(), outputFolder.getRoot());
    generatorProperties = new GeneratorPropertiesFactory().withDefaultServiceComponent();
}
Also used : JavaCompilerUtil(uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil) GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) Before(org.junit.Before)

Example 5 with GeneratorPropertiesFactory

use of uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory in project microservice_framework by CJSCommonPlatform.

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateAnnotatedEventListenerEndpointWithQueueAsDestinationType.

@Test
public void shouldCreateAnnotatedEventListenerEndpointWithQueueAsDestinationType() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:people.event", "people.abc", serviceName, "EVENT_PROCESSOR");
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, new GeneratorPropertiesFactory().withServiceComponentOf(EVENT_LISTENER)));
    Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "ContextEventProcessorPeopleEventJmsListener");
    assertThat(clazz.getAnnotation(MessageDriven.class), is(notNullValue()));
    assertThat(clazz.getAnnotation(MessageDriven.class).activationConfig(), hasItemInArray(allOf(propertyName(equalTo("destinationType")), propertyValue(equalTo("javax.jms.Topic")))));
}
Also used : GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) MessageDriven(javax.ejb.MessageDriven) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Aggregations

GeneratorPropertiesFactory (uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory)12 Test (org.junit.Test)11 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)11 Adapter (uk.gov.justice.services.core.annotation.Adapter)5 TypeSpec (com.squareup.javapoet.TypeSpec)3 GeneratorProperties (uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties)3 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)3 Event (uk.gov.justice.subscription.domain.Event)3 Subscription (uk.gov.justice.subscription.domain.Subscription)3 MessageDriven (javax.ejb.MessageDriven)2 Field (java.lang.reflect.Field)1 ActivationConfigProperty (javax.ejb.ActivationConfigProperty)1 Pool (org.jboss.ejb3.annotation.Pool)1 Before (org.junit.Before)1 JavaCompilerUtil (uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil)1 ReflectionUtil.setField (uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField)1