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