|
18 | 18 |
|
19 | 19 | import java.time.temporal.ChronoUnit;
|
20 | 20 | import java.util.ArrayList;
|
| 21 | +import java.util.Collections; |
21 | 22 | import java.util.List;
|
22 | 23 | import java.util.Map;
|
23 | 24 | import java.util.Set;
|
|
33 | 34 | import org.reactivestreams.Publisher;
|
34 | 35 |
|
35 | 36 | import org.springframework.aot.generate.GeneratedClass;
|
| 37 | +import org.springframework.aot.generate.ValueCodeGenerator.Delegate; |
36 | 38 | import org.springframework.aot.hint.MemberCategory;
|
37 | 39 | import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
38 | 40 | import org.springframework.aot.test.generate.TestGenerationContext;
|
|
49 | 51 | import org.springframework.beans.factory.support.ManagedMap;
|
50 | 52 | import org.springframework.beans.factory.support.ManagedSet;
|
51 | 53 | import org.springframework.beans.factory.support.RootBeanDefinition;
|
| 54 | +import org.springframework.beans.testfixture.beans.factory.aot.CustomPropertyValue; |
52 | 55 | import org.springframework.beans.testfixture.beans.factory.aot.DeferredTypeBuilder;
|
53 | 56 | import org.springframework.core.test.tools.Compiled;
|
54 | 57 | import org.springframework.core.test.tools.TestCompiler;
|
@@ -364,6 +367,21 @@ void propertyValuesWhenValuesOnFactoryBeanClass() {
|
364 | 367 | assertHasDeclaredFieldsHint(PropertyValuesFactoryBean.class);
|
365 | 368 | }
|
366 | 369 |
|
| 370 | + @Test |
| 371 | + void propertyValuesWhenCustomValuesUsingDelegate() { |
| 372 | + this.beanDefinition.setTargetType(PropertyValuesBean.class); |
| 373 | + this.beanDefinition.getPropertyValues().add("test", new CustomPropertyValue("test")); |
| 374 | + this.beanDefinition.getPropertyValues().add("spring", new CustomPropertyValue("framework")); |
| 375 | + compile(value -> true, List.of(new CustomPropertyValue.ValueCodeGeneratorDelegate()), (actual, compiled) -> { |
| 376 | + assertThat(actual.getPropertyValues().get("test")).isInstanceOfSatisfying(CustomPropertyValue.class, |
| 377 | + customPropertyValue -> assertThat(customPropertyValue.value()).isEqualTo("test")); |
| 378 | + assertThat(actual.getPropertyValues().get("spring")).isInstanceOfSatisfying(CustomPropertyValue.class, |
| 379 | + customPropertyValue -> assertThat(customPropertyValue.value()).isEqualTo("framework")); |
| 380 | + }); |
| 381 | + assertHasMethodInvokeHints(PropertyValuesBean.class, "setTest", "setSpring"); |
| 382 | + assertHasDeclaredFieldsHint(PropertyValuesBean.class); |
| 383 | + } |
| 384 | + |
367 | 385 | @Test
|
368 | 386 | void attributesWhenAllFiltered() {
|
369 | 387 | this.beanDefinition.setAttribute("a", "A");
|
@@ -548,12 +566,18 @@ private void compile(BiConsumer<RootBeanDefinition, Compiled> result) {
|
548 | 566 | compile(attribute -> true, result);
|
549 | 567 | }
|
550 | 568 |
|
551 |
| - private void compile(Predicate<String> attributeFilter, BiConsumer<RootBeanDefinition, Compiled> result) { |
| 569 | + private void compile(Predicate<String> attributeFilter, |
| 570 | + BiConsumer<RootBeanDefinition, Compiled> result) { |
| 571 | + compile(attributeFilter, Collections.emptyList(), result); |
| 572 | + } |
| 573 | + |
| 574 | + private void compile(Predicate<String> attributeFilter, List<Delegate> additionalDelegates, |
| 575 | + BiConsumer<RootBeanDefinition, Compiled> result) { |
552 | 576 | DeferredTypeBuilder typeBuilder = new DeferredTypeBuilder();
|
553 | 577 | GeneratedClass generatedClass = this.generationContext.getGeneratedClasses().addForFeature("TestCode", typeBuilder);
|
554 | 578 | BeanDefinitionPropertiesCodeGenerator codeGenerator = new BeanDefinitionPropertiesCodeGenerator(
|
555 | 579 | this.generationContext.getRuntimeHints(), attributeFilter,
|
556 |
| - generatedClass.getMethods(), (name, value) -> null); |
| 580 | + generatedClass.getMethods(), additionalDelegates, (name, value) -> null); |
557 | 581 | CodeBlock generatedCode = codeGenerator.generateCode(this.beanDefinition);
|
558 | 582 | typeBuilder.set(type -> {
|
559 | 583 | type.addModifiers(Modifier.PUBLIC);
|
|
0 commit comments