|
18 | 18 |
|
19 | 19 | import java.util.LinkedHashMap; |
20 | 20 | import java.util.Map; |
| 21 | +import java.util.Properties; |
21 | 22 |
|
22 | 23 | import org.junit.Before; |
23 | 24 | import org.junit.Rule; |
24 | 25 | import org.junit.Test; |
25 | 26 | import org.junit.rules.ExpectedException; |
26 | 27 | import org.springframework.core.env.MapPropertySource; |
| 28 | +import org.springframework.core.env.MutablePropertySources; |
| 29 | +import org.springframework.core.env.PropertiesPropertySource; |
27 | 30 | import org.springframework.core.env.StandardEnvironment; |
28 | 31 |
|
29 | 32 | import static org.hamcrest.Matchers.equalTo; |
30 | 33 | import static org.hamcrest.Matchers.nullValue; |
| 34 | +import static org.junit.Assert.assertEquals; |
31 | 35 | import static org.junit.Assert.assertThat; |
32 | 36 |
|
33 | 37 | /** |
@@ -174,4 +178,29 @@ public void subProperties() throws Exception { |
174 | 178 | assertThat(subProperties.get("a.d"), equalTo((Object) "3")); |
175 | 179 | } |
176 | 180 |
|
| 181 | + @Test |
| 182 | + public void testPropertySource() throws Exception { |
| 183 | + Properties properties; |
| 184 | + PropertiesPropertySource propertySource; |
| 185 | + String propertyPrefix = "spring.datasource."; |
| 186 | + String propertyName = "password"; |
| 187 | + String fullPropertyName = propertyPrefix + propertyName; |
| 188 | + StandardEnvironment environment = new StandardEnvironment(); |
| 189 | + MutablePropertySources sources = environment.getPropertySources(); |
| 190 | + properties = new Properties(); |
| 191 | + properties.put(fullPropertyName, "systemPassword"); |
| 192 | + propertySource = new PropertiesPropertySource("system", properties); |
| 193 | + sources.addLast(propertySource); |
| 194 | + properties = new Properties(); |
| 195 | + properties.put(fullPropertyName, "propertiesPassword"); |
| 196 | + propertySource = new PropertiesPropertySource("properties", properties); |
| 197 | + sources.addLast(propertySource); |
| 198 | + RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver( |
| 199 | + environment, propertyPrefix); |
| 200 | + String directProperty = propertyResolver.getProperty(propertyName); |
| 201 | + Map<String, Object> subProperties = propertyResolver.getSubProperties(""); |
| 202 | + String subProperty = (String) subProperties.get(propertyName); |
| 203 | + assertEquals(directProperty, subProperty); |
| 204 | + } |
| 205 | + |
177 | 206 | } |
0 commit comments