|
25 | 25 |
|
26 | 26 | import org.junit.jupiter.api.AfterAll;
|
27 | 27 | import org.junit.jupiter.api.BeforeEach;
|
| 28 | +import org.junit.jupiter.api.Disabled; |
28 | 29 | import org.junit.jupiter.api.Nested;
|
29 | 30 | import org.junit.jupiter.api.Test;
|
30 | 31 | import org.junit.jupiter.params.ParameterizedTest;
|
|
41 | 42 | import org.springframework.context.annotation.Configuration;
|
42 | 43 | import org.springframework.context.annotation.Scope;
|
43 | 44 | import org.springframework.core.SpringProperties;
|
| 45 | +import org.springframework.core.convert.ConversionService; |
| 46 | +import org.springframework.core.convert.converter.Converter; |
44 | 47 | import org.springframework.core.convert.support.DefaultConversionService;
|
45 | 48 | import org.springframework.core.env.AbstractPropertyResolver;
|
46 | 49 | import org.springframework.core.env.EnumerablePropertySource;
|
@@ -90,6 +93,39 @@ void replacementFromEnvironmentProperties() {
|
90 | 93 | assertThat(ppc.getAppliedPropertySources()).isNotNull();
|
91 | 94 | }
|
92 | 95 |
|
| 96 | + /** |
| 97 | + * Ensure that a {@link Converter} registered in the {@link ConversionService} |
| 98 | + * used by the {@code Environment} is applied during placeholder resolution |
| 99 | + * against a {@link PropertySource} registered in the {@code Environment}. |
| 100 | + */ |
| 101 | + @Disabled("Disabled until gh-34936 is resolved") |
| 102 | + @Test // gh-34936 |
| 103 | + void replacementFromEnvironmentPropertiesWithConversion() { |
| 104 | + DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
| 105 | + bf.registerBeanDefinition("testBean", |
| 106 | + genericBeanDefinition(TestBean.class) |
| 107 | + .addPropertyValue("name", "${my.name}") |
| 108 | + .getBeanDefinition()); |
| 109 | + |
| 110 | + record Point(int x, int y) { |
| 111 | + } |
| 112 | + |
| 113 | + Converter<Point, String> pointToStringConverter = |
| 114 | + point -> "(%d,%d)".formatted(point.x, point.y); |
| 115 | + |
| 116 | + DefaultConversionService conversionService = new DefaultConversionService(); |
| 117 | + conversionService.addConverter(Point.class, String.class, pointToStringConverter); |
| 118 | + |
| 119 | + MockEnvironment env = new MockEnvironment(); |
| 120 | + env.setConversionService(conversionService); |
| 121 | + env.setProperty("my.name", new Point(4,5)); |
| 122 | + |
| 123 | + PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer(); |
| 124 | + ppc.setEnvironment(env); |
| 125 | + ppc.postProcessBeanFactory(bf); |
| 126 | + assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("(4,5)"); |
| 127 | + } |
| 128 | + |
93 | 129 | /**
|
94 | 130 | * Ensure that a {@link PropertySource} added to the {@code Environment} after context
|
95 | 131 | * refresh (i.e., after {@link PropertySourcesPlaceholderConfigurer#postProcessBeanFactory()}
|
|
0 commit comments