Java 类org.springframework.orm.jpa.DefaultJpaDialect 实例源码

项目:spring4-understanding    文件:PersistenceInjectionTests.java   
@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));
}
项目:class-guard    文件:PersistenceInjectionTests.java   
@Test
@SuppressWarnings("unchecked")
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));
}