-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
DefaultClassPathResourceLoader
handle URLs with format `jar:fi…
…le:/{JAR_PATH}!/{PREFIX}!/{RESOURCE}` gracefully (#10092)
- Loading branch information
1 parent
9e20f4f
commit 105f81b
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
core/src/test/groovy/io/micronaut/core/io/scan/DefaultClassPathResourceLoaderSpec.groovy
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,32 @@ | ||
package io.micronaut.core.io.scan | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
import spock.mock.MockFactory | ||
|
||
class DefaultClassPathResourceLoaderSpec extends Specification { | ||
|
||
ClassLoader parent = Mock() { | ||
getResource(_) >> { | ||
args -> new URL("jar:" + this.class.classLoader.getResource("test.war") + "!/WEB-INF/classes!/" + args[0]) | ||
} | ||
} | ||
|
||
@Subject | ||
DefaultClassPathResourceLoader loader = new DefaultClassPathResourceLoader(parent) | ||
|
||
def 'get file resource in war file'() { | ||
when: | ||
Optional<InputStream> input = loader.getResourceAsStream("application.yml") | ||
then: | ||
!input.empty | ||
input.get().text.contains("application configuration") | ||
} | ||
|
||
def 'no such resource in war file'() { | ||
when: | ||
Optional<InputStream> input = loader.getResourceAsStream("no-such-file.yml") | ||
then: | ||
input.empty | ||
} | ||
} |
Binary file not shown.