Search in sources :

Example 51 with SubscriptionDescriptor

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

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateJmsEndpointInADifferentPackage.

@Test
public void shouldCreateJmsEndpointInADifferentPackage() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:structure.controller.command", "my-context.events.something-happened", serviceName, componentName);
    generator.run(subscriptionDescriptor, configurationWithBasePackage("uk.package2", outputFolder, generatorProperties));
    Class<?> clazz = compiler.compiledClassOf("uk.package2", "ContextEventProcessorStructureControllerCommandJmsListener");
    assertThat(clazz.getName(), is("uk.package2.ContextEventProcessorStructureControllerCommandJmsListener"));
}
Also used : SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 52 with SubscriptionDescriptor

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

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateAnnotatedJmsEndpointWithMessageSelectorContainingOneEvent_PluralPillarName.

@Test
public void shouldCreateAnnotatedJmsEndpointWithMessageSelectorContainingOneEvent_PluralPillarName() throws Exception {
    SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:structure.event", "structure.events.test-event", serviceName, componentName);
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
    Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "ContextEventProcessorStructureEventJmsListener");
    assertThat(clazz.getAnnotation(MessageDriven.class), is(notNullValue()));
    assertThat(clazz.getAnnotation(MessageDriven.class).activationConfig(), hasItemInArray(allOf(propertyName(equalTo("messageSelector")), propertyValue(equalTo("CPPNAME in('structure.events.test-event')")))));
}
Also used : MessageDriven(javax.ejb.MessageDriven) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 53 with SubscriptionDescriptor

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

the class SubscriptionJmsEndpointGenerator method run.

/**
 * Generates JMS endpoint classes from a SubscriptionDescriptorDef document.
 *
 * @param subscriptionDescriptor          the subscriptionDescriptor document
 * @param configuration contains package of generated sources, as well as source and destination
 *                      folders
 */
@Override
public void run(final SubscriptionDescriptor subscriptionDescriptor, final GeneratorConfig configuration) {
    final CommonGeneratorProperties commonGeneratorProperties = (CommonGeneratorProperties) configuration.getGeneratorProperties();
    final String basePackageName = configuration.getBasePackageName();
    final List<Subscription> subscriptions = subscriptionDescriptor.getSubscriptions();
    subscriptions.stream().flatMap(subscription -> generatedClassesFrom(subscriptionDescriptor, subscription, commonGeneratorProperties, basePackageName)).forEach(generatedClass -> writeClass(configuration, basePackageName, generatedClass, LOGGER));
    final List<Event> allEvents = subscriptions.stream().map(Subscription::getEvents).flatMap(Collection::stream).collect(toList());
    final String contextName = subscriptionDescriptor.getService();
    final String componentName = subscriptionDescriptor.getServiceComponent();
    subscriptionMediaTypeToSchemaIdGenerator.generateMediaTypeToSchemaIdMapper(contextName, componentName, allEvents, configuration);
}
Also used : GeneratorConfig(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig) Subscription(uk.gov.justice.subscription.domain.Subscription) JmsEndPointGeneratorUtil.shouldGenerateEventFilter(uk.gov.justice.subscription.jms.core.JmsEndPointGeneratorUtil.shouldGenerateEventFilter) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) SubscriptionMediaTypeToSchemaIdGenerator(uk.gov.justice.services.generators.commons.mapping.SubscriptionMediaTypeToSchemaIdGenerator) TypeSpec(com.squareup.javapoet.TypeSpec) EventValidationInterceptorCodeGenerator(uk.gov.justice.subscription.jms.interceptor.EventValidationInterceptorCodeGenerator) EventFilterInterceptorCodeGenerator(uk.gov.justice.subscription.jms.interceptor.EventFilterInterceptorCodeGenerator) Generator(uk.gov.justice.maven.generator.io.files.parser.core.Generator) EventListenerInterceptorChainProviderCodeGenerator(uk.gov.justice.subscription.jms.interceptor.EventListenerInterceptorChainProviderCodeGenerator) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Event(uk.gov.justice.subscription.domain.Event) Stream(java.util.stream.Stream) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) GeneratedClassWriter.writeClass(uk.gov.justice.services.generators.commons.helper.GeneratedClassWriter.writeClass) Event(uk.gov.justice.subscription.domain.Event) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Subscription(uk.gov.justice.subscription.domain.Subscription)

Example 54 with SubscriptionDescriptor

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

the class RamlToJmsSubscriptionConverter method convert.

public SubscriptionDescriptorDef convert(final Raml raml, final String componentName) {
    final String baseUri = raml.getBaseUri();
    final String service = subscriptionNamesGenerator.createContextNameFrom(baseUri);
    final List<Subscription> subscriptions = resourcesListToSubscriptionListConverter.getSubscriptions(raml.getResources().values());
    final SubscriptionDescriptor subscriptionDescriptor = new SubscriptionDescriptor(SUBSCRIPTION_SPEC_VERSION, service, componentName, subscriptions);
    return new SubscriptionDescriptorDef(subscriptionDescriptor);
}
Also used : SubscriptionDescriptorDef(uk.gov.justice.subscription.domain.SubscriptionDescriptorDef) Subscription(uk.gov.justice.subscription.domain.Subscription) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor)

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