use of org.hibernate.resource.beans.container.spi.BeanContainer in project spring-framework by spring-projects.
the class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests method testCanRetrieveFallbackBeanByTypeWithJpaCompliantOptions.
@Test
public void testCanRetrieveFallbackBeanByTypeWithJpaCompliantOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer();
ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean(NoDefinitionInSpringContextTestBean.class, JpaLifecycleOptions.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();
}
use of org.hibernate.resource.beans.container.spi.BeanContainer in project spring-framework by spring-projects.
the class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests method testCanRetrieveBeanByNameWithNativeOptions.
@Test
public void testCanRetrieveBeanByNameWithNativeOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
ContainedBean<MultiplePrototypesInSpringContextTestBean> bean = beanContainer.getBean("multiple-1", MultiplePrototypesInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE);
assertThat(bean).isNotNull();
MultiplePrototypesInSpringContextTestBean instance = bean.getBeanInstance();
assertThat(instance).isNotNull();
assertThat(instance.getName()).isEqualTo("multiple-1");
assertThat(instance.getApplicationContext()).isSameAs(applicationContext);
ContainedBean<MultiplePrototypesInSpringContextTestBean> bean2 = beanContainer.getBean("multiple-1", MultiplePrototypesInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE);
assertThat(bean2).isNotNull();
MultiplePrototypesInSpringContextTestBean 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);
}
use of org.hibernate.resource.beans.container.spi.BeanContainer in project spring-framework by spring-projects.
the class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests method testCanRetrieveBeanByNameWithJpaCompliantOptions.
@Test
public void testCanRetrieveBeanByNameWithJpaCompliantOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
ContainedBean<MultiplePrototypesInSpringContextTestBean> bean = beanContainer.getBean("multiple-1", MultiplePrototypesInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE);
assertThat(bean).isNotNull();
MultiplePrototypesInSpringContextTestBean instance = bean.getBeanInstance();
assertThat(instance).isNotNull();
assertThat(instance.getName()).isEqualTo("multiple-1");
assertThat(instance.getApplicationContext()).isSameAs(applicationContext);
}
Aggregations