|
16 | 16 |
|
17 | 17 | package org.springframework.boot.bind; |
18 | 18 |
|
| 19 | +import static org.hamcrest.Matchers.equalTo; |
| 20 | +import static org.hamcrest.Matchers.nullValue; |
| 21 | +import static org.junit.Assert.assertEquals; |
| 22 | +import static org.junit.Assert.assertThat; |
| 23 | + |
19 | 24 | import java.util.LinkedHashMap; |
20 | 25 | import java.util.Map; |
| 26 | +import java.util.Properties; |
21 | 27 |
|
22 | 28 | import org.junit.Before; |
23 | 29 | import org.junit.Rule; |
24 | 30 | import org.junit.Test; |
25 | 31 | import org.junit.rules.ExpectedException; |
26 | 32 | import org.springframework.core.env.MapPropertySource; |
| 33 | +import org.springframework.core.env.MutablePropertySources; |
| 34 | +import org.springframework.core.env.PropertiesPropertySource; |
27 | 35 | import org.springframework.core.env.StandardEnvironment; |
28 | 36 |
|
29 | | -import static org.hamcrest.Matchers.equalTo; |
30 | | -import static org.hamcrest.Matchers.nullValue; |
31 | | -import static org.junit.Assert.assertThat; |
32 | | - |
33 | 37 | /** |
34 | 38 | * Tests for {@link RelaxedPropertyResolver}. |
35 | 39 | * |
@@ -173,4 +177,30 @@ public void subProperties() throws Exception { |
173 | 177 | assertThat(subProperties.get("a.c"), equalTo((Object) "2")); |
174 | 178 | assertThat(subProperties.get("a.d"), equalTo((Object) "3")); |
175 | 179 | } |
| 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 | + |
176 | 206 | } |
0 commit comments