use of uk.gov.justice.subscription.domain.SubscriptionDescriptorDef in project microservice_framework by CJSCommonPlatform.
the class SubscriptionDescriptorDefBuilderTest method shouldBuildASubscriptionDescriptorDef.
@Test
public void shouldBuildASubscriptionDescriptorDef() throws Exception {
final SubscriptionDescriptor subscriptionDescriptor = mock(SubscriptionDescriptor.class);
final SubscriptionDescriptorDef subscriptionDescriptorDef = subscriptionDescriptorDef().withSubscriptionDescriptor(subscriptionDescriptor).build();
assertThat(subscriptionDescriptorDef.getSubscriptionDescriptor(), is(subscriptionDescriptor));
}
use of uk.gov.justice.subscription.domain.SubscriptionDescriptorDef in project microservice_framework by CJSCommonPlatform.
the class JmsEndpointGeneratorTest method shouldConvertRamlToASubscriptionThenRunTheEndpointGenerators.
@Test
public void shouldConvertRamlToASubscriptionThenRunTheEndpointGenerators() throws Exception {
final String serviceComponent = "EVENT_LISTENER";
final Raml raml = mock(Raml.class);
final GeneratorConfig configuration = mock(GeneratorConfig.class);
final CommonGeneratorProperties commonGeneratorProperties = mock(CommonGeneratorProperties.class);
final SubscriptionDescriptorDef subscriptionDescriptorDef = mock(SubscriptionDescriptorDef.class);
final SubscriptionDescriptor subscriptionDescriptor = mock(SubscriptionDescriptor.class);
when(configuration.getGeneratorProperties()).thenReturn(commonGeneratorProperties);
when(commonGeneratorProperties.getServiceComponent()).thenReturn(serviceComponent);
when(ramlToJmsSubscriptionConverter.convert(raml, serviceComponent)).thenReturn(subscriptionDescriptorDef);
when(subscriptionDescriptorDef.getSubscriptionDescriptor()).thenReturn(subscriptionDescriptor);
jmsEndpointGenerator.run(raml, configuration);
final InOrder inOrder = inOrder(ramlValidator, ramlToJmsSubscriptionConverter, subscriptionJmsEndpointGenerator);
inOrder.verify(ramlValidator).validate(raml);
inOrder.verify(ramlToJmsSubscriptionConverter).convert(raml, serviceComponent);
inOrder.verify(subscriptionJmsEndpointGenerator).run(subscriptionDescriptor, configuration);
}
use of uk.gov.justice.subscription.domain.SubscriptionDescriptorDef in project microservice_framework by CJSCommonPlatform.
the class RamlToJmsSubscriptionConverterTest method shouldCreateASchemaObjectFromARamlObject.
@SuppressWarnings("unchecked")
@Test
public void shouldCreateASchemaObjectFromARamlObject() throws Exception {
final String componentName = "EVENT_LISTENER";
final String contextName = "people";
final String baseUri = "message://command/handler/message/people";
final Raml raml = mock(Raml.class, RETURNS_DEEP_STUBS.get());
final Resource resource_1 = mock(Resource.class);
final Resource resource_2 = mock(Resource.class);
final Resource resource_3 = mock(Resource.class);
final Subscription subscription_1 = mock(Subscription.class);
final Subscription subscription_2 = mock(Subscription.class);
final Subscription subscription_3 = mock(Subscription.class);
final List<Subscription> subscriptions = asList(subscription_1, subscription_2, subscription_3);
when(raml.getBaseUri()).thenReturn(baseUri);
when(subscriptionNamesGenerator.createContextNameFrom(baseUri)).thenReturn(contextName);
when(raml.getResources().values()).thenReturn(asList(resource_1, resource_2, resource_3));
when(resourcesListToSubscriptionListConverter.getSubscriptions(raml.getResources().values())).thenReturn(subscriptions);
final SubscriptionDescriptorDef subscriptionDescriptorDef = ramlToJmsSubscriptionConverter.convert(raml, componentName);
final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptorDef.getSubscriptionDescriptor();
assertThat(subscriptionDescriptor.getSpecVersion(), is("1.0.0"));
assertThat(subscriptionDescriptor.getService(), is(contextName));
assertThat(subscriptionDescriptor.getServiceComponent(), is(componentName));
assertThat(subscriptionDescriptor.getSubscriptions().size(), is(3));
assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_1));
assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_2));
assertThat(subscriptionDescriptor.getSubscriptions(), hasItem(subscription_3));
}
use of uk.gov.justice.subscription.domain.SubscriptionDescriptorDef in project microservice_framework by CJSCommonPlatform.
the class EventFilterCodeGeneratorTest method shouldGenerateCorrectEventFilterJavaCode.
@Test
public void shouldGenerateCorrectEventFilterJavaCode() throws Exception {
final String serviceName = "my-context";
final String componentName = "EVENT_LISTENER";
final String jmsUri = "jms:topic:my-context.handler.command";
final Event event_1 = event().withName("my-context.events.something-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-happened.json").build();
final Event event_2 = event().withName("my-context.events.something-else-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-else-happened.json").build();
final Subscription subscription = subscription().withName("subscription").withEvent(event_1).withEvent(event_2).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(jmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
final SubscriptionDescriptorDef subscriptionDescriptorDef = subscriptionDescriptorDef().withSubscriptionDescriptor(subscriptionDescriptor).build();
final HashMap<ActionType, Action> actions = new HashMap<>();
final Resource resource = new Resource();
resource.setActions(actions);
final Action action = mock(Action.class, RETURNS_DEEP_STUBS.get());
actions.put(POST, action);
final MimeType mimeType_1 = new MimeType("application/vnd.my-context.events.something-happened+json");
final MimeType mimeType_2 = new MimeType("application/vnd.my-context.events.something-else-happened+json");
final String basePackageName = "uk.gov.moj.base.package.name";
when(action.getBody().values()).thenReturn(asList(mimeType_1, mimeType_2));
final ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
final TypeSpec typeSpec = eventFilterCodeGenerator.generate(subscription, classNameFactory);
assertThat(typeSpec.toString(), is("@javax.enterprise.context.ApplicationScoped\n" + "public class MyContextEventListenerMyContextHandlerCommandEventFilter extends uk.gov.justice.services.event.buffer.api.AbstractEventFilter {\n" + " public MyContextEventListenerMyContextHandlerCommandEventFilter() {\n" + " super(\"my-context.events.something-happened\",\"my-context.events.something-else-happened\");}\n" + "}\n"));
}
use of uk.gov.justice.subscription.domain.SubscriptionDescriptorDef in project microservice_framework by CJSCommonPlatform.
the class JmsEndpointGenerator method run.
/**
* Generates JMS endpoint classes from a RAML document.
*
* @param raml the RAML document
* @param configuration contains package of generated sources, as well as source and destination
* folders
*/
@Override
public void run(final Raml raml, final GeneratorConfig configuration) {
ramlValidator.validate(raml);
final CommonGeneratorProperties commonGeneratorProperties = (CommonGeneratorProperties) configuration.getGeneratorProperties();
final SubscriptionDescriptorDef subscriptionDescriptorDef = ramlToJmsSubscriptionConverter.convert(raml, commonGeneratorProperties.getServiceComponent());
subscriptionJmsEndpointGenerator.run(subscriptionDescriptorDef.getSubscriptionDescriptor(), configuration);
}
Aggregations