|
|
|
@ -43,6 +43,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition; |
|
|
|
import org.springframework.core.test.tools.CompileWithForkedClassLoader; |
|
|
|
import org.springframework.core.test.tools.CompileWithForkedClassLoader; |
|
|
|
import org.springframework.core.test.tools.Compiled; |
|
|
|
import org.springframework.core.test.tools.Compiled; |
|
|
|
import org.springframework.core.test.tools.TestCompiler; |
|
|
|
import org.springframework.core.test.tools.TestCompiler; |
|
|
|
|
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
@ -67,6 +68,20 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests { |
|
|
|
this.generationContext = new TestGenerationContext(); |
|
|
|
this.generationContext = new TestGenerationContext(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void processAheadOfTimeWhenPersistenceUnitOnFieldAndPropertyValueSet() { |
|
|
|
|
|
|
|
RegisteredBean registeredBean = registerBean(DefaultPersistenceUnitField.class); |
|
|
|
|
|
|
|
registeredBean.getMergedBeanDefinition().getPropertyValues().add("emf", "myEntityManagerFactory"); |
|
|
|
|
|
|
|
assertThat(processAheadOfTime(registeredBean)).isNotNull(); // Field not handled by property values
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void processAheadOfTimeWhenPersistenceUnitOnMethodAndPropertyValueSet() { |
|
|
|
|
|
|
|
RegisteredBean registeredBean = registerBean(DefaultPersistenceUnitMethod.class); |
|
|
|
|
|
|
|
registeredBean.getMergedBeanDefinition().getPropertyValues().add("emf", "myEntityManagerFactory"); |
|
|
|
|
|
|
|
assertThat(processAheadOfTime(registeredBean)).isNull(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void processAheadOfTimeWhenPersistenceUnitOnPublicField() { |
|
|
|
void processAheadOfTimeWhenPersistenceUnitOnPublicField() { |
|
|
|
RegisteredBean registeredBean = registerBean(DefaultPersistenceUnitField.class); |
|
|
|
RegisteredBean registeredBean = registerBean(DefaultPersistenceUnitField.class); |
|
|
|
@ -192,9 +207,7 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests { |
|
|
|
|
|
|
|
|
|
|
|
private void testCompile(RegisteredBean registeredBean, |
|
|
|
private void testCompile(RegisteredBean registeredBean, |
|
|
|
BiConsumer<BiConsumer<RegisteredBean, Object>, Compiled> result) { |
|
|
|
BiConsumer<BiConsumer<RegisteredBean, Object>, Compiled> result) { |
|
|
|
PersistenceAnnotationBeanPostProcessor postProcessor = new PersistenceAnnotationBeanPostProcessor(); |
|
|
|
BeanRegistrationAotContribution contribution = processAheadOfTime(registeredBean); |
|
|
|
BeanRegistrationAotContribution contribution = postProcessor |
|
|
|
|
|
|
|
.processAheadOfTime(registeredBean); |
|
|
|
|
|
|
|
BeanRegistrationCode beanRegistrationCode = mock(); |
|
|
|
BeanRegistrationCode beanRegistrationCode = mock(); |
|
|
|
contribution.applyTo(generationContext, beanRegistrationCode); |
|
|
|
contribution.applyTo(generationContext, beanRegistrationCode); |
|
|
|
generationContext.writeGeneratedContent(); |
|
|
|
generationContext.writeGeneratedContent(); |
|
|
|
@ -202,6 +215,12 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests { |
|
|
|
.compile(compiled -> result.accept(new Invoker(compiled), compiled)); |
|
|
|
.compile(compiled -> result.accept(new Invoker(compiled), compiled)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
private BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { |
|
|
|
|
|
|
|
PersistenceAnnotationBeanPostProcessor postProcessor = new PersistenceAnnotationBeanPostProcessor(); |
|
|
|
|
|
|
|
return postProcessor.processAheadOfTime(registeredBean); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class Invoker implements BiConsumer<RegisteredBean, Object> { |
|
|
|
static class Invoker implements BiConsumer<RegisteredBean, Object> { |
|
|
|
|
|
|
|
|
|
|
|
private Compiled compiled; |
|
|
|
private Compiled compiled; |
|
|
|
|