From b161b2172404f32791021d2f1ab4c50368d40319 Mon Sep 17 00:00:00 2001 From: himanshumahajan138 Date: Sat, 18 Jan 2025 17:52:40 +0530 Subject: [PATCH 1/2] Testing --- .../javalib/web/6-hello-quarkus/build.mill | 34 +++++++++++++++++++ .../resources/application.properties | 2 ++ .../src/com/example/HelloQuarkus.java | 15 ++++++++ .../src/com/example/HelloQuarkusTest.java | 16 +++++++++ 4 files changed, 67 insertions(+) create mode 100644 example/javalib/web/6-hello-quarkus/build.mill create mode 100644 example/javalib/web/6-hello-quarkus/resources/application.properties create mode 100644 example/javalib/web/6-hello-quarkus/src/com/example/HelloQuarkus.java create mode 100644 example/javalib/web/6-hello-quarkus/test/src/com/example/HelloQuarkusTest.java diff --git a/example/javalib/web/6-hello-quarkus/build.mill b/example/javalib/web/6-hello-quarkus/build.mill new file mode 100644 index 00000000000..c0a523cf302 --- /dev/null +++ b/example/javalib/web/6-hello-quarkus/build.mill @@ -0,0 +1,34 @@ +package build +import mill._, javalib._ + +object `package` extends RootModule with JavaModule { + def ivyDeps = Agg( + ivy"io.quarkus:quarkus-core:3.17.7", + ivy"io.quarkus:quarkus-resteasy:3.17.7" + ) + + object test extends JavaTests with TestModule.Junit5 { + def ivyDeps = super.ivyDeps() ++ Agg( + ivy"io.quarkus:quarkus-junit5:3.17.7", + ivy"io.rest-assured:rest-assured:5.5.0" + ) + } +} + +// This example demonstrates how to set up a simple Quarkus webserver, +// able to handle a single HTTP request at `/` and reply with a single response. + +/** Usage + +> ./mill compile quarkus:dev + +> ./mill test + +> mill runBackground + +> curl http://localhost:8050 +...Hello, Quarkus!... + +> mill clean runBackground + +*/ diff --git a/example/javalib/web/6-hello-quarkus/resources/application.properties b/example/javalib/web/6-hello-quarkus/resources/application.properties new file mode 100644 index 00000000000..fd447343e62 --- /dev/null +++ b/example/javalib/web/6-hello-quarkus/resources/application.properties @@ -0,0 +1,2 @@ +# Application configuration file +quarkus.http.port=8050 diff --git a/example/javalib/web/6-hello-quarkus/src/com/example/HelloQuarkus.java b/example/javalib/web/6-hello-quarkus/src/com/example/HelloQuarkus.java new file mode 100644 index 00000000000..4b27eddfcf8 --- /dev/null +++ b/example/javalib/web/6-hello-quarkus/src/com/example/HelloQuarkus.java @@ -0,0 +1,15 @@ +package com.example; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/") +public class HelloQuarkus { + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "Hello, Quarkus!"; + } +} diff --git a/example/javalib/web/6-hello-quarkus/test/src/com/example/HelloQuarkusTest.java b/example/javalib/web/6-hello-quarkus/test/src/com/example/HelloQuarkusTest.java new file mode 100644 index 00000000000..9091f38419b --- /dev/null +++ b/example/javalib/web/6-hello-quarkus/test/src/com/example/HelloQuarkusTest.java @@ -0,0 +1,16 @@ +package com.example; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +@QuarkusTest +public class HelloQuarkusTest { + + @Test + public void testHelloEndpoint() { + given().when().get("/").then().statusCode(200).body(is("Hello, Quarkus!")); + } +} From c710cce20f3d2c101dc2b6b58a9741c839c8ea27 Mon Sep 17 00:00:00 2001 From: himanshumahajan138 Date: Sun, 19 Jan 2025 13:08:41 +0530 Subject: [PATCH 2/2] Testing --- example/javalib/web/6-hello-quarkus/build.mill | 6 ++++-- .../web/6-hello-quarkus/src/com/example/HelloQuarkus.java | 3 ++- .../test/src/com/example/HelloQuarkusTest.java | 7 +++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/example/javalib/web/6-hello-quarkus/build.mill b/example/javalib/web/6-hello-quarkus/build.mill index c0a523cf302..2d609420f4b 100644 --- a/example/javalib/web/6-hello-quarkus/build.mill +++ b/example/javalib/web/6-hello-quarkus/build.mill @@ -4,7 +4,9 @@ import mill._, javalib._ object `package` extends RootModule with JavaModule { def ivyDeps = Agg( ivy"io.quarkus:quarkus-core:3.17.7", - ivy"io.quarkus:quarkus-resteasy:3.17.7" + ivy"io.quarkus:quarkus-resteasy:3.17.7", + ivy"io.quarkus:quarkus-arc:3.17.7", + ivy"io.quarkus:quarkus-rest:3.17.7" ) object test extends JavaTests with TestModule.Junit5 { @@ -20,7 +22,7 @@ object `package` extends RootModule with JavaModule { /** Usage -> ./mill compile quarkus:dev +> ./mill compile quarkus dev > ./mill test diff --git a/example/javalib/web/6-hello-quarkus/src/com/example/HelloQuarkus.java b/example/javalib/web/6-hello-quarkus/src/com/example/HelloQuarkus.java index 4b27eddfcf8..59127259aad 100644 --- a/example/javalib/web/6-hello-quarkus/src/com/example/HelloQuarkus.java +++ b/example/javalib/web/6-hello-quarkus/src/com/example/HelloQuarkus.java @@ -5,8 +5,9 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; -@Path("/") +@Path("/hello") public class HelloQuarkus { + @GET @Produces(MediaType.TEXT_PLAIN) public String hello() { diff --git a/example/javalib/web/6-hello-quarkus/test/src/com/example/HelloQuarkusTest.java b/example/javalib/web/6-hello-quarkus/test/src/com/example/HelloQuarkusTest.java index 9091f38419b..6c790a025c0 100644 --- a/example/javalib/web/6-hello-quarkus/test/src/com/example/HelloQuarkusTest.java +++ b/example/javalib/web/6-hello-quarkus/test/src/com/example/HelloQuarkusTest.java @@ -7,10 +7,9 @@ import org.junit.jupiter.api.Test; @QuarkusTest -public class HelloQuarkusTest { - +class HelloQuarkusTest { @Test - public void testHelloEndpoint() { - given().when().get("/").then().statusCode(200).body(is("Hello, Quarkus!")); + void testHelloEndpoint() { + given().when().get("/hello").then().statusCode(200).body(is("Hello, Quarkus!")); } }