Search in sources :

Example 6 with BeanContainer

use of org.hibernate.resource.beans.container.spi.BeanContainer in project spring-framework by spring-projects.

the class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests method testCanRetrieveFallbackBeanByTypeWithNativeOptions.

@Test
public void testCanRetrieveFallbackBeanByTypeWithNativeOptions() {
    BeanContainer beanContainer = getBeanContainer();
    assertThat(beanContainer).isNotNull();
    NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer();
    ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean(NoDefinitionInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, fallbackProducer);
    assertThat(fallbackProducer.currentUnnamedInstantiationCount()).isEqualTo(1);
    assertThat(fallbackProducer.currentNamedInstantiationCount()).isEqualTo(0);
    assertThat(bean).isNotNull();
    NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance();
    assertThat(instance).isNotNull();
    assertThat(instance.getSource()).isEqualTo(BeanSource.FALLBACK);
    assertThat(instance.getApplicationContext()).isNull();
}
Also used : BeanContainer(org.hibernate.resource.beans.container.spi.BeanContainer) NoDefinitionInSpringContextTestBean(org.springframework.orm.jpa.hibernate.beans.NoDefinitionInSpringContextTestBean) Test(org.junit.jupiter.api.Test)

Example 7 with BeanContainer

use of org.hibernate.resource.beans.container.spi.BeanContainer in project spring-framework by spring-projects.

the class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests method testCanRetrieveBeanByTypeWithNativeOptions.

@Test
public void testCanRetrieveBeanByTypeWithNativeOptions() {
    BeanContainer beanContainer = getBeanContainer();
    assertThat(beanContainer).isNotNull();
    ContainedBean<SinglePrototypeInSpringContextTestBean> bean = beanContainer.getBean(SinglePrototypeInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE);
    assertThat(bean).isNotNull();
    SinglePrototypeInSpringContextTestBean instance = bean.getBeanInstance();
    assertThat(instance).isNotNull();
    assertThat(instance.getName()).isEqualTo("single");
    assertThat(instance.getApplicationContext()).isSameAs(applicationContext);
    ContainedBean<SinglePrototypeInSpringContextTestBean> bean2 = beanContainer.getBean(SinglePrototypeInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE);
    assertThat(bean2).isNotNull();
    SinglePrototypeInSpringContextTestBean instance2 = bean2.getBeanInstance();
    assertThat(instance2).isNotNull();
    // Due to the lifecycle options, and because the bean has the "prototype" scope, we should not return the same instance
    assertThat(instance2).isNotSameAs(instance);
}
Also used : BeanContainer(org.hibernate.resource.beans.container.spi.BeanContainer) SinglePrototypeInSpringContextTestBean(org.springframework.orm.jpa.hibernate.beans.SinglePrototypeInSpringContextTestBean) Test(org.junit.jupiter.api.Test)

Example 8 with BeanContainer

use of org.hibernate.resource.beans.container.spi.BeanContainer in project spring-framework by spring-projects.

the class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests method testCanRetrieveFallbackBeanByNameWithJpaCompliantOptions.

@Test
public void testCanRetrieveFallbackBeanByNameWithJpaCompliantOptions() {
    BeanContainer beanContainer = getBeanContainer();
    assertThat(beanContainer).isNotNull();
    NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer();
    ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean("some name", NoDefinitionInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, fallbackProducer);
    assertThat(fallbackProducer.currentUnnamedInstantiationCount()).isEqualTo(0);
    assertThat(fallbackProducer.currentNamedInstantiationCount()).isEqualTo(1);
    assertThat(bean).isNotNull();
    NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance();
    assertThat(instance).isNotNull();
    assertThat(instance.getSource()).isEqualTo(BeanSource.FALLBACK);
    assertThat(instance.getName()).isEqualTo("some name");
    assertThat(instance.getApplicationContext()).isNull();
}
Also used : BeanContainer(org.hibernate.resource.beans.container.spi.BeanContainer) NoDefinitionInSpringContextTestBean(org.springframework.orm.jpa.hibernate.beans.NoDefinitionInSpringContextTestBean) Test(org.junit.jupiter.api.Test)

Example 9 with BeanContainer

use of org.hibernate.resource.beans.container.spi.BeanContainer in project spring-framework by spring-projects.

the class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests method testCanRetrieveFallbackBeanByNameWithNativeOptions.

@Test
public void testCanRetrieveFallbackBeanByNameWithNativeOptions() {
    BeanContainer beanContainer = getBeanContainer();
    assertThat(beanContainer).isNotNull();
    NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer();
    ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean("some name", NoDefinitionInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, fallbackProducer);
    assertThat(fallbackProducer.currentUnnamedInstantiationCount()).isEqualTo(0);
    assertThat(fallbackProducer.currentNamedInstantiationCount()).isEqualTo(1);
    assertThat(bean).isNotNull();
    NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance();
    assertThat(instance).isNotNull();
    assertThat(instance.getSource()).isEqualTo(BeanSource.FALLBACK);
    assertThat(instance.getName()).isEqualTo("some name");
    assertThat(instance.getApplicationContext()).isNull();
}
Also used : BeanContainer(org.hibernate.resource.beans.container.spi.BeanContainer) NoDefinitionInSpringContextTestBean(org.springframework.orm.jpa.hibernate.beans.NoDefinitionInSpringContextTestBean) Test(org.junit.jupiter.api.Test)

Example 10 with BeanContainer

use of org.hibernate.resource.beans.container.spi.BeanContainer in project spring-framework by spring-projects.

the class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests method testCanRetrieveBeanByTypeWithJpaCompliantOptions.

@Test
public void testCanRetrieveBeanByTypeWithJpaCompliantOptions() {
    BeanContainer beanContainer = getBeanContainer();
    assertThat(beanContainer).isNotNull();
    ContainedBean<SinglePrototypeInSpringContextTestBean> bean = beanContainer.getBean(SinglePrototypeInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE);
    assertThat(bean).isNotNull();
    SinglePrototypeInSpringContextTestBean instance = bean.getBeanInstance();
    assertThat(instance).isNotNull();
    assertThat(instance.getApplicationContext()).isSameAs(applicationContext);
}
Also used : BeanContainer(org.hibernate.resource.beans.container.spi.BeanContainer) SinglePrototypeInSpringContextTestBean(org.springframework.orm.jpa.hibernate.beans.SinglePrototypeInSpringContextTestBean) Test(org.junit.jupiter.api.Test)

Aggregations

BeanContainer (org.hibernate.resource.beans.container.spi.BeanContainer)13 Test (org.junit.jupiter.api.Test)8 NoDefinitionInSpringContextTestBean (org.springframework.orm.jpa.hibernate.beans.NoDefinitionInSpringContextTestBean)4 SeContainer (javax.enterprise.inject.se.SeContainer)3 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)3 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)3 Test (org.junit.Test)3 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)2 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)2 ManagedBeanRegistry (org.hibernate.resource.beans.spi.ManagedBeanRegistry)2 MultiplePrototypesInSpringContextTestBean (org.springframework.orm.jpa.hibernate.beans.MultiplePrototypesInSpringContextTestBean)2 SinglePrototypeInSpringContextTestBean (org.springframework.orm.jpa.hibernate.beans.SinglePrototypeInSpringContextTestBean)2 BeanManager (javax.enterprise.inject.spi.BeanManager)1 InstantiationException (org.hibernate.InstantiationException)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)1 CdiBeanContainerDelayedAccessImpl (org.hibernate.resource.beans.container.internal.CdiBeanContainerDelayedAccessImpl)1 CdiBeanContainerExtendedAccessImpl (org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl)1 CdiBeanContainerImmediateAccessImpl (org.hibernate.resource.beans.container.internal.CdiBeanContainerImmediateAccessImpl)1