use of javax.enterprise.inject.spi.AfterDeploymentValidation in project microservice_framework by CJSCommonPlatform.
the class ActionNameToMediaTypesMappingObserverTest 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(DodgyMediaTypesMapper.class);
try {
actionNameToMediaTypesMappingObserver.afterDeploymentValidation(event, beanManager);
fail();
} catch (final BadMediaTypesMapperAnnotationException expected) {
assertThat(expected.getMessage(), is("Class 'uk.gov.justice.services.core.mapping.ActionNameToMediaTypesMappingObserverTest$DodgyMediaTypesMapper' " + "annotated with @MediaTypesMapper " + "should implement the 'uk.gov.justice.services.core.mapping.ActionNameToMediaTypesMapper' interface"));
}
}
use of javax.enterprise.inject.spi.AfterDeploymentValidation in project microservice_framework by CJSCommonPlatform.
the class SchemaIdMappingObserverTest method shouldOnlyRegisterAnnotatedSchemaIdMappers.
@Test
public void shouldOnlyRegisterAnnotatedSchemaIdMappers() 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(Object.class);
schemaIdMappingObserver.afterDeploymentValidation(event, beanManager);
final List<Bean<MediaTypeToSchemaIdMapper>> interceptorBeans = schemaIdMappingObserver.getMediaTypeToSchemaIdMappers();
assertThat(interceptorBeans.size(), is(1));
assertThat(interceptorBeans, containsInAnyOrder(bean_1));
}
Aggregations