16
16
17
17
package org .springframework .boot .test ;
18
18
19
- import java .io .IOException ;
20
- import java .io .StringReader ;
21
19
import java .lang .annotation .Annotation ;
22
20
import java .util .ArrayList ;
23
21
import java .util .Arrays ;
26
24
import java .util .LinkedHashSet ;
27
25
import java .util .List ;
28
26
import java .util .Map ;
29
- import java .util .Properties ;
30
27
import java .util .Set ;
31
28
32
29
import org .springframework .beans .BeanUtils ;
75
72
*/
76
73
public class SpringApplicationContextLoader extends AbstractContextLoader {
77
74
78
- private static final String LINE_SEPARATOR = System .getProperty ("line.separator" );
79
-
80
75
@ Override
81
76
public ApplicationContext loadContext (final MergedContextConfiguration config )
82
77
throws Exception {
@@ -146,8 +141,8 @@ protected Map<String, Object> getEnvironmentProperties(
146
141
Map <String , Object > properties = new LinkedHashMap <String , Object >();
147
142
// JMX bean names will clash if the same bean is used in multiple contexts
148
143
disableJmx (properties );
149
- properties .putAll (
150
- extractEnvironmentProperties (config .getPropertySourceProperties ()));
144
+ properties .putAll (TestPropertySourceUtils
145
+ . convertInlinedPropertiesToMap (config .getPropertySourceProperties ()));
151
146
if (!TestAnnotations .isIntegrationTest (config )) {
152
147
properties .putAll (getDefaultEnvironmentProperties ());
153
148
}
@@ -158,31 +153,6 @@ private void disableJmx(Map<String, Object> properties) {
158
153
properties .put ("spring.jmx.enabled" , "false" );
159
154
}
160
155
161
- final Map <String , Object > extractEnvironmentProperties (String [] values ) {
162
- // Instead of parsing the keys ourselves, we rely on standard handling
163
- if (values == null ) {
164
- return Collections .emptyMap ();
165
- }
166
- String content = StringUtils .arrayToDelimitedString (values , LINE_SEPARATOR );
167
- Properties properties = new Properties ();
168
- try {
169
- properties .load (new StringReader (content ));
170
- return asMap (properties );
171
- }
172
- catch (IOException ex ) {
173
- throw new IllegalStateException (
174
- "Unexpected could not load properties from '" + content + "'" , ex );
175
- }
176
- }
177
-
178
- private Map <String , Object > asMap (Properties properties ) {
179
- Map <String , Object > map = new LinkedHashMap <String , Object >();
180
- for (String name : properties .stringPropertyNames ()) {
181
- map .put (name , properties .getProperty (name ));
182
- }
183
- return map ;
184
- }
185
-
186
156
private Map <String , String > getDefaultEnvironmentProperties () {
187
157
return Collections .singletonMap ("server.port" , "-1" );
188
158
}
0 commit comments