-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'issue/KRZ-212_webjar' into 'main'
KRZ-212 Native Webjar Support See merge request reactivecore/kreuzberg!73
- Loading branch information
Showing
8 changed files
with
139 additions
and
10 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
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
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
1 change: 1 addition & 0 deletions
1
miniserver-common/src/test/resources/test_resource/sub1/Test.txt
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 @@ | ||
Hello Testcase! |
1 change: 1 addition & 0 deletions
1
miniserver-common/src/test/resources/test_resource/sub2/Hidden.txt
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 @@ | ||
Should not be served |
55 changes: 55 additions & 0 deletions
55
miniserver-common/src/test/scala/kreuzberg/miniserver/AssetCandidatePathTest.scala
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,55 @@ | ||
package kreuzberg.miniserver | ||
|
||
import kreuzberg.testcore.TestBase | ||
|
||
import java.nio.charset.StandardCharsets | ||
import java.nio.file.Files | ||
|
||
class AssetCandidatePathTest extends TestBase { | ||
|
||
"Resource" should "load resources" in { | ||
val candidatePath = AssetCandidatePath.Resource("test_resource/sub1/", "foo/") | ||
|
||
val bytes = candidatePath.locate("foo/Test.txt").value.load().readAllBytes() | ||
new String(bytes, StandardCharsets.UTF_8).trim shouldBe "Hello Testcase!" | ||
|
||
candidatePath.locate("foo/not_found") shouldBe empty | ||
candidatePath.locate("foo/../sub2/Hidden.txt") shouldBe empty | ||
|
||
val candidatePath2 = AssetCandidatePath.Resource("test_resource", "") | ||
val bytes2 = candidatePath2.locate("sub1/Test.txt") | ||
new String(bytes, StandardCharsets.UTF_8).trim shouldBe "Hello Testcase!" | ||
|
||
candidatePath2.locate("../sub1/Test.txt") shouldBe empty | ||
} | ||
|
||
"Directory" should "load files" in { | ||
val dir = Files.createTempDirectory("kreuzberg_test") | ||
Files.createDirectory(dir.resolve("sub1")) | ||
Files.createDirectory(dir.resolve("sub2")) | ||
Files.writeString(dir.resolve("sub1/test.txt"), "Hello World") | ||
Files.writeString(dir.resolve("sub2/test.txt"), "Hidden") | ||
|
||
val candidatePath = AssetCandidatePath.Directory(dir.resolve("sub1").toString, "foo/") | ||
new String( | ||
candidatePath.locate("foo/test.txt").value.load().readAllBytes(), | ||
StandardCharsets.UTF_8 | ||
) shouldBe "Hello World" | ||
candidatePath.locate("foo/unknown") shouldBe empty | ||
candidatePath.locate("test.txt") shouldBe empty | ||
|
||
candidatePath.locate("foo/../sub2/test.txt") shouldBe empty | ||
} | ||
|
||
"Webjar" should "load webjars" in { | ||
val candidatePath = AssetCandidatePath.Webjar("foo/") | ||
val found = candidatePath.locate("foo/jquery/jquery.js").value | ||
found.load().readAllBytes().size shouldBe >=(10) | ||
|
||
candidatePath.locate("foo/jquery/missing.js") shouldBe empty | ||
candidatePath.locate("jquery/jquery.js") shouldBe empty | ||
candidatePath.locate("foo/other/jquery.js") shouldBe empty | ||
candidatePath.locate("jquery") shouldBe empty | ||
candidatePath.locate("foo/jquery") shouldBe empty | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
test-core/shared/src/main/scala/kreuzberg/testcore/TestBase.scala
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