-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for path resource loader URL connection
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
resource/src/test/java/io/smallrye/common/resource/PathResourceLoaderTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.smallrye.common.resource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public final class PathResourceLoaderTests { | ||
|
||
@Test | ||
public void testLoading() throws IOException { | ||
URL myClass = PathResourceLoaderTests.class.getResource("PathResourceLoaderTests.class"); | ||
assumeTrue(myClass != null); | ||
assumeTrue("file".equals(myClass.getProtocol())); | ||
String absPath = myClass.getPath(); | ||
Path testClasses = Path.of(absPath).getParent().getParent().getParent().getParent().getParent(); | ||
byte[] myClassBytes; | ||
try (InputStream is = myClass.openStream()) { | ||
assumeTrue(is != null); | ||
myClassBytes = is.readAllBytes(); | ||
} | ||
try (PathResourceLoader rl = new PathResourceLoader(testClasses)) { | ||
Resource myClassRsrc = rl.findResource("io/smallrye/common/resource/PathResourceLoaderTests.class"); | ||
assertNotNull(myClassRsrc); | ||
try (InputStream is = myClassRsrc.openStream()) { | ||
assertArrayEquals(myClassBytes, is.readAllBytes()); | ||
} | ||
URL url = myClassRsrc.url(); | ||
assertInstanceOf(ResourceURLConnection.class, url.openConnection()); | ||
} | ||
} | ||
} |