Search in sources :

Example 11 with SubscriptionDescriptor

use of uk.gov.justice.subscription.domain.SubscriptionDescriptor in project microservice_framework by CJSCommonPlatform.

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateJmsEndpointWithAnnotatedJmsProcessorProperty.

@Test
public void shouldCreateJmsEndpointWithAnnotatedJmsProcessorProperty() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:somecontext.controller.command", "somecontext.command1", serviceName, componentName);
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
    Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "ContextEventProcessorSomecontextControllerCommandJmsListener");
    Field jmsProcessorField = clazz.getDeclaredField("jmsProcessor");
    assertThat(jmsProcessorField, not(nullValue()));
    assertThat(jmsProcessorField.getType(), CoreMatchers.equalTo((JmsProcessor.class)));
    assertThat(jmsProcessorField.getAnnotations(), arrayWithSize(1));
    assertThat(jmsProcessorField.getAnnotation(Inject.class), not(nullValue()));
}
Also used : Inject(javax.inject.Inject) Field(java.lang.reflect.Field) ReflectionUtil.setField(uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 12 with SubscriptionDescriptor

use of uk.gov.justice.subscription.domain.SubscriptionDescriptor in project microservice_framework by CJSCommonPlatform.

the class SubscriptionJmsEndpointGeneratorTest method shouldCallJmsProcessorWhenOnMessageIsInvoked.

@Test
@SuppressWarnings("unchecked")
public void shouldCallJmsProcessorWhenOnMessageIsInvoked() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:somecontext.controller.command", "somecontext.command1", serviceName, componentName);
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
    Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "ContextEventProcessorSomecontextControllerCommandJmsListener");
    Object object = instantiate(clazz);
    assertThat(object, is(instanceOf(MessageListener.class)));
    MessageListener jmsListener = (MessageListener) object;
    Message message = mock(Message.class);
    jmsListener.onMessage(message);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    verify(jmsProcessor).process(consumerCaptor.capture(), eq(message));
    JsonEnvelope envelope = mock(JsonEnvelope.class);
    final InterceptorContext interceptorContext = interceptorContextWithInput(envelope);
    consumerCaptor.getValue().accept(interceptorContext);
    verify(interceptorChainProcessor).process(interceptorContext);
}
Also used : Message(javax.jms.Message) Consumer(java.util.function.Consumer) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) MessageListener(javax.jms.MessageListener) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 13 with SubscriptionDescriptor

use of uk.gov.justice.subscription.domain.SubscriptionDescriptor in project microservice_framework by CJSCommonPlatform.

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateLoggerConstant.

@Test
public void shouldCreateLoggerConstant() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:structure.controller.command", "my-context.events.something-happened", serviceName, componentName);
    generator.run(subscriptionDescriptor, configurationWithBasePackage("uk.somepackage", outputFolder, generatorProperties));
    Class<?> resourceClass = compiler.compiledClassOf("uk.somepackage", "ContextEventProcessorStructureControllerCommandJmsListener");
    Field logger = resourceClass.getDeclaredField("LOGGER");
    assertThat(logger, CoreMatchers.not(nullValue()));
    assertThat(logger.getType(), CoreMatchers.equalTo(Logger.class));
    assertThat(Modifier.isPrivate(logger.getModifiers()), Matchers.is(true));
    assertThat(Modifier.isStatic(logger.getModifiers()), Matchers.is(true));
    assertThat(Modifier.isFinal(logger.getModifiers()), Matchers.is(true));
}
Also used : Field(java.lang.reflect.Field) ReflectionUtil.setField(uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField) Logger(org.slf4j.Logger) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 14 with SubscriptionDescriptor

use of uk.gov.justice.subscription.domain.SubscriptionDescriptor in project microservice_framework by CJSCommonPlatform.

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateJmsEndpointAnnotatedWithCustomEventListenerAdapter.

@Test
public void shouldCreateJmsEndpointAnnotatedWithCustomEventListenerAdapter() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:people.event", "people.abc", "custom", "CUSTOM_EVENT_LISTENER");
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, new GeneratorPropertiesFactory().withServiceComponentOf("CUSTOM_EVENT_LISTENER")));
    Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "CustomCustomEventListenerPeopleEventJmsListener");
    Adapter adapterAnnotation = clazz.getAnnotation(Adapter.class);
    assertThat(adapterAnnotation, not(nullValue()));
    assertThat(adapterAnnotation.value(), is("CUSTOM_EVENT_LISTENER"));
    final Class<?> customEventFilterInterceptor = compiler.compiledClassOf(BASE_PACKAGE, "CustomCustomEventListenerPeopleEventEventFilterInterceptor");
    final Field eventFilter = customEventFilterInterceptor.getDeclaredField("eventFilter");
    final Class<?> customEventFilterClass = eventFilter.getType();
    assertThat(customEventFilterClass.getName(), is("uk.test.CustomCustomEventListenerPeopleEventEventFilter"));
}
Also used : Field(java.lang.reflect.Field) ReflectionUtil.setField(uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField) GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) Adapter(uk.gov.justice.services.core.annotation.Adapter) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 15 with SubscriptionDescriptor

use of uk.gov.justice.subscription.domain.SubscriptionDescriptor in project microservice_framework by CJSCommonPlatform.

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateAnnotatedCommandHandlerEndpointWithQueueAsDestinationType.

@Test
public void shouldCreateAnnotatedCommandHandlerEndpointWithQueueAsDestinationType() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:lifecycle.blah", "lifecycle.abc", "aaa", "COMMAND_HANDLER");
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
    Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "AaaCommandHandlerLifecycleBlahJmsListener");
    assertThat(clazz.getAnnotation(MessageDriven.class), is(notNullValue()));
    assertThat(clazz.getAnnotation(MessageDriven.class).activationConfig(), hasItemInArray(allOf(propertyName(equalTo("destinationType")), propertyValue(equalTo("javax.jms.Queue")))));
}
Also used : MessageDriven(javax.ejb.MessageDriven) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Aggregations

SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)54 Test (org.junit.Test)52 MessageDriven (javax.ejb.MessageDriven)16 Subscription (uk.gov.justice.subscription.domain.Subscription)14 GeneratorPropertiesFactory (uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory)11 Event (uk.gov.justice.subscription.domain.Event)7 TypeSpec (com.squareup.javapoet.TypeSpec)5 Adapter (uk.gov.justice.services.core.annotation.Adapter)5 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)5 SubscriptionDescriptorDef (uk.gov.justice.subscription.domain.SubscriptionDescriptorDef)5 Field (java.lang.reflect.Field)4 ReflectionUtil.setField (uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField)4 File (java.io.File)3 Path (java.nio.file.Path)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 GeneratorProperties (uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties)3 ActivationConfigProperty (javax.ejb.ActivationConfigProperty)2 Inject (javax.inject.Inject)2 Message (javax.jms.Message)2 MessageListener (javax.jms.MessageListener)2