use of uk.gov.justice.services.core.interceptor.InterceptorChainEntry 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