Search in sources :

Example 21 with Subscription

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

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateAnnotatedJmsEndpointWithMessageSelectorContainingTwoCommand.

@Test
public void shouldCreateAnnotatedJmsEndpointWithMessageSelectorContainingTwoCommand() throws Exception {
    String jmsUri = "jms:topic:people.controller.command";
    Event event1 = event().withName("people.command1").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/people.command1.json").build();
    Event event2 = event().withName("people.command2").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/people.command2.json").build();
    Subscription subscription = subscription().withName("subscription").withEvent(event1).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(jmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
    subscription.getEvents().add(event2);
    SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
    Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "ContextEventProcessorPeopleControllerCommandJmsListener");
    assertThat(clazz.getAnnotation(MessageDriven.class), is(notNullValue()));
    assertThat(clazz.getAnnotation(MessageDriven.class).activationConfig(), hasItemInArray(allOf(propertyName(equalTo("messageSelector")), propertyValue(startsWith("CPPNAME in")), propertyValue(allOf(containsString("'people.command1'"), containsString("'people.command2'"))))));
}
Also used : Event(uk.gov.justice.subscription.domain.Event) Matchers.containsString(org.hamcrest.Matchers.containsString) Subscription(uk.gov.justice.subscription.domain.Subscription) MessageDriven(javax.ejb.MessageDriven) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 22 with Subscription

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

the class SubscriptionJmsEndpointGeneratorTest method shouldCreateMultipleJmsClasses.

@SuppressWarnings("unchecked")
@Test
public void shouldCreateMultipleJmsClasses() throws Exception {
    String structureJmsUri = "jms:topic:structure.controller.command";
    String peopleJmsUri = "jms:topic:people.controller.command";
    Event event = event().withName("my-context.events.something-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-happened.json").build();
    Subscription subscription = subscription().withName("subscription").withEvent(event).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(structureJmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
    Subscription subscription2 = subscription().withName("subscription2").withEvent(event).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(peopleJmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
    SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
    subscriptionDescriptor.getSubscriptions().add(subscription2);
    generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
    File packageDir = new File(outputFolder.getRoot().getAbsolutePath() + BASE_PACKAGE_FOLDER);
    final File[] a = packageDir.listFiles();
    assertThat(asList(a), hasItems(hasProperty("name", equalTo("ContextEventProcessorPeopleControllerCommandJmsListener.java")), hasProperty("name", equalTo("ContextEventProcessorStructureControllerCommandJmsListener.java"))));
}
Also used : Event(uk.gov.justice.subscription.domain.Event) Matchers.containsString(org.hamcrest.Matchers.containsString) Subscription(uk.gov.justice.subscription.domain.Subscription) File(java.io.File) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 23 with Subscription

use of uk.gov.justice.subscription.domain.Subscription 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 24 with Subscription

use of uk.gov.justice.subscription.domain.Subscription 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

Subscription (uk.gov.justice.subscription.domain.Subscription)24 Test (org.junit.Test)19 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)14 Event (uk.gov.justice.subscription.domain.Event)12 Resource (org.raml.model.Resource)6 TypeSpec (com.squareup.javapoet.TypeSpec)5 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)4 Eventsource (uk.gov.justice.subscription.domain.Eventsource)4 Action (org.raml.model.Action)3 MimeType (org.raml.model.MimeType)3 GeneratorProperties (uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties)3 GeneratorPropertiesFactory (uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory)3 SubscriptionDescriptorDef (uk.gov.justice.subscription.domain.SubscriptionDescriptorDef)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 SubscriptionName (uk.gov.justice.services.core.cdi.SubscriptionName)2 EventSource (uk.gov.justice.services.eventsourcing.source.core.EventSource)2 Location (uk.gov.justice.subscription.domain.Location)2 File (java.io.File)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1