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