@@ -159,4 +159,153 @@ void testAppInfoWithComplexActions() throws IOException {
159
159
System .setProperty ("user.dir" , originalDir );
160
160
}
161
161
}
162
+
163
+ @ Test
164
+ void testReadAppInfoWithRepositories () throws IOException {
165
+ // Create a test app.yml file with repositories
166
+ Path appYmlPath = tempDir .resolve ("app.yml" );
167
+ String yamlContent =
168
+ "dependencies:\n "
169
+ + " com.example:test-lib: \" 1.0.0\" \n "
170
+ + "\n "
171
+ + "repositories:\n "
172
+ + " central: \" https://repo1.maven.org/maven2\" \n "
173
+ + " jcenter: \" https://jcenter.bintray.com\" \n "
174
+ + " custom: \" https://my.custom.repo/maven2\" \n " ;
175
+ Files .writeString (appYmlPath , yamlContent );
176
+
177
+ String originalDir = System .getProperty ("user.dir" );
178
+ System .setProperty ("user.dir" , tempDir .toString ());
179
+
180
+ try {
181
+ AppInfo appInfo = AppInfo .read ();
182
+
183
+ // Test repository retrieval
184
+ assertThat (appInfo .repositories ).hasSize (3 );
185
+ assertThat (appInfo .repositories )
186
+ .containsEntry ("central" , "https://repo1.maven.org/maven2" )
187
+ .containsEntry ("jcenter" , "https://jcenter.bintray.com" )
188
+ .containsEntry ("custom" , "https://my.custom.repo/maven2" );
189
+
190
+ // Test dependencies are still parsed correctly
191
+ assertThat (appInfo .dependencies ).hasSize (1 );
192
+ assertThat (appInfo .dependencies ).containsEntry ("com.example:test-lib" , "1.0.0" );
193
+ } finally {
194
+ System .setProperty ("user.dir" , originalDir );
195
+ }
196
+ }
197
+
198
+ @ Test
199
+ void testReadAppInfoWithoutRepositories () throws IOException {
200
+ // Create a test app.yml file without repositories
201
+ Path appYmlPath = tempDir .resolve ("app.yml" );
202
+ String yamlContent = "dependencies:\n " + " com.example:test-lib: \" 1.0.0\" \n " ;
203
+ Files .writeString (appYmlPath , yamlContent );
204
+
205
+ String originalDir = System .getProperty ("user.dir" );
206
+ System .setProperty ("user.dir" , tempDir .toString ());
207
+
208
+ try {
209
+ AppInfo appInfo = AppInfo .read ();
210
+
211
+ // Test no repositories
212
+ assertThat (appInfo .repositories ).isEmpty ();
213
+
214
+ // Test dependencies are still parsed correctly
215
+ assertThat (appInfo .dependencies ).hasSize (1 );
216
+ } finally {
217
+ System .setProperty ("user.dir" , originalDir );
218
+ }
219
+ }
220
+
221
+ @ Test
222
+ void testWriteAppInfoWithRepositories () throws IOException {
223
+ AppInfo appInfo = new AppInfo ();
224
+ appInfo .dependencies .put ("com.example:test-lib" , "1.0.0" );
225
+ appInfo .repositories .put ("central" , "https://repo1.maven.org/maven2" );
226
+ appInfo .repositories .put ("custom" , "https://my.custom.repo/maven2" );
227
+
228
+ String originalDir = System .getProperty ("user.dir" );
229
+ System .setProperty ("user.dir" , tempDir .toString ());
230
+
231
+ try {
232
+ AppInfo .write (appInfo );
233
+
234
+ // Verify the file was written
235
+ Path appYmlPath = tempDir .resolve ("app.yml" );
236
+ assertThat (appYmlPath ).exists ();
237
+
238
+ // Read it back and verify
239
+ AppInfo readBack = AppInfo .read ();
240
+ assertThat (readBack .repositories ).hasSize (2 );
241
+ assertThat (readBack .repositories )
242
+ .containsEntry ("central" , "https://repo1.maven.org/maven2" )
243
+ .containsEntry ("custom" , "https://my.custom.repo/maven2" );
244
+ assertThat (readBack .dependencies ).hasSize (1 );
245
+ } finally {
246
+ System .setProperty ("user.dir" , originalDir );
247
+ }
248
+ }
249
+
250
+ @ Test
251
+ void testWriteAppInfoWithoutRepositories () throws IOException {
252
+ AppInfo appInfo = new AppInfo ();
253
+ appInfo .dependencies .put ("com.example:test-lib" , "1.0.0" );
254
+ // No repositories added
255
+
256
+ String originalDir = System .getProperty ("user.dir" );
257
+ System .setProperty ("user.dir" , tempDir .toString ());
258
+
259
+ try {
260
+ AppInfo .write (appInfo );
261
+
262
+ // Read it back and verify repositories section is not present
263
+ AppInfo readBack = AppInfo .read ();
264
+ assertThat (readBack .repositories ).isEmpty ();
265
+ assertThat (readBack .dependencies ).hasSize (1 );
266
+
267
+ // Also verify the YAML content doesn't contain repositories section
268
+ String content = Files .readString (tempDir .resolve ("app.yml" ));
269
+ assertThat (content ).doesNotContain ("repositories:" );
270
+ } finally {
271
+ System .setProperty ("user.dir" , originalDir );
272
+ }
273
+ }
274
+
275
+ @ Test
276
+ void testAppInfoWithComplexRepositoriesAndActions () throws IOException {
277
+ Path appYmlPath = tempDir .resolve ("app.yml" );
278
+ String yamlContent =
279
+ "dependencies:\n "
280
+ + " com.example:test-lib: \" 1.0.0\" \n "
281
+ + "\n "
282
+ + "repositories:\n "
283
+ + " central: \" https://repo1.maven.org/maven2\" \n "
284
+ + " sonatype-snapshots: \" https://oss.sonatype.org/content/repositories/snapshots\" \n "
285
+ + "\n "
286
+ + "actions:\n "
287
+ + " build: \" javac -cp {{deps}} *.java\" \n " ;
288
+ Files .writeString (appYmlPath , yamlContent );
289
+
290
+ String originalDir = System .getProperty ("user.dir" );
291
+ System .setProperty ("user.dir" , tempDir .toString ());
292
+
293
+ try {
294
+ AppInfo appInfo = AppInfo .read ();
295
+
296
+ // Test all sections are parsed correctly
297
+ assertThat (appInfo .dependencies ).hasSize (1 );
298
+ assertThat (appInfo .repositories ).hasSize (2 );
299
+ assertThat (appInfo .getActionNames ()).hasSize (1 );
300
+
301
+ assertThat (appInfo .repositories )
302
+ .containsEntry ("central" , "https://repo1.maven.org/maven2" )
303
+ .containsEntry (
304
+ "sonatype-snapshots" ,
305
+ "https://oss.sonatype.org/content/repositories/snapshots" );
306
+ assertThat (appInfo .getAction ("build" )).isEqualTo ("javac -cp {{deps}} *.java" );
307
+ } finally {
308
+ System .setProperty ("user.dir" , originalDir );
309
+ }
310
+ }
162
311
}
0 commit comments