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