36
36
*
37
37
* @author Phillip Webb
38
38
* @author Andy Wilkinson
39
+ * @author HaiTao Zhang
39
40
*/
40
41
class DevToolsHomePropertiesPostProcessorTests {
41
42
@@ -47,7 +48,7 @@ void setup(@TempDir File tempDir) throws IOException {
47
48
}
48
49
49
50
@ Test
50
- void loadsHomeProperties () throws Exception {
51
+ void loadsPropertiesFromHomeFolderUsingProperties () throws Exception {
51
52
Properties properties = new Properties ();
52
53
properties .put ("abc" , "def" );
53
54
OutputStream out = new FileOutputStream (new File (this .home , ".spring-boot-devtools.properties" ));
@@ -59,6 +60,137 @@ void loadsHomeProperties() throws Exception {
59
60
assertThat (environment .getProperty ("abc" )).isEqualTo ("def" );
60
61
}
61
62
63
+ @ Test
64
+ void loadsPropertiesFromHomeFolderUsingYml () throws Exception {
65
+ Properties properties = new Properties ();
66
+ properties .put ("abc" , "def" );
67
+ OutputStream out = new FileOutputStream (new File (this .home , ".spring-boot-devtools.yml" ));
68
+ properties .store (out , null );
69
+ out .close ();
70
+ ConfigurableEnvironment environment = new MockEnvironment ();
71
+ MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor ();
72
+ runPostProcessor (() -> postProcessor .postProcessEnvironment (environment , null ));
73
+ assertThat (environment .getProperty ("abc" )).isEqualTo ("def" );
74
+ }
75
+
76
+ @ Test
77
+ void loadsPropertiesFromHomeFolderUsingYaml () throws Exception {
78
+ Properties properties = new Properties ();
79
+ properties .put ("abc" , "def" );
80
+ OutputStream out = new FileOutputStream (new File (this .home , ".spring-boot-devtools.yaml" ));
81
+ properties .store (out , null );
82
+ out .close ();
83
+ ConfigurableEnvironment environment = new MockEnvironment ();
84
+ MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor ();
85
+ runPostProcessor (() -> postProcessor .postProcessEnvironment (environment , null ));
86
+ assertThat (environment .getProperty ("abc" )).isEqualTo ("def" );
87
+ }
88
+
89
+ @ Test
90
+ void loadsPropertiesFromConfigFolderUsingProperties () throws Exception {
91
+ Properties properties = new Properties ();
92
+ new File (this .home + "/.config/spring-boot" ).mkdirs ();
93
+ properties .put ("abc" , "def" );
94
+ OutputStream out = new FileOutputStream (
95
+ new File (this .home + "/.config/spring-boot" , ".spring-boot-devtools.properties" ));
96
+ properties .store (out , null );
97
+ out .close ();
98
+ ConfigurableEnvironment environment = new MockEnvironment ();
99
+ MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor ();
100
+ runPostProcessor (() -> postProcessor .postProcessEnvironment (environment , null ));
101
+ assertThat (environment .getProperty ("abc" )).isEqualTo ("def" );
102
+ }
103
+
104
+ @ Test
105
+ void loadsPropertiesFromConfigFolderUsingYml () throws Exception {
106
+ Properties properties = new Properties ();
107
+ new File (this .home + "/.config/spring-boot" ).mkdirs ();
108
+ properties .put ("abc" , "def" );
109
+ OutputStream out = new FileOutputStream (
110
+ new File (this .home + "/.config/spring-boot" , ".spring-boot-devtools.yml" ));
111
+ properties .store (out , null );
112
+ out .close ();
113
+ ConfigurableEnvironment environment = new MockEnvironment ();
114
+ MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor ();
115
+ runPostProcessor (() -> postProcessor .postProcessEnvironment (environment , null ));
116
+ assertThat (environment .getProperty ("abc" )).isEqualTo ("def" );
117
+ }
118
+
119
+ @ Test
120
+ void loadsPropertiesFromConfigFolderUsingYaml () throws Exception {
121
+ Properties properties = new Properties ();
122
+ new File (this .home + "/.config/spring-boot" ).mkdirs ();
123
+ properties .put ("abc" , "def" );
124
+ OutputStream out = new FileOutputStream (
125
+ new File (this .home + "/.config/spring-boot" , ".spring-boot-devtools.yaml" ));
126
+ properties .store (out , null );
127
+ out .close ();
128
+ ConfigurableEnvironment environment = new MockEnvironment ();
129
+ MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor ();
130
+ runPostProcessor (() -> postProcessor .postProcessEnvironment (environment , null ));
131
+ assertThat (environment .getProperty ("abc" )).isEqualTo ("def" );
132
+ }
133
+
134
+ @ Test
135
+ void loadFromConfigFolderWithPropertiesTakingPrecedence () throws Exception {
136
+ Properties properties = new Properties ();
137
+ properties .put ("abc" , "def" );
138
+ new File (this .home + "/.config/spring-boot" ).mkdirs ();
139
+ OutputStream out = new FileOutputStream (
140
+ new File (this .home + "/.config/spring-boot/" , ".spring-boot-devtools.yaml" ));
141
+ properties .store (out , null );
142
+ out .close ();
143
+ Properties properties2 = new Properties ();
144
+ properties2 .put ("abc" , "jkl" );
145
+ OutputStream out2 = new FileOutputStream (
146
+ new File (this .home + "/.config/spring-boot/" , ".spring-boot-devtools.properties" ));
147
+ properties2 .store (out2 , null );
148
+ out2 .close ();
149
+ ConfigurableEnvironment environment = new MockEnvironment ();
150
+ MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor ();
151
+ runPostProcessor (() -> postProcessor .postProcessEnvironment (environment , null ));
152
+ assertThat (environment .getProperty ("abc" )).isEqualTo ("jkl" );
153
+ }
154
+
155
+ @ Test
156
+ void loadFromHomeFolderWithPropertiesTakingPrecedence () throws Exception {
157
+ Properties properties = new Properties ();
158
+ properties .put ("abc" , "def" );
159
+ new File (this .home + "/.config/spring-boot" ).mkdirs ();
160
+ OutputStream out = new FileOutputStream (new File (this .home , ".spring-boot-devtools.yaml" ));
161
+ properties .store (out , null );
162
+ out .close ();
163
+ Properties properties2 = new Properties ();
164
+ properties2 .put ("abc" , "jkl" );
165
+ OutputStream out2 = new FileOutputStream (new File (this .home , ".spring-boot-devtools.properties" ));
166
+ properties2 .store (out2 , null );
167
+ out2 .close ();
168
+ ConfigurableEnvironment environment = new MockEnvironment ();
169
+ MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor ();
170
+ runPostProcessor (() -> postProcessor .postProcessEnvironment (environment , null ));
171
+ assertThat (environment .getProperty ("abc" )).isEqualTo ("jkl" );
172
+ }
173
+
174
+ @ Test
175
+ void loadFromConfigFolderTakesPrecedenceOverHomeFolder () throws Exception {
176
+ Properties properties = new Properties ();
177
+ properties .put ("abc" , "def" );
178
+ new File (this .home + "/.config/spring-boot" ).mkdirs ();
179
+ OutputStream out = new FileOutputStream (new File (this .home , ".spring-boot-devtools.properties" ));
180
+ properties .store (out , null );
181
+ out .close ();
182
+ Properties properties2 = new Properties ();
183
+ properties2 .put ("abc" , "jkl" );
184
+ OutputStream out2 = new FileOutputStream (
185
+ new File (this .home + "/.config/spring-boot/" , ".spring-boot-devtools.properties" ));
186
+ properties2 .store (out2 , null );
187
+ out2 .close ();
188
+ ConfigurableEnvironment environment = new MockEnvironment ();
189
+ MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor ();
190
+ runPostProcessor (() -> postProcessor .postProcessEnvironment (environment , null ));
191
+ assertThat (environment .getProperty ("abc" )).isEqualTo ("jkl" );
192
+ }
193
+
62
194
@ Test
63
195
void ignoresMissingHomeProperties () throws Exception {
64
196
ConfigurableEnvironment environment = new MockEnvironment ();
0 commit comments