Search in sources :

Example 11 with AfterDeploymentValidation

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"));
    }
}
Also used : AnnotationLiteral(javax.enterprise.util.AnnotationLiteral) AfterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation) BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with AfterDeploymentValidation

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));
}
Also used : AnnotationLiteral(javax.enterprise.util.AnnotationLiteral) AfterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation) BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AfterDeploymentValidation (javax.enterprise.inject.spi.AfterDeploymentValidation)12 Bean (javax.enterprise.inject.spi.Bean)11 BeanManager (javax.enterprise.inject.spi.BeanManager)11 Test (org.junit.Test)11 HashSet (java.util.HashSet)10 AnnotationLiteral (javax.enterprise.util.AnnotationLiteral)10 AfterBeanDiscovery (javax.enterprise.inject.spi.AfterBeanDiscovery)2 BeforeBeanDiscovery (javax.enterprise.inject.spi.BeforeBeanDiscovery)2 Extension (javax.enterprise.inject.spi.Extension)2 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)2 ProcessBean (javax.enterprise.inject.spi.ProcessBean)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1