use of uk.gov.justice.subscription.jms.core.ClassNameFactory 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.subscription.jms.core.ClassNameFactory 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.subscription.jms.core.ClassNameFactory in project microservice_framework by CJSCommonPlatform.
the class EventListenerInterceptorChainProviderCodeGeneratorTest method shouldGenerateAWorkingEventListenerInterceptorChainProviderWithTheCorrectInterceptorChainEntiresAndComponentName.
@Test
public void shouldGenerateAWorkingEventListenerInterceptorChainProviderWithTheCorrectInterceptorChainEntiresAndComponentName() throws Exception {
final String componentName = "MY_CUSTOM_EVENT_LISTENER";
final String packageName = "uk.gov.justice.api.interceptor.filter";
final String simpleName = "MyCustomEventListenerInterceptorChainProvider";
final ClassName eventListenerInterceptorChainProviderClassName = ClassName.get(packageName, simpleName);
final ClassName eventFilterInterceptorClassName = ClassName.get(StubEventFilterInterceptor.class);
final ClassNameFactory classNameFactory = mock(ClassNameFactory.class);
when(classNameFactory.classNameFor(EVENT_LISTENER_INTERCEPTOR_CHAIN_PROVIDER)).thenReturn(eventListenerInterceptorChainProviderClassName);
when(classNameFactory.classNameFor(EVENT_FILTER_INTERCEPTOR)).thenReturn(eventFilterInterceptorClassName);
final TypeSpec typeSpec = eventListenerInterceptorChainProviderCodeGenerator.generate(componentName, classNameFactory);
final File codeGenerationOutputDirectory = getDirectory(CODE_GENERATION_OUTPUT_DIRECTORY);
final File compilationOutputDirectory = getDirectory(COMPILATION_OUTPUT_DIRECTORY);
builder(packageName, typeSpec).build().writeTo(codeGenerationOutputDirectory);
final JavaCompilerUtil compiler = new JavaCompilerUtil(codeGenerationOutputDirectory, compilationOutputDirectory);
final Class<?> compiledClass = compiler.compiledClassOf(packageName, simpleName);
final InterceptorChainEntryProvider interceptorChainEntryProvider = (InterceptorChainEntryProvider) compiledClass.newInstance();
assertThat(interceptorChainEntryProvider.component(), is(componentName));
final List<InterceptorChainEntry> interceptorChainEntries = interceptorChainEntryProvider.interceptorChainTypes();
assertThat(interceptorChainEntries, hasItem(new InterceptorChainEntry(1000, EventBufferInterceptor.class)));
assertThat(interceptorChainEntries, hasItem(new InterceptorChainEntry(2000, StubEventFilterInterceptor.class)));
}
Aggregations