use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class MessageListenerCodeGeneratorTest method shouldGenerateMDBForCommandHandlerQueue.
@Test
public void shouldGenerateMDBForCommandHandlerQueue() throws Exception {
final String basePackageName = "uk.gov.moj.base.package.name";
final String serviceName = "my-context";
final String componentName = "COMMAND_HANDLER";
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 ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
GeneratorProperties generatorProperties = new GeneratorPropertiesFactory().withServiceComponentOf(componentName);
final TypeSpec typeSpec = messageListenerCodeGenerator.generate(subscriptionDescriptor, subscription, (CommonGeneratorProperties) generatorProperties, classNameFactory);
assertThat(typeSpec.toString(), is("@uk.gov.justice.services.core.annotation.Adapter(\"COMMAND_HANDLER\")\n" + "@javax.ejb.MessageDriven(\n" + " activationConfig = {\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Queue\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"my-context.handler.command\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"shareSubscriptions\", propertyValue = \"true\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"messageSelector\", propertyValue = \"CPPNAME in('my-context.events.something-happened','my-context.events.something-else-happened')\")\n" + " }\n" + ")\n" + "@javax.interceptor.Interceptors({\n" + " uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor.class,\n" + " uk.gov.justice.services.adapter.messaging.JsonSchemaValidationInterceptor.class\n" + "})\n" + "public class MyContextCommandHandlerMyContextHandlerCommandJmsListener implements javax.jms.MessageListener {\n" + " private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(uk.gov.moj.base.package.name.MyContextCommandHandlerMyContextHandlerCommandJmsListener.class);\n" + "\n" + " @javax.inject.Inject\n" + " uk.gov.justice.services.core.interceptor.InterceptorChainProcessor interceptorChainProcessor;\n" + "\n" + " @javax.inject.Inject\n" + " uk.gov.justice.services.adapter.messaging.JmsProcessor jmsProcessor;\n" + "\n" + " @java.lang.Override\n" + " public void onMessage(javax.jms.Message message) {\n" + " uk.gov.justice.services.messaging.logging.LoggerUtils.trace(LOGGER, () -> \"Received JMS message\");\n" + " jmsProcessor.process(interceptorChainProcessor::process, message);\n" + " }\n" + "}\n"));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class MessageListenerCodeGeneratorTest method shouldGenerateMDBForQueue.
@Test
public void shouldGenerateMDBForQueue() throws Exception {
final String basePackageName = "uk.gov.moj.base.package.name";
final String serviceName = "my-context";
final String componentName = "COMMAND_API";
final String jmsUri = "jms:queue: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 ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
GeneratorProperties generatorProperties = new GeneratorPropertiesFactory().withServiceComponentOf("COMMAND_API");
final TypeSpec typeSpec = messageListenerCodeGenerator.generate(subscriptionDescriptor, subscription, (CommonGeneratorProperties) generatorProperties, classNameFactory);
assertThat(typeSpec.toString(), is("@uk.gov.justice.services.core.annotation.Adapter(\"COMMAND_API\")\n" + "@javax.ejb.MessageDriven(\n" + " activationConfig = {\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"destinationType\", propertyValue = \"javax.jms.Queue\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"destinationLookup\", propertyValue = \"my-context.handler.command\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"shareSubscriptions\", propertyValue = \"true\"),\n" + " @javax.ejb.ActivationConfigProperty(propertyName = \"messageSelector\", propertyValue = \"CPPNAME in('my-context.events.something-happened','my-context.events.something-else-happened')\")\n" + " }\n" + ")\n" + "@javax.interceptor.Interceptors({\n" + " uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor.class,\n" + " uk.gov.justice.services.adapter.messaging.JsonSchemaValidationInterceptor.class\n" + "})\n" + "public class MyContextCommandApiMyContextHandlerCommandJmsListener implements javax.jms.MessageListener {\n" + " private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(uk.gov.moj.base.package.name.MyContextCommandApiMyContextHandlerCommandJmsListener.class);\n" + "\n" + " @javax.inject.Inject\n" + " uk.gov.justice.services.core.interceptor.InterceptorChainProcessor interceptorChainProcessor;\n" + "\n" + " @javax.inject.Inject\n" + " uk.gov.justice.services.adapter.messaging.JmsProcessor jmsProcessor;\n" + "\n" + " @java.lang.Override\n" + " public void onMessage(javax.jms.Message message) {\n" + " uk.gov.justice.services.messaging.logging.LoggerUtils.trace(LOGGER, () -> \"Received JMS message\");\n" + " jmsProcessor.process(interceptorChainProcessor::process, message);\n" + " }\n" + "}\n"));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class GeneratorPropertiesFactory method withCustomMDBPool.
public GeneratorProperties withCustomMDBPool() {
final CommonGeneratorProperties properties = new CommonGeneratorProperties();
try {
setField(properties, CUSTOM_MDB_POOL, "TRUE");
setField(properties, SERVICE_COMPONENT_KEY, "EVENT_LISTENER");
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
return properties;
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RamlMediaTypeToSchemaIdGeneratorTest method shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet.
@Test
public void shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet() throws Exception {
final String schemaId = "http://justice.gov.uk/test/schema.json";
final MimeType mimeType_1 = createMimeTypeWith(MEDIA_TYPE_1.toString(), schemaId);
new RamlMediaTypeToSchemaIdGenerator().generateMediaTypeToSchemaIdMapper(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(GET).withResponseTypes(mimeType_1))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> schemaIdMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "WarnameMediaTypeToSchemaIdMapper");
final MediaTypeToSchemaIdMapper instance = (MediaTypeToSchemaIdMapper) schemaIdMapperClass.newInstance();
final Map<MediaType, String> mediaTypeToSchemaIdMap = instance.getMediaTypeToSchemaIdMap();
assertThat(mediaTypeToSchemaIdMap.size(), is(1));
assertThat(mediaTypeToSchemaIdMap.get(MEDIA_TYPE_1), is(schemaId));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class SubscriptionMediaTypeToSchemaIdGeneratorTest method shouldCreateMediaTypeToSchemaIdMapper.
@Test
public void shouldCreateMediaTypeToSchemaIdMapper() throws Exception {
final String eventName_1 = "ctx.command.command1";
final String mediaType_1 = "application/vnd." + eventName_1 + "+json";
final String schemaId_1 = "http://justice.gov.uk/test/schema1.json";
final String eventName_2 = "ctx.command.command2";
final String mediaType_2 = "application/vnd." + eventName_2 + "+json";
final String schemaId_2 = "http://justice.gov.uk/test/schema2.json";
final String contextName = "my-context";
final String componentName = "EVENT_LISTENER";
final String generatedClassName = "MyContextEventListenerMediaTypeToSchemaIdMapper";
final List<Event> events = asList(new Event(eventName_1, schemaId_1), new Event(eventName_2, schemaId_2));
new SubscriptionMediaTypeToSchemaIdGenerator().generateMediaTypeToSchemaIdMapper(contextName, componentName, events, configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> schemaIdMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", generatedClassName);
final MediaTypeToSchemaIdMapper instance = (MediaTypeToSchemaIdMapper) schemaIdMapperClass.newInstance();
final Map<MediaType, String> mediaTypeToSchemaIdMap = instance.getMediaTypeToSchemaIdMap();
assertThat(mediaTypeToSchemaIdMap.size(), is(2));
assertThat(mediaTypeToSchemaIdMap.get(new MediaType(mediaType_1)), is(schemaId_1));
assertThat(mediaTypeToSchemaIdMap.get(new MediaType(mediaType_2)), is(schemaId_2));
}
Aggregations