use of jakarta.enterprise.inject.spi.BeanManager in project hibernate-orm by hibernate.
the class ExtendedMixedAccessTest method doTest.
private void doTest(TestingExtendedBeanManager extendedBeanManager) {
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, extendedBeanManager).build()) {
final BeanContainer beanContainer = ssr.getService(ManagedBeanRegistry.class).getBeanContainer();
assertThat(beanContainer, instanceOf(CdiBeanContainerExtendedAccessImpl.class));
try (final SeContainer cdiContainer = Helper.createSeContainer()) {
final BeanManager beanManager = cdiContainer.getBeanManager();
extendedBeanManager.notifyListenerReady(beanManager);
assertThat(beanManager, sameInstance(((CdiBeanContainerExtendedAccessImpl) beanContainer).getUsableBeanManager()));
final ContainedBean<HostedBean> hostedBean = beanContainer.getBean(HostedBean.class, this, FallbackBeanInstanceProducer.INSTANCE);
assertThat(hostedBean, notNullValue());
assertThat(hostedBean.getBeanInstance(), notNullValue());
assertThat(hostedBean.getBeanInstance().getInjectedHostedBean(), notNullValue());
final ContainedBean<NonHostedBean> nonHostedBean = beanContainer.getBean(NonHostedBean.class, this, FallbackBeanInstanceProducer.INSTANCE);
assertThat(nonHostedBean, notNullValue());
assertThat(nonHostedBean.getBeanInstance(), notNullValue());
extendedBeanManager.notifyListenerShuttingDown(beanManager);
}
}
}
use of jakarta.enterprise.inject.spi.BeanManager in project resteasy by resteasy.
the class CdiInjectorFactory method lookupBeanManagerViaServletContext.
private static BeanManager lookupBeanManagerViaServletContext() {
BeanManager beanManager = null;
try {
// Look for BeanManager in ServletContext
ServletContext servletContext = ResteasyContext.getContextData(ServletContext.class);
// null check for RESTEASY-1009
if (servletContext != null) {
beanManager = (BeanManager) servletContext.getAttribute(BEAN_MANAGER_ATTRIBUTE_PREFIX + BeanManager.class.getName());
if (beanManager != null) {
LogMessages.LOGGER.debug(Messages.MESSAGES.foundBeanManagerInServletContext());
return beanManager;
}
// Look for BeanManager in ServletContext (the old attribute name for backwards compatibility)
beanManager = (BeanManager) servletContext.getAttribute(BeanManager.class.getName());
if (beanManager != null) {
LogMessages.LOGGER.debug(Messages.MESSAGES.foundBeanManagerInServletContext());
return beanManager;
}
}
} catch (NoClassDefFoundError e) {
LogMessages.LOGGER.debug(Messages.MESSAGES.unableToFindServletContextClass(), e);
} catch (Exception e) {
LogMessages.LOGGER.debug(Messages.MESSAGES.errorOccurredLookingUpServletContext(), e);
}
return beanManager;
}
use of jakarta.enterprise.inject.spi.BeanManager in project resteasy by resteasy.
the class WeldInitCDITest method testInitWeld.
/**
* @tpTestDetails Initialized weld should enable lookupBeanManagerCDIUtil method to work correctly.
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testInitWeld() {
Weld weld = new Weld();
// next assert fails without initialized weld
WeldContainer weldContainer = weld.initialize();
BeanManager bm = CdiInjectorFactory.lookupBeanManagerCDIUtil();
Assert.assertNotNull("Bean manager was not initialized successfully", bm);
weld.shutdown();
}
use of jakarta.enterprise.inject.spi.BeanManager in project core by weld.
the class InjectWeldManagerTest method testWeldManagerInjection.
@Test
public void testWeldManagerInjection() {
try (WeldContainer container = new Weld().initialize()) {
WeldInstance<WeldManager> managerInstance = container.select(WeldManager.class);
Assert.assertTrue(managerInstance.isResolvable());
// try some call on it
managerInstance.get().createAnnotatedType(SomeBean.class);
// verify that BeanManager and BeanManagerImpl are still injectable as well
WeldInstance<BeanManager> bmInstance = container.select(BeanManager.class);
Assert.assertTrue(bmInstance.isResolvable());
WeldInstance<BeanManagerImpl> bmImplInstance = container.select(BeanManagerImpl.class);
Assert.assertTrue(bmImplInstance.isResolvable());
}
}
use of jakarta.enterprise.inject.spi.BeanManager in project core by weld.
the class War1Listener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
// validate accessibility from the war1 module
Set<Bean<?>> accessibleImplementations = manager.getBeans(Animal.class);
assertEquals(accessibleImplementations.size(), 4);
assertTrue(containsBean(accessibleImplementations, War1Impl.class));
assertTrue(containsBean(accessibleImplementations, Library1Impl.class));
assertTrue(containsBean(accessibleImplementations, SharedLibrary1Impl.class));
assertTrue(containsBean(accessibleImplementations, SharedLibrary2Impl.class));
// validate accessibility from the war1 library module
Bean<?> library1ImplBean = getUniqueBean(accessibleImplementations, Library1Impl.class);
Library1Impl library1Impl = (Library1Impl) manager.getReference(library1ImplBean, Animal.class, manager.createCreationalContext(library1ImplBean));
BeanManager library1BeanManager = library1Impl.getBeanManager();
accessibleImplementations = library1BeanManager.getBeans(Animal.class);
assertEquals(accessibleImplementations.size(), 4);
assertTrue(containsBean(accessibleImplementations, War1Impl.class));
assertTrue(containsBean(accessibleImplementations, Library1Impl.class));
assertTrue(containsBean(accessibleImplementations, SharedLibrary1Impl.class));
assertTrue(containsBean(accessibleImplementations, SharedLibrary2Impl.class));
// validate accessibility from the shared library 1
Bean<?> sharedLibrary1ImplBean = getUniqueBean(accessibleImplementations, SharedLibrary1Impl.class);
SharedLibrary1Impl sharedLibrary1Impl = (SharedLibrary1Impl) manager.getReference(sharedLibrary1ImplBean, Animal.class, manager.createCreationalContext(sharedLibrary1ImplBean));
BeanManager sharedLibrary1BeanManager = sharedLibrary1Impl.getBeanManager();
accessibleImplementations = sharedLibrary1BeanManager.getBeans(Animal.class);
// implementations within wars are not accessible
assertEquals(accessibleImplementations.size(), 2);
assertTrue(containsBean(accessibleImplementations, SharedLibrary1Impl.class));
assertTrue(containsBean(accessibleImplementations, SharedLibrary2Impl.class));
// validate accessibility from the shared library 2
Bean<?> sharedLibrary2ImplBean = getUniqueBean(accessibleImplementations, SharedLibrary2Impl.class);
SharedLibrary2Impl sharedLibrary2Impl = (SharedLibrary2Impl) manager.getReference(sharedLibrary2ImplBean, Animal.class, manager.createCreationalContext(sharedLibrary2ImplBean));
BeanManager sharedLibrary2BeanManager = sharedLibrary2Impl.getBeanManager();
accessibleImplementations = sharedLibrary2BeanManager.getBeans(Animal.class);
// implementations within wars are not accessible
assertEquals(accessibleImplementations.size(), 2);
assertTrue(containsBean(accessibleImplementations, SharedLibrary1Impl.class));
assertTrue(containsBean(accessibleImplementations, SharedLibrary2Impl.class));
}
Aggregations