use of jakarta.enterprise.inject.spi.BeanManager in project core by weld.
the class AlternativeDiscoveryTest 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 DevelopmentModeDisabledSmokeTest method testDevelopmentMode.
@SuppressWarnings("unchecked")
@Test
public void testDevelopmentMode() {
try (WeldContainer container = new Weld().initialize()) {
assertTrue(container.select(ProbeExtension.class).isUnsatisfied());
BeanManager beanManager = container.getBeanManager();
Bean<Omega> bean = (Bean<Omega>) beanManager.resolve(beanManager.getBeans(Omega.class));
assertFalse(bean.getStereotypes().contains(MonitoredComponent.class));
container.select(Omega.class).get().ping();
}
}
use of jakarta.enterprise.inject.spi.BeanManager in project core by weld.
the class DevelopmentModeEnabledSmokeTest method testDevelopmentMode.
@SuppressWarnings("unchecked")
@Test
public void testDevelopmentMode() {
try (WeldContainer container = new Weld().initialize()) {
assertNotNull(container.select(ProbeExtension.class).get());
BeanManager beanManager = container.getBeanManager();
Bean<Omega> bean = (Bean<Omega>) beanManager.resolve(beanManager.getBeans(Omega.class));
assertTrue(bean.getStereotypes().contains(MonitoredComponent.class));
container.select(Omega.class).get().ping();
}
}
use of jakarta.enterprise.inject.spi.BeanManager in project core by weld.
the class BasicCDIProviderTest 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());
}
use of jakarta.enterprise.inject.spi.BeanManager in project tomee by apache.
the class OpenEJBEnricher method resolve.
public static Object[] resolve(final AppContext appContext, final TestClass ignored, final Method method) {
// suppose all is a CDI bean...
final Object[] values = new Object[method.getParameterTypes().length];
if (appContext == null) {
return values;
}
final List<BeanManager> beanManagers = new ArrayList<>();
final BeanManager bm = findBeanManager(appContext);
if (bm != null) {
// then add web bean manager first, TODO: selection of the webapp containing the test?
for (final WebContext web : appContext.getWebContexts()) {
final WebBeansContext webBeansContext = web.getWebBeansContext();
if (webBeansContext == null) {
continue;
}
final BeanManagerImpl webAppBm = webBeansContext.getBeanManagerImpl();
if (bm != webAppBm) {
beanManagers.add(webAppBm);
}
}
beanManagers.add(bm);
}
if (beanManagers.isEmpty()) {
return values;
}
final Class<?>[] parameterTypes = method.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
Exception ex = null;
for (final BeanManager beanManager : beanManagers) {
try {
values[i] = getParamInstance(beanManager, i, method);
break;
} catch (final Exception e) {
ex = e;
}
}
if (ex != null) {
LOGGER.info(ex.getMessage());
}
}
return values;
}
Aggregations