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()));
}
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);
}
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));
}
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"));
}
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")))));
}
Aggregations