Search in sources :

Example 1 with ClassNameFactory

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);
}
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 2 with ClassNameFactory

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);
}
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 3 with ClassNameFactory

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)));
}
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)3 TypeSpec (com.squareup.javapoet.TypeSpec)3 File (java.io.File)3 Test (org.junit.Test)3 JavaCompilerUtil (uk.gov.justice.services.test.utils.core.compiler.JavaCompilerUtil)3 ClassNameFactory (uk.gov.justice.subscription.jms.core.ClassNameFactory)3 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