diff --git a/pom.xml b/pom.xml index 3231a2c9dc..f876ed0493 100644 --- a/pom.xml +++ b/pom.xml @@ -959,6 +959,16 @@ + + org.apache.maven + maven-plugin-api + + + range + [4.0.0-alpha-1,) + + + org.apache.maven.plugins diff --git a/test/coreprofile/pom.xml b/test/coreprofile/pom.xml index 0dbdace261..a985c1ae3e 100644 --- a/test/coreprofile/pom.xml +++ b/test/coreprofile/pom.xml @@ -34,5 +34,6 @@ integration json no_servlet_class + rest diff --git a/test/coreprofile/rest/pom.xml b/test/coreprofile/rest/pom.xml new file mode 100644 index 0000000000..e269b78502 --- /dev/null +++ b/test/coreprofile/rest/pom.xml @@ -0,0 +1,115 @@ + + + + 4.0.0 + + cloud.piranha.test.coreprofile + project + 25.1.0-SNAPSHOT + + piranha-test-coreprofile-rest + war + Piranha - Test - Core Profile - REST + + + ${project.version} + UTF-8 + + + + + jakarta.ws.rs + jakarta.ws.rs-api + provided + + + + org.junit.jupiter + junit-jupiter-api + test + + + + rest + + + cloud.piranha.maven + piranha-maven-plugin + ${piranha.version} + + + pre-integration-test + pre-integration-test + + start + + + + post-integration-test + post-integration-test + + stop + + + + + /rest + ${httpPort} + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + + integration-test + verify + + + + + 1 + + ${httpPort} + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + org.codehaus.mojo + build-helper-maven-plugin + + + reserve-network-port + + reserve-network-port + + package + + + httpPort + + + + + + + + diff --git a/test/coreprofile/rest/src/main/java/cloud/piranha/test/coreprofile/rest/RestApplication.java b/test/coreprofile/rest/src/main/java/cloud/piranha/test/coreprofile/rest/RestApplication.java new file mode 100644 index 0000000000..ddcf80409d --- /dev/null +++ b/test/coreprofile/rest/src/main/java/cloud/piranha/test/coreprofile/rest/RestApplication.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package cloud.piranha.test.coreprofile.rest; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +/** + * A REST application. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +@ApplicationPath("") +public class RestApplication extends Application { +} diff --git a/test/embedded/jersey/src/main/java/jersey/HelloResource.java b/test/coreprofile/rest/src/main/java/cloud/piranha/test/coreprofile/rest/RestBean.java similarity index 84% rename from test/embedded/jersey/src/main/java/jersey/HelloResource.java rename to test/coreprofile/rest/src/main/java/cloud/piranha/test/coreprofile/rest/RestBean.java index ec1e7dfcfb..43ac832786 100644 --- a/test/embedded/jersey/src/main/java/jersey/HelloResource.java +++ b/test/coreprofile/rest/src/main/java/cloud/piranha/test/coreprofile/rest/RestBean.java @@ -25,29 +25,30 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package jersey; +package cloud.piranha.test.coreprofile.rest; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; +import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN; /** - * A Hello resource. + * A REST bean. * * @author Manfred Riem (mriem@manorrock.com) */ -@Path("/hello") -public class HelloResource { +@Path("") +public class RestBean { /** - * GET request + * Invoke the '/hellorest' endpoint. * - * @return "Hello" + * @return "Hello REST" */ @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "Hello"; + @Produces(TEXT_PLAIN) + @Path("/hellorest") + public String helloRest() { + return "Hello REST"; } } diff --git a/test/coreprofile/rest/src/main/webapp/WEB-INF/web.xml b/test/coreprofile/rest/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..310acde56a --- /dev/null +++ b/test/coreprofile/rest/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,10 @@ + + + + + 30 + + diff --git a/test/embedded/jersey/src/test/java/jersey/JerseyTest.java b/test/coreprofile/rest/src/test/java/cloud/piranha/test/coreprofile/rest/RestIT.java similarity index 58% rename from test/embedded/jersey/src/test/java/jersey/JerseyTest.java rename to test/coreprofile/rest/src/test/java/cloud/piranha/test/coreprofile/rest/RestIT.java index 6d02f1567d..670078dbcd 100644 --- a/test/embedded/jersey/src/test/java/jersey/JerseyTest.java +++ b/test/coreprofile/rest/src/test/java/cloud/piranha/test/coreprofile/rest/RestIT.java @@ -25,45 +25,27 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package jersey; +package cloud.piranha.test.coreprofile.rest; -import cloud.piranha.embedded.EmbeddedPiranha; -import cloud.piranha.embedded.EmbeddedPiranhaBuilder; -import cloud.piranha.embedded.EmbeddedRequest; -import cloud.piranha.embedded.EmbeddedRequestBuilder; -import cloud.piranha.embedded.EmbeddedResponse; -import cloud.piranha.extension.webxml.WebXmlExtension; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; -/** - * The JUnit tests for the HelloResource class. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -class JerseyTest { - - /** - * Test /rest/hello. - * - * @throws Exception when a serious error occurs. - */ +class RestIT { + + private String httpPort = System.getProperty("httpPort"); + @Test - void testHello() throws Exception { - EmbeddedPiranha piranha = new EmbeddedPiranhaBuilder() - .directoryResource("src/main/webapp") - .extension(WebXmlExtension.class) - .build() - .start(); - EmbeddedRequest request = new EmbeddedRequestBuilder() - .contextPath("") - .servletPath("/rest") - .pathInfo("/hello") + void testHelloRest() throws Exception { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest + .newBuilder(new URI("http://localhost:" + httpPort + "/rest/hellorest")) .build(); - EmbeddedResponse response = new EmbeddedResponse(); - piranha.service(request, response); - assertEquals(200, response.getStatus()); - assertTrue(response.getResponseAsString().contains("Hello")); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + assertEquals("Hello REST", response.body()); } } diff --git a/test/embedded/jersey/pom.xml b/test/embedded/jersey/pom.xml deleted file mode 100644 index 174435b685..0000000000 --- a/test/embedded/jersey/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - - cloud.piranha.test.embedded - project - 25.1.0-SNAPSHOT - - piranha-test-embedded-jersey - war - Piranha - Test - Embedded - Jersey - - UTF-8 - - - - - jakarta.ws.rs - jakarta.ws.rs-api - provided - - - - cloud.piranha - piranha-embedded - ${project.version} - test - - - cloud.piranha.extension - piranha-extension-jersey - ${project.version} - test - - - cloud.piranha.extension - piranha-extension-weld - ${project.version} - test - - - cloud.piranha.extension - piranha-extension-webxml - ${project.version} - test - - - org.junit.jupiter - junit-jupiter-api - test - - - diff --git a/test/embedded/jersey/src/main/webapp/WEB-INF/web.xml b/test/embedded/jersey/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index f97ae2225c..0000000000 --- a/test/embedded/jersey/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - Jersey - org.glassfish.jersey.servlet.ServletContainer - - jersey.config.server.provider.packages - jersey - - - - Jersey - /rest/* - - - 30 - - diff --git a/test/embedded/pom.xml b/test/embedded/pom.xml index d3452a6b43..f304def264 100644 --- a/test/embedded/pom.xml +++ b/test/embedded/pom.xml @@ -21,7 +21,6 @@ exousia hazelcast helloworld - jersey soteria-basic soteria-form springboot