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 core by weld.
the class BeanDiscoveryAlternativeTest method testAnnotatedBeanDiscoveryAlternative.
@Test
public void testAnnotatedBeanDiscoveryAlternative(Plant representative) {
BeanManager bm = representative.getBeanManager();
Set<Bean<?>> treeBeans = bm.getBeans(Tree.class);
assertEquals(2, treeBeans.size());
assertEquals(AlternativeTree.class, bm.resolve(treeBeans).getBeanClass());
Set<Bean<?>> stoneBeans = bm.getBeans(Stone.class);
assertEquals(0, stoneBeans.size());
}
use of jakarta.enterprise.inject.spi.BeanManager in project core by weld.
the class TestExtension method afterBeanDiscovery.
public void afterBeanDiscovery(@Observes AfterBeanDiscovery event) {
try {
CDI.current().select(Foo.class);
fail();
} catch (IllegalStateException expected) {
}
BeanManager beanManager = beanManagerReference.get();
if (beanManager != null) {
fooBeanReference.set(beanManager.resolve(beanManager.getBeans(Foo.class)));
}
}
use of jakarta.enterprise.inject.spi.BeanManager in project core by weld.
the class WeldSEProviderTest method testExtension.
@Test
public void testExtension() {
TestExtension.reset();
try (WeldContainer weldContainer = new Weld().disableDiscovery().beanClasses(Foo.class).addExtension(new TestExtension()).initialize()) {
BeanManager beanManager = TestExtension.beanManagerReference.get();
assertNotNull(beanManager);
Bean<?> fooBean = TestExtension.fooBeanReference.get();
assertNotNull(fooBean);
}
}
use of jakarta.enterprise.inject.spi.BeanManager in project core by weld.
the class AbstractCDIProviderTest method testCDIProvider.
@Test
public void testCDIProvider() {
BeanManager manager = KarateClubLocator.getBeanManager();
assertNotNull(manager);
// Boy, Girl, Chick
assertEquals(3, manager.getBeans(Child.class, Any.Literal.INSTANCE).size());
// Chick
assertEquals(1, manager.getBeans(Girl.class, PrettyLiteral.INSTANCE).size());
KarateClub club = KarateClubLocator.lookupKarateClub();
assertNotNull(club);
assertTrue(club.kick());
}
Aggregations