Search in sources :

Example 1 with InterceptorChainEntry

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)));
}
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) InterceptorChainEntryProvider(uk.gov.justice.services.core.interceptor.InterceptorChainEntryProvider) File(java.io.File) TypeSpec(com.squareup.javapoet.TypeSpec) InterceptorChainEntry(uk.gov.justice.services.core.interceptor.InterceptorChainEntry) Test(org.junit.Test)

Aggregations

ClassName (com.squareup.javapoet.ClassName)1 TypeSpec (com.squareup.javapoet.TypeSpec)1 File (java.io.File)1 Test (org.junit.Test)1 InterceptorChainEntry (uk.gov.justice.services.core.interceptor.InterceptorChainEntry)1 InterceptorChainEntryProvider (uk.gov.justice.services.core.interceptor.InterceptorChainEntryProvider)1 JavaCompilerUtil (uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil)1 ClassNameFactory (uk.gov.justice.subscription.jms.core.ClassNameFactory)1