Search in sources :

Example 1 with GeneratorConfig

use of uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig 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);
}
Also used : InOrder(org.mockito.InOrder) Raml(org.raml.model.Raml) SubscriptionDescriptorDef(uk.gov.justice.subscription.domain.SubscriptionDescriptorDef) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) GeneratorConfig(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 2 with GeneratorConfig

use of uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_CodeStructureTest method shouldGenerateInterfaceInSpecifiedPackage.

@Test
public void shouldGenerateInterfaceInSpecifiedPackage() throws Exception {
    final String basePackageName = "uk.gov.test1";
    java.nio.file.Path outputPath = get(outputFolder.getRoot().getAbsolutePath());
    final GeneratorConfig config = new GeneratorConfig(outputPath, outputPath, basePackageName, new CommonGeneratorProperties(), singletonList(outputPath.getParent()));
    generator.run(restRamlWithDefaults().with(defaultPostResource()).build(), config);
    final Class<?> interfaceClass = compiler.compiledInterfaceOf(basePackageName + ".resource");
    assertThat(interfaceClass.getPackage().getName(), is(basePackageName + ".resource"));
}
Also used : CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) GeneratorConfig(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig) Test(org.junit.Test)

Example 3 with GeneratorConfig

use of uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_CodeStructureTest method shouldGenerateClassInSpecifiedPackage.

@Test
public void shouldGenerateClassInSpecifiedPackage() throws Exception {
    final String basePackageName = "uk.gov.test2";
    java.nio.file.Path outputPath = get(outputFolder.getRoot().getAbsolutePath());
    generator.run(restRamlWithCommandApiDefaults().with(defaultPostResource().withRelativeUri("/some/path")).build(), new GeneratorConfig(outputPath, outputPath, basePackageName, new CommonGeneratorProperties(), singletonList(outputPath.getParent())));
    final Class<?> resourceImplementation = compiler.compiledClassOf(basePackageName, "resource", "DefaultCommandApiSomePathResource");
    assertThat(resourceImplementation.getPackage().getName(), is(basePackageName + ".resource"));
}
Also used : CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) GeneratorConfig(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig) Test(org.junit.Test)

Example 4 with GeneratorConfig

use of uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig 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)

Aggregations

GeneratorConfig (uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig)4 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)4 Test (org.junit.Test)3 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)2 TypeSpec (com.squareup.javapoet.TypeSpec)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 InOrder (org.mockito.InOrder)1 Raml (org.raml.model.Raml)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Generator (uk.gov.justice.maven.generator.io.files.parser.core.Generator)1 GeneratedClassWriter.writeClass (uk.gov.justice.services.generators.commons.helper.GeneratedClassWriter.writeClass)1 SubscriptionMediaTypeToSchemaIdGenerator (uk.gov.justice.services.generators.commons.mapping.SubscriptionMediaTypeToSchemaIdGenerator)1 Event (uk.gov.justice.subscription.domain.Event)1 Subscription (uk.gov.justice.subscription.domain.Subscription)1 SubscriptionDescriptorDef (uk.gov.justice.subscription.domain.SubscriptionDescriptorDef)1 JmsEndPointGeneratorUtil.shouldGenerateEventFilter (uk.gov.justice.subscription.jms.core.JmsEndPointGeneratorUtil.shouldGenerateEventFilter)1