use of javax.enterprise.inject.spi.AfterDeploymentValidation in project meecrowave by apache.
the class JpaExtension method initBeans.
void initBeans(@Observes final AfterDeploymentValidation adv, final BeanManager bm) {
if (entityManagerBeans.isEmpty()) {
return;
}
// only not portable part is this config read, could be optional
final ServletContext sc = ServletContext.class.cast(bm.getReference(bm.resolve(bm.getBeans(ServletContext.class)), ServletContext.class, bm.createCreationalContext(null)));
final Meecrowave.Builder config = Meecrowave.Builder.class.cast(sc.getAttribute("meecrowave.configuration"));
final Map<String, String> props = new HashMap<>();
if (config != null) {
ofNullable(config.getProperties()).ifPresent(p -> p.stringPropertyNames().stream().filter(k -> k.startsWith("jpa.property.")).forEach(k -> props.put(k.substring("jpa.property.".length()), p.getProperty(k))));
}
final Map<String, PersistenceUnitInfo> infoIndex = unitBuilders.stream().map(bean -> {
final CreationalContext<?> cc = bm.createCreationalContext(null);
try {
final Bean<?> resolvedBean = bm.resolve(bm.getBeans(PersistenceUnitInfoBuilder.class, bean.getQualifiers().toArray(new Annotation[bean.getQualifiers().size()])));
final PersistenceUnitInfoBuilder builder = PersistenceUnitInfoBuilder.class.cast(bm.getReference(resolvedBean, PersistenceUnitInfoBuilder.class, cc));
if (builder.getManagedClasses().isEmpty()) {
builder.setManagedClassNames(jpaClasses).setExcludeUnlistedClasses(true);
}
props.forEach(builder::addProperty);
return builder.toInfo();
} finally {
cc.release();
}
}).collect(toMap(PersistenceUnitInfo::getPersistenceUnitName, identity()));
entityManagerBeans.forEach((k, e) -> {
PersistenceUnitInfo info = infoIndex.get(k.unitName);
if (info == null) {
info = tryCreateDefaultPersistenceUnit(k.unitName, bm, props);
}
if (info == null) {
// not valid
adv.addDeploymentProblem(new IllegalArgumentException("Didn't find any PersistenceUnitInfoBuilder for " + k));
} else {
e.init(info, bm);
}
});
}
use of javax.enterprise.inject.spi.AfterDeploymentValidation in project microservice_framework by CJSCommonPlatform.
the class InterceptorChainObserverTest method shouldRegisterInterceptor.
@Test
public void shouldRegisterInterceptor() 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(Interceptor.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.getInterceptorBeans();
assertThat(interceptorBeans, containsInAnyOrder(bean_1, bean_2));
}
use of javax.enterprise.inject.spi.AfterDeploymentValidation in project microservice_framework by CJSCommonPlatform.
the class InterceptorChainObserverTest method shouldRegisterDeprecatedInterceptorChainProvider.
@Test
public void shouldRegisterDeprecatedInterceptorChainProvider() 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(InterceptorChainProvider.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));
}
use of javax.enterprise.inject.spi.AfterDeploymentValidation in project microservice_framework by CJSCommonPlatform.
the class InterceptorChainObserverTest method shouldRegisterBothTypesOfInterceptorChainProvider.
@Test
public void shouldRegisterBothTypesOfInterceptorChainProvider() 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<?>> interceptorChainEntryProviderBeans = new HashSet<>();
interceptorChainEntryProviderBeans.add(bean_1);
final Set<Bean<?>> interceptorChainProviderBeans = new HashSet<>();
interceptorChainProviderBeans.add(bean_2);
when(beanManager.getBeans(eq(InterceptorChainEntryProvider.class), any(AnnotationLiteral.class))).thenReturn(interceptorChainEntryProviderBeans);
when(bean_1.getBeanClass()).thenReturn(Object.class);
when(beanManager.getBeans(eq(InterceptorChainProvider.class), any(AnnotationLiteral.class))).thenReturn(interceptorChainProviderBeans);
when(bean_2.getBeanClass()).thenReturn(Object.class);
interceptorChainObserver.afterDeploymentValidation(event, beanManager);
final List<Bean<?>> interceptorBeans = interceptorChainObserver.getInterceptorChainProviderBeans();
assertThat(interceptorBeans, containsInAnyOrder(bean_1, bean_2));
}
use of javax.enterprise.inject.spi.AfterDeploymentValidation 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));
}
Aggregations