|
|
|
@ -330,8 +330,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT |
|
|
|
assertSame(mockEmf2, bean2.emf); |
|
|
|
assertSame(mockEmf2, bean2.emf); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Ignore |
|
|
|
@Ignore |
|
|
|
public void ignoreTestPersistenceUnitsFromJndi() { |
|
|
|
public void testPersistenceUnitsFromJndi() { |
|
|
|
EntityManager mockEm = mock(EntityManager.class); |
|
|
|
EntityManager mockEm = mock(EntityManager.class); |
|
|
|
given(mockEmf.createEntityManager()).willReturn(mockEm); |
|
|
|
given(mockEmf.createEntityManager()).willReturn(mockEm); |
|
|
|
|
|
|
|
|
|
|
|
@ -542,9 +543,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testFieldOfWrongTypeAnnotatedWithPersistenceUnit() { |
|
|
|
public void testFieldOfWrongTypeAnnotatedWithPersistenceUnit() { |
|
|
|
PersistenceAnnotationBeanPostProcessor babpp = new PersistenceAnnotationBeanPostProcessor(); |
|
|
|
PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
babpp.postProcessPropertyValues(null, null, new FieldOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, new FieldOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"); |
|
|
|
fail("Can't inject this field"); |
|
|
|
fail("Can't inject this field"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (IllegalStateException ex) { |
|
|
|
catch (IllegalStateException ex) { |
|
|
|
@ -554,9 +555,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSetterOfWrongTypeAnnotatedWithPersistenceUnit() { |
|
|
|
public void testSetterOfWrongTypeAnnotatedWithPersistenceUnit() { |
|
|
|
PersistenceAnnotationBeanPostProcessor babpp = new PersistenceAnnotationBeanPostProcessor(); |
|
|
|
PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
babpp.postProcessPropertyValues(null, null, new SetterOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, new SetterOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"); |
|
|
|
fail("Can't inject this setter"); |
|
|
|
fail("Can't inject this setter"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (IllegalStateException ex) { |
|
|
|
catch (IllegalStateException ex) { |
|
|
|
@ -566,9 +567,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSetterWithNoArgs() { |
|
|
|
public void testSetterWithNoArgs() { |
|
|
|
PersistenceAnnotationBeanPostProcessor babpp = new PersistenceAnnotationBeanPostProcessor(); |
|
|
|
PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
babpp.postProcessPropertyValues(null, null, new SetterWithNoArgs(), "bean"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, new SetterWithNoArgs(), "bean"); |
|
|
|
fail("Can't inject this setter"); |
|
|
|
fail("Can't inject this setter"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (IllegalStateException ex) { |
|
|
|
catch (IllegalStateException ex) { |
|
|
|
@ -576,28 +577,28 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
@Test |
|
|
|
public void ignoreTestNoPropertiesPassedIn() { |
|
|
|
public void testNoPropertiesPassedIn() { |
|
|
|
EntityManager mockEm = mock(EntityManager.class); |
|
|
|
EntityManager mockEm = mock(EntityManager.class); |
|
|
|
given(mockEmf.createEntityManager()).willReturn(mockEm); |
|
|
|
given(mockEmf.createEntityManager()).willReturn(mockEm); |
|
|
|
|
|
|
|
|
|
|
|
PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
DefaultPrivatePersistenceContextFieldExtended dppcf = new DefaultPrivatePersistenceContextFieldExtended(); |
|
|
|
DefaultPrivatePersistenceContextFieldExtended dppcf = new DefaultPrivatePersistenceContextFieldExtended(); |
|
|
|
babpp.postProcessAfterInstantiation(dppcf, "bean name does not matter"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, dppcf, "bean"); |
|
|
|
assertNotNull(dppcf.em); |
|
|
|
assertNotNull(dppcf.em); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
@Test |
|
|
|
public void ignoreTestPropertiesPassedIn() { |
|
|
|
public void testPropertiesPassedIn() { |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.put("foo", "bar"); |
|
|
|
props.put("foo", "bar"); |
|
|
|
EntityManager mockEm = mock(EntityManager.class); |
|
|
|
EntityManager mockEm = mock(EntityManager.class); |
|
|
|
given(mockEmf.createEntityManager(props)).willReturn(mockEm); |
|
|
|
given(mockEmf.createEntityManager(props)).willReturn(mockEm); |
|
|
|
|
|
|
|
|
|
|
|
PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
DefaultPrivatePersistenceContextFieldExtendedWithProps dppcf = |
|
|
|
DefaultPrivatePersistenceContextFieldExtendedWithProps dppcf = |
|
|
|
new DefaultPrivatePersistenceContextFieldExtendedWithProps(); |
|
|
|
new DefaultPrivatePersistenceContextFieldExtendedWithProps(); |
|
|
|
babpp.postProcessAfterInstantiation(dppcf, "bean name does not matter"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, dppcf, "bean"); |
|
|
|
assertNotNull(dppcf.em); |
|
|
|
assertNotNull(dppcf.em); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -610,10 +611,10 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT |
|
|
|
given(em.getDelegate()).willReturn(new Object()); |
|
|
|
given(em.getDelegate()).willReturn(new Object()); |
|
|
|
given(em.isOpen()).willReturn(true); |
|
|
|
given(em.isOpen()).willReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
DefaultPrivatePersistenceContextFieldWithProperties transactionalField = |
|
|
|
DefaultPrivatePersistenceContextFieldWithProperties transactionalField = |
|
|
|
new DefaultPrivatePersistenceContextFieldWithProperties(); |
|
|
|
new DefaultPrivatePersistenceContextFieldWithProperties(); |
|
|
|
babpp.postProcessPropertyValues(null, null, transactionalField, "bean"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, transactionalField, "bean"); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(transactionalField.em); |
|
|
|
assertNotNull(transactionalField.em); |
|
|
|
assertNotNull(transactionalField.em.getDelegate()); |
|
|
|
assertNotNull(transactionalField.em.getDelegate()); |
|
|
|
@ -635,13 +636,13 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT |
|
|
|
given(em.getDelegate()).willReturn(new Object()); |
|
|
|
given(em.getDelegate()).willReturn(new Object()); |
|
|
|
given(em.isOpen()).willReturn(true); |
|
|
|
given(em.isOpen()).willReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
DefaultPrivatePersistenceContextFieldWithProperties transactionalFieldWithProperties = |
|
|
|
DefaultPrivatePersistenceContextFieldWithProperties transactionalFieldWithProperties = |
|
|
|
new DefaultPrivatePersistenceContextFieldWithProperties(); |
|
|
|
new DefaultPrivatePersistenceContextFieldWithProperties(); |
|
|
|
DefaultPrivatePersistenceContextField transactionalField = new DefaultPrivatePersistenceContextField(); |
|
|
|
DefaultPrivatePersistenceContextField transactionalField = new DefaultPrivatePersistenceContextField(); |
|
|
|
|
|
|
|
|
|
|
|
babpp.postProcessPropertyValues(null, null, transactionalFieldWithProperties, "bean1"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, transactionalFieldWithProperties, "bean1"); |
|
|
|
babpp.postProcessPropertyValues(null, null, transactionalField, "bean2"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, transactionalField, "bean2"); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(transactionalFieldWithProperties.em); |
|
|
|
assertNotNull(transactionalFieldWithProperties.em); |
|
|
|
assertNotNull(transactionalField.em); |
|
|
|
assertNotNull(transactionalField.em); |
|
|
|
@ -668,13 +669,13 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT |
|
|
|
given(em.getDelegate()).willReturn(new Object(), 2); |
|
|
|
given(em.getDelegate()).willReturn(new Object(), 2); |
|
|
|
given(em.isOpen()).willReturn(true); |
|
|
|
given(em.isOpen()).willReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); |
|
|
|
DefaultPrivatePersistenceContextFieldWithProperties transactionalFieldWithProperties = |
|
|
|
DefaultPrivatePersistenceContextFieldWithProperties transactionalFieldWithProperties = |
|
|
|
new DefaultPrivatePersistenceContextFieldWithProperties(); |
|
|
|
new DefaultPrivatePersistenceContextFieldWithProperties(); |
|
|
|
DefaultPrivatePersistenceContextField transactionalField = new DefaultPrivatePersistenceContextField(); |
|
|
|
DefaultPrivatePersistenceContextField transactionalField = new DefaultPrivatePersistenceContextField(); |
|
|
|
|
|
|
|
|
|
|
|
babpp.postProcessPropertyValues(null, null, transactionalFieldWithProperties, "bean1"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, transactionalFieldWithProperties, "bean1"); |
|
|
|
babpp.postProcessPropertyValues(null, null, transactionalField, "bean2"); |
|
|
|
pabpp.postProcessPropertyValues(null, null, transactionalField, "bean2"); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(transactionalFieldWithProperties.em); |
|
|
|
assertNotNull(transactionalFieldWithProperties.em); |
|
|
|
assertNotNull(transactionalField.em); |
|
|
|
assertNotNull(transactionalField.em); |
|
|
|
|