use of javax.enterprise.inject.spi.Bean in project microservice_framework by CJSCommonPlatform.
the class InterceptorChainObserverTest method shouldRegisterInterceptorChainEntryProvider.
@Test
public void shouldRegisterInterceptorChainEntryProvider() throws Exception {
final BeanManager beanManager = mock(BeanManager.class);
final AfterDeploymentValidation event = mock(AfterDeploymentValidation.class);
final Bean bean_1 = mock(Bean.class);
final Bean bean_2 = mock(Bean.class);
final Set<Bean<?>> beans = new HashSet<>();
beans.add(bean_1);
beans.add(bean_2);
when(beanManager.getBeans(eq(InterceptorChainEntryProvider.class), any(AnnotationLiteral.class))).thenReturn(beans);
when(bean_1.getBeanClass()).thenReturn(Object.class);
when(bean_2.getBeanClass()).thenReturn(Object.class);
interceptorChainObserver.afterDeploymentValidation(event, beanManager);
final List<Bean<?>> interceptorBeans = interceptorChainObserver.getInterceptorChainProviderBeans();
assertThat(interceptorBeans, containsInAnyOrder(bean_1, bean_2));
}
use of javax.enterprise.inject.spi.Bean in project microservice_framework by CJSCommonPlatform.
the class ActionNameToMediaTypesMappingObserverTest method shouldRegisterAnnotatedMediaTypesMappers.
@Test
public void shouldRegisterAnnotatedMediaTypesMappers() throws Exception {
final BeanManager beanManager = mock(BeanManager.class);
final AfterDeploymentValidation event = mock(AfterDeploymentValidation.class);
final Bean bean_1 = mock(Bean.class);
final Bean bean_2 = mock(Bean.class);
final Set<Bean<?>> beans = new HashSet<>();
beans.add(bean_1);
beans.add(bean_2);
when(beanManager.getBeans(eq(Object.class), any(AnnotationLiteral.class))).thenReturn(beans);
when(bean_1.getBeanClass()).thenReturn(TestMediaTypesMapperAction.class);
when(bean_2.getBeanClass()).thenReturn(TestMediaTypesMapperAction.class);
actionNameToMediaTypesMappingObserver.afterDeploymentValidation(event, beanManager);
final List<Bean<ActionNameToMediaTypesMapper>> interceptorBeans = actionNameToMediaTypesMappingObserver.getNameMediaTypesMappers();
assertThat(interceptorBeans.size(), is(2));
assertThat(interceptorBeans, containsInAnyOrder(bean_1, bean_2));
}
use of javax.enterprise.inject.spi.Bean in project microservice_framework by CJSCommonPlatform.
the class ActionNameToMediaTypesMappingObserverTest method shouldOnlyRegisterAnnotatedMediaTypesMappers.
@Test
public void shouldOnlyRegisterAnnotatedMediaTypesMappers() throws Exception {
final BeanManager beanManager = mock(BeanManager.class);
final AfterDeploymentValidation event = mock(AfterDeploymentValidation.class);
final Bean bean_1 = mock(Bean.class);
final Bean bean_2 = mock(Bean.class);
final Set<Bean<?>> beans = new HashSet<>();
beans.add(bean_1);
beans.add(bean_2);
when(beanManager.getBeans(eq(Object.class), any(AnnotationLiteral.class))).thenReturn(beans);
when(bean_1.getBeanClass()).thenReturn(TestMediaTypesMapperAction.class);
when(bean_2.getBeanClass()).thenReturn(Object.class);
actionNameToMediaTypesMappingObserver.afterDeploymentValidation(event, beanManager);
final List<Bean<ActionNameToMediaTypesMapper>> interceptorBeans = actionNameToMediaTypesMappingObserver.getNameMediaTypesMappers();
assertThat(interceptorBeans.size(), is(1));
assertThat(interceptorBeans, containsInAnyOrder(bean_1));
}
use of javax.enterprise.inject.spi.Bean in project microservice_framework by CJSCommonPlatform.
the class SchemaIdMappingObserverTest method shouldFailIfTheBeanAnnotatedWithSchemaIdMapperIsNotAnInstanceOfMediaTypeToSchemaIdMapper.
@Test
public void shouldFailIfTheBeanAnnotatedWithSchemaIdMapperIsNotAnInstanceOfMediaTypeToSchemaIdMapper() throws Exception {
final BeanManager beanManager = mock(BeanManager.class);
final AfterDeploymentValidation event = mock(AfterDeploymentValidation.class);
final Bean bean_1 = mock(Bean.class);
final Set<Bean<?>> beans = new HashSet<>();
beans.add(bean_1);
when(beanManager.getBeans(eq(Object.class), any(AnnotationLiteral.class))).thenReturn(beans);
when(bean_1.getBeanClass()).thenReturn(DodgySchemaIdMapper.class);
try {
schemaIdMappingObserver.afterDeploymentValidation(event, beanManager);
fail();
} catch (final BadSchemaIdMapperAnnotationException expected) {
assertThat(expected.getMessage(), is("Class 'uk.gov.justice.services.core.mapping.SchemaIdMappingObserverTest$DodgySchemaIdMapper' " + "annotated with @SchemaIdMapper " + "should implement the 'uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper' interface"));
}
}
use of javax.enterprise.inject.spi.Bean in project microservice_framework by CJSCommonPlatform.
the class SchemaIdMappingObserverTest method shouldRegisterAnnotatedSchemaIdMappers.
@Test
public void shouldRegisterAnnotatedSchemaIdMappers() throws Exception {
final BeanManager beanManager = mock(BeanManager.class);
final AfterDeploymentValidation event = mock(AfterDeploymentValidation.class);
final Bean bean_1 = mock(Bean.class);
final Bean bean_2 = mock(Bean.class);
final Set<Bean<?>> beans = new HashSet<>();
beans.add(bean_1);
beans.add(bean_2);
when(beanManager.getBeans(eq(Object.class), any(AnnotationLiteral.class))).thenReturn(beans);
when(bean_1.getBeanClass()).thenReturn(TestSchemaIdMapper.class);
when(bean_2.getBeanClass()).thenReturn(TestSchemaIdMapper.class);
schemaIdMappingObserver.afterDeploymentValidation(event, beanManager);
final List<Bean<MediaTypeToSchemaIdMapper>> interceptorBeans = schemaIdMappingObserver.getMediaTypeToSchemaIdMappers();
assertThat(interceptorBeans.size(), is(2));
assertThat(interceptorBeans, containsInAnyOrder(bean_1, bean_2));
}
Aggregations