44
44
import java .util .zip .ZipEntry ;
45
45
46
46
import org .apache .commons .logging .LogFactory ;
47
+ import org .junit .jupiter .api .AfterAll ;
48
+ import org .junit .jupiter .api .BeforeAll ;
47
49
import org .junit .jupiter .api .Nested ;
48
50
import org .junit .jupiter .api .Test ;
49
51
import org .junit .jupiter .api .io .TempDir ;
@@ -298,8 +300,8 @@ void classpathStarWithPatternInJar() {
298
300
@ Test
299
301
void rootPatternRetrievalInJarFiles () throws IOException {
300
302
assertThat (resolver .getResources ("classpath*:aspectj*.dtd" )).extracting (Resource ::getFilename )
301
- .as ("Could not find aspectj_1_5_0.dtd in the root of the aspectjweaver jar" )
302
- .containsExactly ("aspectj_1_5_0.dtd" );
303
+ .as ("Could not find aspectj_1_5_0.dtd in the root of the aspectjweaver jar" )
304
+ .containsExactly ("aspectj_1_5_0.dtd" );
303
305
}
304
306
}
305
307
@@ -310,6 +312,16 @@ class ClassPathManifestEntries {
310
312
@ TempDir
311
313
Path temp ;
312
314
315
+ @ BeforeAll
316
+ static void suppressJarCaches () {
317
+ URLConnection .setDefaultUseCaches ("jar" , false );
318
+ }
319
+
320
+ @ AfterAll
321
+ static void restoreJarCaches () {
322
+ URLConnection .setDefaultUseCaches ("jar" , true );
323
+ }
324
+
313
325
@ Test
314
326
void javaDashJarFindsClassPathManifestEntries () throws Exception {
315
327
Path lib = this .temp .resolve ("lib" );
@@ -333,13 +345,22 @@ private void writeAssetJar(Path path) throws Exception {
333
345
StreamUtils .copy ("test" , StandardCharsets .UTF_8 , jar );
334
346
jar .closeEntry ();
335
347
}
348
+
336
349
assertThat (new FileSystemResource (path ).exists ()).isTrue ();
337
350
assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isTrue ();
338
351
assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/file.txt" ).exists ()).isTrue ();
339
352
assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/none.txt" ).exists ()).isFalse ();
340
353
assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + "X" + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isFalse ();
341
354
assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + "X" + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/file.txt" ).exists ()).isFalse ();
342
355
assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + "X" + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/none.txt" ).exists ()).isFalse ();
356
+
357
+ Resource resource = new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/file.txt" );
358
+ try (InputStream is = resource .getInputStream ()) {
359
+ assertThat (resource .exists ()).isTrue ();
360
+ assertThat (resource .createRelative ("file.txt" ).exists ()).isTrue ();
361
+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isTrue ();
362
+ is .readAllBytes ();
363
+ }
343
364
}
344
365
345
366
private void writeApplicationJar (Path path ) throws Exception {
0 commit comments