Search in sources :

Example 1 with JavaCompilerUtil

use of uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil in project microservice_framework by CJSCommonPlatform.

the class AbstractClientGeneratorTest method before.

@Before
public void before() {
    overrideLogger(generator, logger);
    compiler = new JavaCompilerUtil(outputFolder.getRoot(), outputFolder.getRoot());
}
Also used : JavaCompilerUtil(uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil) Before(org.junit.Before)

Example 2 with JavaCompilerUtil

use of uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil in project microservice_framework by CJSCommonPlatform.

the class SubscriptionJmsEndpointGeneratorTest method setup.

@Before
public void setup() throws Exception {
    generator = new JmsEndpointGenerationObjects().subscriptionJmsEndpointGenerator();
    compiler = new JavaCompilerUtil(outputFolder.getRoot(), outputFolder.getRoot());
    generatorProperties = new GeneratorPropertiesFactory().withDefaultServiceComponent();
}
Also used : JavaCompilerUtil(uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil) GeneratorPropertiesFactory(uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory) Before(org.junit.Before)

Example 3 with JavaCompilerUtil

use of uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil in project microservice_framework by CJSCommonPlatform.

the class EventFilterInterceptorCodeGeneratorTest method shouldGenerateAWorkingEventFilterInterceptorThatUsesACustomEventFilter.

@Test
public void shouldGenerateAWorkingEventFilterInterceptorThatUsesACustomEventFilter() throws Exception {
    final String packageName = "uk.gov.justice.api.interceptor.filter";
    final String simpleName = "MyCustomEventFilterInterceptor";
    final ClassName eventFilterInterceptorClassName = get(packageName, simpleName);
    final ClassName eventFilterClassName = get(MyCustomEventFilter.class);
    final ClassNameFactory classNameFactory = mock(ClassNameFactory.class);
    when(classNameFactory.classNameFor(EVENT_FILTER_INTERCEPTOR)).thenReturn(eventFilterInterceptorClassName);
    when(classNameFactory.classNameFor(EVENT_FILTER)).thenReturn(eventFilterClassName);
    final TypeSpec typeSpec = eventFilterInterceptorCodeGenerator.generate(classNameFactory);
    final File outputDirectory = getOutputDirectory("./target/test-generation");
    builder(packageName, typeSpec).build().writeTo(outputDirectory);
    final JavaCompilerUtil compiler = new JavaCompilerUtil(outputDirectory, COMPILATION_OUTPUT_DIRECTORY);
    final Class<?> compiledClass = compiler.compiledClassOf(packageName, simpleName);
    nowTestTheGeneratedClass(compiledClass);
    nowTestTheFailureCase(compiledClass);
}
Also used : JavaCompilerUtil(uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil) ClassNameFactory(uk.gov.justice.subscription.jms.core.ClassNameFactory) ClassName(com.squareup.javapoet.ClassName) File(java.io.File) TypeSpec(com.squareup.javapoet.TypeSpec) Test(org.junit.Test)

Example 4 with JavaCompilerUtil

use of uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil in project microservice_framework by CJSCommonPlatform.

the class EventValidationInterceptorCodeGeneratorTest method shouldGenerateAWorkingEventValidationInterceptorThatUsesACustomEventFilter.

@Test
public void shouldGenerateAWorkingEventValidationInterceptorThatUsesACustomEventFilter() throws Exception {
    final String packageName = "uk.gov.justice.api.interceptor.filter";
    final String simpleName = "MyCustomEventValidationInterceptor";
    final ClassName eventValidationInterceptorClassName = get(packageName, simpleName);
    final ClassName eventFilterClassName = get(MyCustomEventFilter.class);
    final ClassNameFactory classNameFactory = mock(ClassNameFactory.class);
    when(classNameFactory.classNameFor(EVENT_VALIDATION_INTERCEPTOR)).thenReturn(eventValidationInterceptorClassName);
    when(classNameFactory.classNameFor(EVENT_FILTER)).thenReturn(eventFilterClassName);
    final TypeSpec typeSpec = eventValidationInterceptorCodeGenerator.generate(classNameFactory);
    final File codeGenerationOutputDirectory = getDirectory(CODE_GENERATION_OUTPUT_DIRECTORY);
    final File compilationOutputDirectory = getDirectory(COMPILATION_OUTPUT_DIRECTORY);
    builder(packageName, typeSpec).addStaticImport(get(HeaderConstants.class), "JMS_HEADER_CPPNAME").build().writeTo(codeGenerationOutputDirectory);
    final JavaCompilerUtil compiler = new JavaCompilerUtil(codeGenerationOutputDirectory, compilationOutputDirectory);
    final Class<?> compiledClass = compiler.compiledClassOf(packageName, simpleName);
    nowTestTheGeneratedClass(compiledClass);
    nowTestTheFailureCase(compiledClass);
}
Also used : JavaCompilerUtil(uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil) HeaderConstants(uk.gov.justice.services.messaging.jms.HeaderConstants) ClassNameFactory(uk.gov.justice.subscription.jms.core.ClassNameFactory) ClassName(com.squareup.javapoet.ClassName) File(java.io.File) TypeSpec(com.squareup.javapoet.TypeSpec) Test(org.junit.Test)

Example 5 with JavaCompilerUtil

use of uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil in project microservice_framework by CJSCommonPlatform.

the class RamlMediaTypeToSchemaIdMapperClassBuilderTest method writeSourceFileAndCompile.

@SuppressWarnings("ConstantConditions")
private Class<?> writeSourceFileAndCompile(final String packageName, final TypeSpec typeSpec) throws IOException {
    final File outputFolderRoot = outputFolder.getRoot();
    JavaFile.builder(packageName, typeSpec).build().writeTo(outputFolderRoot);
    return new JavaCompilerUtil(outputFolderRoot, outputFolderRoot).compiledClassesOf(packageName).stream().filter(clazz -> !clazz.getName().equals("java.lang.Object")).findFirst().orElseGet(null);
}
Also used : JavaCompilerUtil(uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil) File(java.io.File) JavaFile(com.squareup.javapoet.JavaFile)

Aggregations

JavaCompilerUtil (uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil)9 File (java.io.File)7 ClassName (com.squareup.javapoet.ClassName)4 JavaFile (com.squareup.javapoet.JavaFile)4 TypeSpec (com.squareup.javapoet.TypeSpec)4 Test (org.junit.Test)3 ClassNameFactory (uk.gov.justice.subscription.jms.core.ClassNameFactory)3 Before (org.junit.Before)2 FieldSpec (com.squareup.javapoet.FieldSpec)1 MethodSpec (com.squareup.javapoet.MethodSpec)1 Stream (java.util.stream.Stream)1 Aggregate (uk.gov.justice.domain.aggregate.Aggregate)1 GeneratorPropertiesFactory (uk.gov.justice.raml.jms.config.GeneratorPropertiesFactory)1 InterceptorChainEntry (uk.gov.justice.services.core.interceptor.InterceptorChainEntry)1 InterceptorChainEntryProvider (uk.gov.justice.services.core.interceptor.InterceptorChainEntryProvider)1 HeaderConstants (uk.gov.justice.services.messaging.jms.HeaderConstants)1