Search in sources :

Example 1 with SinglePrototypeInSpringContextTestBean

use of org.springframework.orm.jpa.hibernate.beans.SinglePrototypeInSpringContextTestBean 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 2 with SinglePrototypeInSpringContextTestBean

use of org.springframework.orm.jpa.hibernate.beans.SinglePrototypeInSpringContextTestBean 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)2 Test (org.junit.jupiter.api.Test)2 SinglePrototypeInSpringContextTestBean (org.springframework.orm.jpa.hibernate.beans.SinglePrototypeInSpringContextTestBean)2