Search in sources :

Example 26 with BeanManager

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);
        }
    }
}
Also used : CdiBeanContainerExtendedAccessImpl(org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ManagedBeanRegistry(org.hibernate.resource.beans.spi.ManagedBeanRegistry) BeanContainer(org.hibernate.resource.beans.container.spi.BeanContainer) SeContainer(jakarta.enterprise.inject.se.SeContainer) TestingExtendedBeanManager(org.hibernate.orm.test.cdi.testsupport.TestingExtendedBeanManager) BeanManager(jakarta.enterprise.inject.spi.BeanManager) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

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

Example 28 with BeanManager

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

Example 29 with BeanManager

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

Example 30 with BeanManager

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

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