|
|
|
@ -41,10 +41,12 @@ import org.springframework.beans.factory.support.RegisteredBean; |
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition; |
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.data.aot.ManagedTypesRegistrationAotContribution.ManagedTypesInstanceCodeFragment; |
|
|
|
import org.springframework.data.aot.ManagedTypesRegistrationAotContribution.ManagedTypesInstanceCodeFragment; |
|
|
|
import org.springframework.data.domain.ManagedTypes; |
|
|
|
import org.springframework.data.domain.ManagedTypes; |
|
|
|
import org.springframework.javapoet.MethodSpec; |
|
|
|
import org.springframework.javapoet.MethodSpec; |
|
|
|
import org.springframework.javapoet.MethodSpec.Builder; |
|
|
|
import org.springframework.javapoet.MethodSpec.Builder; |
|
|
|
|
|
|
|
import org.springframework.mock.env.MockEnvironment; |
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -198,7 +200,8 @@ class ManagedTypesBeanRegistrationAotProcessorUnitTests { |
|
|
|
@Test // GH-2680
|
|
|
|
@Test // GH-2680
|
|
|
|
void generatesInstanceSupplierCodeFragmentToAvoidDuplicateInvocationsForEmptyManagedTypes() { |
|
|
|
void generatesInstanceSupplierCodeFragmentToAvoidDuplicateInvocationsForEmptyManagedTypes() { |
|
|
|
|
|
|
|
|
|
|
|
beanFactory.registerBeanDefinition("commons.managed-types", BeanDefinitionBuilder.rootBeanDefinition(EmptyManagedTypes.class).getBeanDefinition()); |
|
|
|
beanFactory.registerBeanDefinition("commons.managed-types", |
|
|
|
|
|
|
|
BeanDefinitionBuilder.rootBeanDefinition(EmptyManagedTypes.class).getBeanDefinition()); |
|
|
|
RegisteredBean registeredBean = RegisteredBean.of(beanFactory, "commons.managed-types"); |
|
|
|
RegisteredBean registeredBean = RegisteredBean.of(beanFactory, "commons.managed-types"); |
|
|
|
|
|
|
|
|
|
|
|
BeanRegistrationAotContribution contribution = createPostProcessor("commons") |
|
|
|
BeanRegistrationAotContribution contribution = createPostProcessor("commons") |
|
|
|
@ -206,7 +209,6 @@ class ManagedTypesBeanRegistrationAotProcessorUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
AotTestCodeContributionBuilder.withContextFor(this.getClass()).writeContentFor(contribution).compile(it -> { |
|
|
|
AotTestCodeContributionBuilder.withContextFor(this.getClass()).writeContentFor(contribution).compile(it -> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InstanceSupplier<ManagedTypes> types = ReflectionTestUtils |
|
|
|
InstanceSupplier<ManagedTypes> types = ReflectionTestUtils |
|
|
|
.invokeMethod(it.getAllCompiledClasses().iterator().next(), "instance"); |
|
|
|
.invokeMethod(it.getAllCompiledClasses().iterator().next(), "instance"); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -266,6 +268,40 @@ class ManagedTypesBeanRegistrationAotProcessorUnitTests { |
|
|
|
assertThat(fragment.canGenerateCode()).isFalse(); |
|
|
|
assertThat(fragment.canGenerateCode()).isFalse(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-3414
|
|
|
|
|
|
|
|
void usesConfiguredEnvironment() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MockEnvironment env = spy(new MockEnvironment()); |
|
|
|
|
|
|
|
ManagedTypesBeanRegistrationAotProcessor processor = createPostProcessor("commons"); |
|
|
|
|
|
|
|
processor.setEnvironment(env); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
beanFactory.registerBeanDefinition("commons.managed-types", managedTypesDefinition); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BeanRegistrationAotContribution contribution = processor |
|
|
|
|
|
|
|
.processAheadOfTime(RegisteredBean.of(beanFactory, "commons.managed-types")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contribution.applyTo(new TestGenerationContext(Object.class), null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(env).getProperty(eq("spring.aot.data.accessors.enabled"), eq(Boolean.class), eq(true)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-3414
|
|
|
|
|
|
|
|
void usesUsesEnvironmentFromBeanIfNotSet() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MockEnvironment env = spy(new MockEnvironment()); |
|
|
|
|
|
|
|
ManagedTypesBeanRegistrationAotProcessor processor = createPostProcessor("commons"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
beanFactory.registerBeanDefinition("commons.managed-types", managedTypesDefinition); |
|
|
|
|
|
|
|
beanFactory.registerBeanDefinition("environment", new RootBeanDefinition(Environment.class, () -> env)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BeanRegistrationAotContribution contribution = processor |
|
|
|
|
|
|
|
.processAheadOfTime(RegisteredBean.of(beanFactory, "commons.managed-types")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contribution.applyTo(new TestGenerationContext(Object.class), null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(env).getProperty(eq("spring.aot.data.accessors.enabled"), eq(Boolean.class), eq(true)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ManagedTypesBeanRegistrationAotProcessor createPostProcessor(String moduleIdentifier) { |
|
|
|
private ManagedTypesBeanRegistrationAotProcessor createPostProcessor(String moduleIdentifier) { |
|
|
|
ManagedTypesBeanRegistrationAotProcessor postProcessor = new ManagedTypesBeanRegistrationAotProcessor(); |
|
|
|
ManagedTypesBeanRegistrationAotProcessor postProcessor = new ManagedTypesBeanRegistrationAotProcessor(); |
|
|
|
postProcessor.setModuleIdentifier(moduleIdentifier); |
|
|
|
postProcessor.setModuleIdentifier(moduleIdentifier); |
|
|
|
|