Search in sources :

Example 21 with Bean

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));
}
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 22 with Bean

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));
}
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 23 with Bean

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));
}
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 24 with Bean

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"));
    }
}
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 25 with Bean

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));
}
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

Bean (javax.enterprise.inject.spi.Bean)259 Test (org.junit.Test)119 CreationalContext (javax.enterprise.context.spi.CreationalContext)110 BeanManager (javax.enterprise.inject.spi.BeanManager)76 URL (java.net.URL)68 Path (org.uberfire.backend.vfs.Path)67 KieModuleService (org.kie.workbench.common.services.shared.project.KieModuleService)66 Package (org.guvnor.common.services.project.model.Package)43 HashSet (java.util.HashSet)31 Annotation (java.lang.annotation.Annotation)18 ArrayList (java.util.ArrayList)14 Module (org.guvnor.common.services.project.model.Module)13 AnnotationLiteral (javax.enterprise.util.AnnotationLiteral)11 Type (java.lang.reflect.Type)9 Set (java.util.Set)9 AfterDeploymentValidation (javax.enterprise.inject.spi.AfterDeploymentValidation)9 BeanManagerImpl (org.apache.webbeans.container.BeanManagerImpl)9 Any (javax.enterprise.inject.Any)8 AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)8 Weld (org.jboss.weld.environment.se.Weld)8