Search in sources :

Example 91 with BeanManager

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());
}
Also used : BeanManager(jakarta.enterprise.inject.spi.BeanManager) Bean(jakarta.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 92 with BeanManager

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();
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(jakarta.enterprise.inject.spi.BeanManager) MonitoredComponent(org.jboss.weld.probe.MonitoredComponent) Weld(org.jboss.weld.environment.se.Weld) Bean(jakarta.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 93 with BeanManager

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();
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(jakarta.enterprise.inject.spi.BeanManager) MonitoredComponent(org.jboss.weld.probe.MonitoredComponent) Weld(org.jboss.weld.environment.se.Weld) Bean(jakarta.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 94 with BeanManager

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());
}
Also used : BeanManager(jakarta.enterprise.inject.spi.BeanManager) Test(org.junit.Test)

Example 95 with BeanManager

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;
}
Also used : WebContext(org.apache.openejb.core.WebContext) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanManagerImpl(org.apache.webbeans.container.BeanManagerImpl) ArrayList(java.util.ArrayList) TestClass(org.jboss.arquillian.test.spi.TestClass) BeanManager(jakarta.enterprise.inject.spi.BeanManager) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Aggregations

BeanManager (jakarta.enterprise.inject.spi.BeanManager)129 Bean (jakarta.enterprise.inject.spi.Bean)29 Test (org.testng.annotations.Test)22 Test (org.junit.Test)15 IOException (java.io.IOException)10 Test (org.junit.jupiter.api.Test)10 ServiceDescriptor (io.helidon.grpc.server.ServiceDescriptor)9 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)9 SeContainer (jakarta.enterprise.inject.se.SeContainer)9 FacesContext (jakarta.faces.context.FacesContext)9 NamingException (javax.naming.NamingException)9 TestContainer (org.jboss.arquillian.container.weld.embedded.mock.TestContainer)9 Map (java.util.Map)8 Set (java.util.Set)8 SpecAssertions (org.jboss.test.audit.annotations.SpecAssertions)8 Observes (jakarta.enterprise.event.Observes)7 Instance (jakarta.enterprise.inject.Instance)7 HashSet (java.util.HashSet)7 CreationalContext (jakarta.enterprise.context.spi.CreationalContext)6 SeContainerInitializer (jakarta.enterprise.inject.se.SeContainerInitializer)6