Introduce EntityManager initialization callbacks
JpaVendorAdapter.postProcessEntityManager and EntityManagerFactoryInfo.createNativeEntityManager SPI, plus convenient setEntityManagerInitializer configuration options. Closes gh-25125
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -105,7 +105,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublicExtendedPersistenceContextSetter() throws Exception {
|
||||
public void testPublicExtendedPersistenceContextSetter() {
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
given(mockEmf.createEntityManager()).willReturn(mockEm);
|
||||
|
||||
@@ -123,7 +123,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublicSpecificExtendedPersistenceContextSetter() throws Exception {
|
||||
public void testPublicSpecificExtendedPersistenceContextSetter() {
|
||||
EntityManagerFactory mockEmf2 = mock(EntityManagerFactory.class);
|
||||
EntityManager mockEm2 = mock(EntityManager.class);
|
||||
given(mockEmf2.createEntityManager()).willReturn(mockEm2);
|
||||
@@ -194,16 +194,15 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@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.getEntityManagerInterface()).willReturn((Class) EntityManager.class);
|
||||
given(mockEmf.getBeanClassLoader()).willReturn(getClass().getClassLoader());
|
||||
given(mockEmf.createEntityManager()).willReturn(mockEm);
|
||||
given(mockEmf.createNativeEntityManager(null)).willReturn(mockEm);
|
||||
|
||||
GenericApplicationContext gac = new GenericApplicationContext();
|
||||
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
|
||||
|
||||
Reference in New Issue
Block a user