Skip to content

Commit

Permalink
Fixes #4398 - Move REST example to Piranha Core Profile tests (#4399)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem authored Dec 15, 2024
1 parent aaf1b15 commit e6548c7
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 121 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,16 @@
</ignoreVersion>
</ignoreVersions>
</rule>
<rule>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<ignoreVersions>
<ignoreVersion>
<type>range</type>
<version>[4.0.0-alpha-1,)</version>
</ignoreVersion>
</ignoreVersions>
</rule>
<rule>
<groupId>org.apache.maven.plugins</groupId>
<ignoreVersions>
Expand Down
1 change: 1 addition & 0 deletions test/coreprofile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
<module>integration</module>
<module>json</module>
<module>no_servlet_class</module>
<module>rest</module>
</modules>
</project>
115 changes: 115 additions & 0 deletions test/coreprofile/rest/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cloud.piranha.test.coreprofile</groupId>
<artifactId>project</artifactId>
<version>25.1.0-SNAPSHOT</version>
</parent>
<artifactId>piranha-test-coreprofile-rest</artifactId>
<packaging>war</packaging>
<name>Piranha - Test - Core Profile - REST</name>
<properties>
<!-- other -->
<piranha.version>${project.version}</piranha.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- compile -->
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>rest</finalName>
<plugins>
<plugin>
<groupId>cloud.piranha.maven</groupId>
<artifactId>piranha-maven-plugin</artifactId>
<version>${piranha.version}</version>
<executions>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<contextPath>/rest</contextPath>
<httpPort>${httpPort}</httpPort>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<forkCount>1</forkCount>
<systemPropertyVariables>
<httpPort>${httpPort}</httpPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>package</phase>
<configuration>
<portNames>
<portName>httpPort</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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 ([email protected])
*/
@ApplicationPath("")
public class RestApplication extends Application {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
*/
@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";
}
}
10 changes: 10 additions & 0 deletions test/coreprofile/rest/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
*/
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<String> response = client.send(request, BodyHandlers.ofString());
assertEquals("Hello REST", response.body());
}
}
54 changes: 0 additions & 54 deletions test/embedded/jersey/pom.xml

This file was deleted.

22 changes: 0 additions & 22 deletions test/embedded/jersey/src/main/webapp/WEB-INF/web.xml

This file was deleted.

1 change: 0 additions & 1 deletion test/embedded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<module>exousia</module>
<module>hazelcast</module>
<module>helloworld</module>
<module>jersey</module>
<module>soteria-basic</module>
<module>soteria-form</module>
<module>springboot</module>
Expand Down

0 comments on commit e6548c7

Please sign in to comment.