Search in sources :

Example 1 with DefaultJpaDialect

use of org.springframework.orm.jpa.DefaultJpaDialect in project spring-framework by spring-projects.

the class PersistenceInjectionTests method testPublicExtendedPersistenceContextSetterWithEntityManagerInfoAndSerialization.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testPublicExtendedPersistenceContextSetterWithEntityManagerInfoAndSerialization() throws Exception {
    EntityManager mockEm = mock(EntityManager.class, withSettings().serializable());
    given(mockEm.isOpen()).willReturn(true);
    EntityManagerFactoryWithInfo mockEmf = mock(EntityManagerFactoryWithInfo.class);
    given(mockEmf.getNativeEntityManagerFactory()).willReturn(mockEmf);
    given(mockEmf.getJpaDialect()).willReturn(new DefaultJpaDialect());
    given(mockEmf.getEntityManagerInterface()).willReturn((Class) EntityManager.class);
    given(mockEmf.getBeanClassLoader()).willReturn(getClass().getClassLoader());
    given(mockEmf.createEntityManager()).willReturn(mockEm);
    GenericApplicationContext gac = new GenericApplicationContext();
    gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
    gac.registerBeanDefinition("annotationProcessor", new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
    gac.registerBeanDefinition(DefaultPublicPersistenceContextSetter.class.getName(), new RootBeanDefinition(DefaultPublicPersistenceContextSetter.class));
    gac.refresh();
    DefaultPublicPersistenceContextSetter bean = (DefaultPublicPersistenceContextSetter) gac.getBean(DefaultPublicPersistenceContextSetter.class.getName());
    assertNotNull(bean.em);
    assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));
}
Also used : EntityManager(javax.persistence.EntityManager) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) DefaultJpaDialect(org.springframework.orm.jpa.DefaultJpaDialect) Test(org.junit.Test)

Aggregations

EntityManager (javax.persistence.EntityManager)1 Test (org.junit.Test)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 DefaultJpaDialect (org.springframework.orm.jpa.DefaultJpaDialect)1