|
| 1 | +package io.quarkus.webjar.locator.test; |
| 2 | + |
| 3 | +import static org.hamcrest.core.Is.is; |
| 4 | + |
| 5 | +import org.hamcrest.Matchers; |
| 6 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 7 | +import org.jboss.shrinkwrap.api.asset.StringAsset; |
| 8 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 11 | + |
| 12 | +import io.quarkus.test.QuarkusDevModeTest; |
| 13 | +import io.restassured.RestAssured; |
| 14 | + |
| 15 | +public class WebJarLocatorDevModeTest { |
| 16 | + private static final String META_INF_RESOURCES = "META-INF/resources/"; |
| 17 | + |
| 18 | + @RegisterExtension |
| 19 | + static QuarkusDevModeTest test = new QuarkusDevModeTest() |
| 20 | + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) |
| 21 | + .addClass(PostResource.class) |
| 22 | + .addAsResource(new StringAsset("<html>Hello!<html>"), META_INF_RESOURCES + "/index.html") |
| 23 | + .addAsResource(new StringAsset("Test"), META_INF_RESOURCES + "/some/path/test.txt")); |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testDevMode() { |
| 27 | + // Test Endpoint |
| 28 | + RestAssured.given().body("Stuart") |
| 29 | + .when() |
| 30 | + .post("/post") |
| 31 | + .then() |
| 32 | + .body(Matchers.equalTo("Hello: Stuart")); |
| 33 | + // Test normal files |
| 34 | + RestAssured.get("/").then() |
| 35 | + .statusCode(200) |
| 36 | + .body(is("<html>Hello!<html>")); |
| 37 | + |
| 38 | + RestAssured.get("/index.html").then() |
| 39 | + .statusCode(200) |
| 40 | + .body(is("<html>Hello!<html>")); |
| 41 | + |
| 42 | + RestAssured.get("/some/path/test.txt").then() |
| 43 | + .statusCode(200) |
| 44 | + .body(is("Test")); |
| 45 | + |
| 46 | + // Test Existing Web Jars |
| 47 | + RestAssured.get("/webjars/jquery/jquery.min.js").then() |
| 48 | + .statusCode(200); |
| 49 | + RestAssured.get("/webjars/momentjs/min/moment.min.js").then() |
| 50 | + .statusCode(200); |
| 51 | + |
| 52 | + // Test using version in url of existing Web Jar |
| 53 | + RestAssured.get("/webjars/jquery/3.4.1/jquery.min.js").then() |
| 54 | + .statusCode(200); |
| 55 | + RestAssured.get("/webjars/momentjs/2.24.0/min/moment.min.js").then() |
| 56 | + .statusCode(200); |
| 57 | + |
| 58 | + // Test non-existing Web Jar |
| 59 | + RestAssured.get("/webjars/bootstrap/js/bootstrap.min.js").then() |
| 60 | + .statusCode(404); |
| 61 | + RestAssured.get("/webjars/bootstrap/4.3.1/js/bootstrap.min.js").then() |
| 62 | + .statusCode(404); |
| 63 | + RestAssured.get("/webjars/momentjs/2.25.0/min/moment.min.js").then() |
| 64 | + .statusCode(404); |
| 65 | + |
| 66 | + // Change a source file |
| 67 | + test.modifySourceFile(PostResource.class, s -> s.replace("Hello:", "Hi:")); |
| 68 | + |
| 69 | + // Test modified endpoint |
| 70 | + RestAssured.given().body("Stuart") |
| 71 | + .when() |
| 72 | + .post("/post") |
| 73 | + .then() |
| 74 | + .body(Matchers.equalTo("Hi: Stuart")); |
| 75 | + |
| 76 | + // Test normal files |
| 77 | + RestAssured.get("/").then() |
| 78 | + .statusCode(200) |
| 79 | + .body(is("<html>Hello!<html>")); |
| 80 | + |
| 81 | + RestAssured.get("/index.html").then() |
| 82 | + .statusCode(200) |
| 83 | + .body(is("<html>Hello!<html>")); |
| 84 | + |
| 85 | + RestAssured.get("/some/path/test.txt").then() |
| 86 | + .statusCode(200) |
| 87 | + .body(is("Test")); |
| 88 | + |
| 89 | + // Test Existing Web Jars |
| 90 | + RestAssured.get("/webjars/jquery/jquery.min.js").then() |
| 91 | + .statusCode(200); |
| 92 | + RestAssured.get("/webjars/momentjs/min/moment.min.js").then() |
| 93 | + .statusCode(200); |
| 94 | + |
| 95 | + // Test using version in url of existing Web Jar |
| 96 | + RestAssured.get("/webjars/jquery/3.4.1/jquery.min.js").then() |
| 97 | + .statusCode(200); |
| 98 | + RestAssured.get("/webjars/momentjs/2.24.0/min/moment.min.js").then() |
| 99 | + .statusCode(200); |
| 100 | + |
| 101 | + // Test non-existing Web Jar |
| 102 | + RestAssured.get("/webjars/bootstrap/js/bootstrap.min.js").then() |
| 103 | + .statusCode(404); |
| 104 | + RestAssured.get("/webjars/bootstrap/4.3.1/js/bootstrap.min.js").then() |
| 105 | + .statusCode(404); |
| 106 | + RestAssured.get("/webjars/momentjs/2.25.0/min/moment.min.js").then() |
| 107 | + .statusCode(404); |
| 108 | + } |
| 109 | +} |
0 commit comments