Search in sources :

Example 1 with CdiBeanContainerExtendedAccessImpl

use of org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl in project hibernate-orm by hibernate.

the class ExtendedMixedAccessTest method testExtendedMixedAccess.

@Test
public void testExtendedMixedAccess() {
    final Helper.TestingExtendedBeanManager extendedBeanManager = Helper.createExtendedBeanManager();
    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 : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) CdiBeanContainerExtendedAccessImpl(org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl) ManagedBeanRegistry(org.hibernate.resource.beans.spi.ManagedBeanRegistry) BeanContainer(org.hibernate.resource.beans.container.spi.BeanContainer) SeContainer(javax.enterprise.inject.se.SeContainer) BeanManager(javax.enterprise.inject.spi.BeanManager) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Aggregations

SeContainer (javax.enterprise.inject.se.SeContainer)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 CdiBeanContainerExtendedAccessImpl (org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl)1 BeanContainer (org.hibernate.resource.beans.container.spi.BeanContainer)1 ManagedBeanRegistry (org.hibernate.resource.beans.spi.ManagedBeanRegistry)1 Test (org.junit.Test)1