Search in sources :

Example 6 with AfterDeploymentValidation

use of javax.enterprise.inject.spi.AfterDeploymentValidation 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 7 with AfterDeploymentValidation

use of javax.enterprise.inject.spi.AfterDeploymentValidation 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 8 with AfterDeploymentValidation

use of javax.enterprise.inject.spi.AfterDeploymentValidation 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 9 with AfterDeploymentValidation

use of javax.enterprise.inject.spi.AfterDeploymentValidation 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)

Example 10 with AfterDeploymentValidation

use of javax.enterprise.inject.spi.AfterDeploymentValidation in project core by weld.

the class ContainerLifecyleObserverTest method testExtensionBuilder.

@SuppressWarnings({ "serial" })
@Test
public void testExtensionBuilder() {
    ActionSequence.reset();
    Extension myExtension = ContainerLifecycleObserver.extensionBuilder().add(beforeBeanDiscovery((e) -> addAction(BeforeBeanDiscovery.class.getSimpleName()))).add(afterTypeDiscovery().notify((e, b) -> {
        addAction(AfterTypeDiscovery.class.getSimpleName());
        e.addAnnotatedType(b.createAnnotatedType(Charlie.class), Charlie.class.getName());
    })).add(afterBeanDiscovery((e) -> {
        addAction(AfterBeanDiscovery.class.getSimpleName());
        e.addObserverMethod().beanClass(Foo.class).observedType(Foo.class).notifyWith((ctx) -> {
        });
        e.addBean().beanClass(Integer.class).addType(Integer.class).addQualifier(Juicy.Literal.INSTANCE).createWith((ctx) -> Integer.valueOf(10));
    })).add(afterDeploymentValidation((e) -> addAction(AfterDeploymentValidation.class.getSimpleName()))).add(beforeShutdown((e) -> addAction(BeforeShutdown.class.getSimpleName()))).build();
    Extension myExtension2 = ContainerLifecycleObserver.extensionBuilder().add(processAnnotatedType().withAnnotations(RequestScoped.class).notify((e) -> e.veto())).add(processBeanAttributes().notify((e) -> addAction(ProcessBeanAttributes.class.getSimpleName()))).add(processSyntheticAnnotatedType(new TypeLiteral<ProcessSyntheticAnnotatedType<?>>() {
    }.getType()).notify((e) -> addAction(ProcessSyntheticAnnotatedType.class.getSimpleName()))).add(processInjectionPoint().notify((e) -> addAction(ProcessInjectionPoint.class.getSimpleName()))).add(processProducer().notify((e) -> addAction(ProcessProducer.class.getSimpleName()))).add(processBean().notify((e) -> addAction(ProcessBean.class.getSimpleName()))).add(processManagedBean().notify((e) -> addAction(ProcessManagedBean.class.getSimpleName()))).add(processProducerField().notify((e) -> addAction(ProcessProducerField.class.getSimpleName()))).add(processProducerMethod().notify((e) -> {
        // Weld SE defines some producer methods, e.g. ParametersFactory
        addAction(ProcessProducerMethod.class.getSimpleName());
    })).add(processBeanAttributes().notify((e) -> addAction(ProcessBeanAttributes.class.getSimpleName()))).add(processObserverMethod().notify((e) -> addAction(ProcessObserverMethod.class.getSimpleName()))).add(processObserverMethod(new TypeLiteral<ProcessObserverMethod<String, ?>>() {
    }.getType()).notify((e) -> addAction(ProcessObserverMethod.class.getSimpleName() + String.class.getSimpleName()))).add(processSyntheticObserverMethod(new TypeLiteral<ProcessSyntheticObserverMethod<Foo, ?>>() {
    }.getType()).notify((e) -> addAction(ProcessSyntheticObserverMethod.class.getSimpleName() + Foo.class.getSimpleName()))).add(processSyntheticBean(new TypeLiteral<ProcessSyntheticBean<Integer>>() {
    }.getType()).notify((e) -> addAction(ProcessSyntheticBean.class.getSimpleName() + Integer.class.getSimpleName()))).build();
    try (WeldContainer container = new Weld().disableDiscovery().beanClasses(Foo.class, Bravo.class).addExtension(myExtension).addExtension(myExtension2).initialize()) {
        assertTrue(container.select(Foo.class).isUnsatisfied());
        assertFalse(container.select(Bravo.class).isUnsatisfied());
        Assert.assertEquals(Integer.valueOf(10), container.select(Integer.class, Juicy.Literal.INSTANCE).get());
    }
    ActionSequence.assertSequenceDataContainsAll(BeforeBeanDiscovery.class, AfterTypeDiscovery.class, AfterBeanDiscovery.class, AfterDeploymentValidation.class, BeforeShutdown.class);
    ActionSequence.assertSequenceDataContainsAll(ProcessBeanAttributes.class, ProcessSyntheticAnnotatedType.class, ProcessInjectionPoint.class, ProcessObserverMethod.class, ProcessBeanAttributes.class, ProcessProducer.class);
    ActionSequence.assertSequenceDataContainsAll(ProcessObserverMethod.class.getSimpleName() + String.class.getSimpleName(), ProcessSyntheticObserverMethod.class.getSimpleName() + Foo.class.getSimpleName(), ProcessSyntheticBean.class.getSimpleName() + Integer.class.getSimpleName());
    ActionSequence.assertSequenceDataContainsAll(ProcessBean.class, ProcessManagedBean.class, ProcessProducerMethod.class, ProcessProducerField.class);
}
Also used : ContainerLifecycleObserver.processObserverMethod(org.jboss.weld.environment.se.ContainerLifecycleObserver.processObserverMethod) ContainerLifecycleObserver.processSyntheticBean(org.jboss.weld.environment.se.ContainerLifecycleObserver.processSyntheticBean) AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) ContainerLifecycleObserver.beforeBeanDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.beforeBeanDiscovery) ContainerLifecycleObserver.afterBeanDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterBeanDiscovery) ContainerLifecycleObserver.afterTypeDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterTypeDiscovery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProcessSyntheticBean(javax.enterprise.inject.spi.ProcessSyntheticBean) ProcessBean(javax.enterprise.inject.spi.ProcessBean) ContainerLifecycleObserver.processProducer(org.jboss.weld.environment.se.ContainerLifecycleObserver.processProducer) ContainerLifecycleObserver.processBean(org.jboss.weld.environment.se.ContainerLifecycleObserver.processBean) ContainerLifecycleObserver.beforeShutdown(org.jboss.weld.environment.se.ContainerLifecycleObserver.beforeShutdown) ProcessProducer(javax.enterprise.inject.spi.ProcessProducer) ProcessProducerField(javax.enterprise.inject.spi.ProcessProducerField) BeforeBeanDiscovery(javax.enterprise.inject.spi.BeforeBeanDiscovery) TypeLiteral(javax.enterprise.util.TypeLiteral) ActionSequence(org.jboss.weld.test.util.ActionSequence) ContainerLifecycleObserver.processInjectionPoint(org.jboss.weld.environment.se.ContainerLifecycleObserver.processInjectionPoint) ProcessObserverMethod(javax.enterprise.inject.spi.ProcessObserverMethod) AfterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation) ContainerLifecycleObserver.processSyntheticAnnotatedType(org.jboss.weld.environment.se.ContainerLifecycleObserver.processSyntheticAnnotatedType) ContainerLifecycleObserver.processProducerField(org.jboss.weld.environment.se.ContainerLifecycleObserver.processProducerField) Weld(org.jboss.weld.environment.se.Weld) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) ContainerLifecycleObserver.processSyntheticObserverMethod(org.jboss.weld.environment.se.ContainerLifecycleObserver.processSyntheticObserverMethod) Extension(javax.enterprise.inject.spi.Extension) ProcessManagedBean(javax.enterprise.inject.spi.ProcessManagedBean) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ContainerLifecycleObserver.processManagedBean(org.jboss.weld.environment.se.ContainerLifecycleObserver.processManagedBean) ProcessSyntheticAnnotatedType(javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType) WeldContainer(org.jboss.weld.environment.se.WeldContainer) ProcessProducerMethod(javax.enterprise.inject.spi.ProcessProducerMethod) ContainerLifecycleObserver.afterDeploymentValidation(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterDeploymentValidation) ContainerLifecycleObserver.processProducerMethod(org.jboss.weld.environment.se.ContainerLifecycleObserver.processProducerMethod) AfterTypeDiscovery(javax.enterprise.inject.spi.AfterTypeDiscovery) ContainerLifecycleObserver(org.jboss.weld.environment.se.ContainerLifecycleObserver) Assert.assertFalse(org.junit.Assert.assertFalse) RequestScoped(javax.enterprise.context.RequestScoped) BeforeShutdown(javax.enterprise.inject.spi.BeforeShutdown) ActionSequence.addAction(org.jboss.weld.test.util.ActionSequence.addAction) ProcessBeanAttributes(javax.enterprise.inject.spi.ProcessBeanAttributes) ContainerLifecycleObserver.processAnnotatedType(org.jboss.weld.environment.se.ContainerLifecycleObserver.processAnnotatedType) Assert(org.junit.Assert) ContainerLifecycleObserver.processBeanAttributes(org.jboss.weld.environment.se.ContainerLifecycleObserver.processBeanAttributes) ProcessSyntheticObserverMethod(javax.enterprise.inject.spi.ProcessSyntheticObserverMethod) WeldContainer(org.jboss.weld.environment.se.WeldContainer) AfterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation) ProcessObserverMethod(javax.enterprise.inject.spi.ProcessObserverMethod) ProcessSyntheticAnnotatedType(javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType) Weld(org.jboss.weld.environment.se.Weld) Extension(javax.enterprise.inject.spi.Extension) ProcessManagedBean(javax.enterprise.inject.spi.ProcessManagedBean) ProcessSyntheticBean(javax.enterprise.inject.spi.ProcessSyntheticBean) TypeLiteral(javax.enterprise.util.TypeLiteral) ProcessProducer(javax.enterprise.inject.spi.ProcessProducer) AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) 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