diff --git a/docs/src/site/markdown/index.md b/docs/src/site/markdown/index.md index f7afbfef1d..1923e26a1b 100644 --- a/docs/src/site/markdown/index.md +++ b/docs/src/site/markdown/index.md @@ -29,10 +29,10 @@ distribution supports see our [Jakarta EE / Micro Profile matrix](https://piranh ## Distribution specific documentation * [Piranha Core Profile](coreprofile/index.html) -* [Piranha Embedded](https://piranha.cloud/embedded/index.html) +* [Piranha Embedded](embedded/index.html) * [Piranha Servlet](https://piranha.cloud/servlet/index.html) * [Piranha Server](https://piranha.cloud/server/index.html) -* [Piranha Web Profile](https://piranha.cloud/web-profile/index.html) +* [Piranha Web Profile](webprofile/index.html) ## Maven Plugin documentation diff --git a/docs/src/site/markdown/webprofile/create_a_faces_application.md b/docs/src/site/markdown/webprofile/create_a_faces_application.md new file mode 100644 index 0000000000..feb1adc3c2 --- /dev/null +++ b/docs/src/site/markdown/webprofile/create_a_faces_application.md @@ -0,0 +1,290 @@ +# Create a Faces application + +If you are looking to use Piranha Web Profile with Jakarta Faces then read this! + +In 8 steps you will learn how to use Jakarta Faces on Piranha Web Profile. They +are: + +1. Create the Maven POM file +1. Add the hellofaces.xhtml page +1. Add the HelloBean.java file +1. Add the web.xml file +1. Add the beans.xml file +1. Add an integration test +1. Test the application +1. Deploy the application + +## Create the Maven POM file + +Create an empty directory to store your Maven project. Inside of that directory +create the ```pom.xml``` file with the content as below. + +```xml + + + + 4.0.0 + cloud.piranha.guides.webprofile + faces + 1-SNAPSHOT + war + Piranha Web Profile - Jakarta Faces application + + 10.0.0 + 17 + 5.10.0-M1 + 3.11.0 + 3.0.0 + 3.3.2 + webprofile + 23.6.0 + UTF-8 + + + + jakarta.platform + jakarta.jakartaee-web-api + ${jakartaee.version} + provided + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + + + faces + + + cloud.piranha.maven.plugins + piranha-maven-plugin + ${piranha.version} + + + pre-integration-test + pre-integration-test + + start + + + + post-integration-test + post-integration-test + + stop + + + + + ${piranha.distribution} + + + + 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 + + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + +``` + +## Add the Hello Faces XHTML file + +Add the helloworld.xhtml file in the `src/main/webapp` directory. + +```html + + + + + + + Jakarta Faces application + + + +
Jakarta Faces application
+ + +
+
+
+ +``` + +## Add the HelloBean.java file + +Add the HelloBean.java file in the `src/main/java/hello` directory. + +```java +package hello; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Named; + +@Named(value = "helloBean") +@RequestScoped +public class HelloBean { + + private String hello = "Hello from Jakarta Faces!"; + + public String getHello() { + return hello; + } + + public void setHello(String hello) { + this.hello = hello; + } +} +``` + +## Add the web.xml file + +Add the web.xml file in the `src/main/webapp/WEB-INF` directory. + +```xml + + + + + Faces Servlet + jakarta.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.xhtml + + +``` + +## Add the beans.xml file + +Add the beans.xml file in the `src/main/webapp/WEB-INF` directory. + +```xml + + + + +``` + +## Add an integration test + +As we want to make sure the application gets tested before we release an +integration test is added which will be executed as part of the build. + +We'll add the integration test to the `src/test/java` directory. + +```java +package hello; + +import java.net.URI; +import java.net.http.HttpClient; +import static java.net.http.HttpClient.Redirect.ALWAYS; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; +import java.time.Duration; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + +public class HelloIT { + + @Test + public void testHelloFacesXhtml() throws Exception { + HttpClient client = HttpClient + .newBuilder() + .connectTimeout(Duration.ofSeconds(60)) + .followRedirects(ALWAYS) + .build(); + HttpRequest request = HttpRequest + .newBuilder(new URI("http://localhost:8080/faces/hellofaces.xhtml")) + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + assertTrue(response.body().contains("Hello from Jakarta Faces!")); + } +} +``` + +## Test the application + +The application is setup to use JUnit to do integration testing using the +Piranha Maven plugin so when you are building the application it will also +execute an integration test validating the web application works. + +To build and test the application execute the following command: + +```bash + mvn install +``` + +## Deploy the application + +To deploy your application you will need 2 pieces. + +1. The Piranha Web Profile runtime JAR. +2. The WAR file you just produced. + +For the WAR file see the `target` directory. For the Piranha Web Profile +distribution go to Maven Central. And then the following command line will +deploy your application: + +```bash + java -jar piranha-dist-webprofile.jar --war-file faces.war +``` + +## Conclusion + +As you can integrating Jakarta Faces with Piranha Servlet can be done quickly! diff --git a/docs/src/site/markdown/webprofile/create_a_hello_world_application.md b/docs/src/site/markdown/webprofile/create_a_hello_world_application.md new file mode 100644 index 0000000000..76841786e9 --- /dev/null +++ b/docs/src/site/markdown/webprofile/create_a_hello_world_application.md @@ -0,0 +1,203 @@ +# Create a Hello World web application + +If you are looking to create a simple Hello World web application with Piranha +Web Profile you can start here! + +In 5 steps you will learn how to create the web application. They are: + +1. Create the Maven POM file +1. Add the helloworld.html page +1. Add an integration test +1. Test the application +1. Deploy the application + +## Create the Maven POM file + +Create an empty directory to store your Maven project. Inside of that directory create the ```pom.xml``` file with the content as below. + +```xml + + + + 4.0.0 + cloud.piranha.guides.webprofile + helloworld + 1-SNAPSHOT + war + Piranha Web Profile - HelloWorld application + + 17 + 5.10.0-M1 + 3.11.0 + 3.0.0 + 3.3.2 + webprofile + 23.6.0 + UTF-8 + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + + + helloworld + + + cloud.piranha.maven.plugins + piranha-maven-plugin + ${piranha.version} + + + pre-integration-test + pre-integration-test + + start + + + + post-integration-test + post-integration-test + + stop + + + + + ${piranha.distribution} + + + + 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 + + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + +``` + +## Add the Hello World HTML file + +Add the helloworld.html file in the `src/main/webapp` directory. + +```html + + + + + Hello World + + + + +
Hello World!
+ + +``` + +## Add an integration test + +As we want to make sure the application gets tested before we release an +integration test is added which will be executed as part of the build. + +We'll add the integration test to the `src/test/java` directory. + +```java +package helloworld; + +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.assertTrue; +import org.junit.jupiter.api.Test; + +class HelloWorldIT { + + @Test + void testHelloWorldHtml() throws Exception { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest + .newBuilder(new URI("http://localhost:8080/helloworld/helloworld.html")) + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + assertTrue(response.body().contains("Hello World!")); + } +} +``` + +## Test the application + +The application is setup to use JUnit to do integration testing using the +Piranha Maven plugin so when you are building the application it will also +execute an integration test validating the web application works. + +To build and test the application execute the following command: + +```bash + mvn install +``` + +## Deploy the application + +To deploy your application you will need 2 pieces. + +1. The Piranha Web Profile runtime JAR. +2. The WAR file you just produced. + +For the WAR file see the `target` directory. For the Piranha Web Profile +distribution go to Maven Central. And then the following command line will +deploy your application: + +```bash + java -jar piranha-dist-web-profile.jar --war-file helloworld.war +``` + +## Conclusion + +As you can see getting started with Piranha Web Profile takes (almost) no effort! + diff --git a/docs/src/site/markdown/webprofile/create_a_jakarta_rest_service.md b/docs/src/site/markdown/webprofile/create_a_jakarta_rest_service.md new file mode 100644 index 0000000000..337c14e5d7 --- /dev/null +++ b/docs/src/site/markdown/webprofile/create_a_jakarta_rest_service.md @@ -0,0 +1,236 @@ +# Create a Jakarta REST service + +This guide illustrates how you can create a Jakarta REST service with Piranha +Web Profile. + +In 6 steps you will learn how to create the REST service. They are: + +1. Create the Maven POM file +1. Add the application class +1. Add the endpoint +1. Add an integration test +1. Test the application +1. Deploy the application + +## Create the Maven POM file + +Create an empty directory to store your Maven project. Inside of that directory create the ```pom.xml``` file with the content as below. + +```xml + + + + 4.0.0 + cloud.piranha.guides.webprofile + rest + 1-SNAPSHOT + war + Piranha Web Profile - HelloREST service + + 10.0.0 + 17 + 5.10.0-M1 + 3.11.0 + 3.0.0 + 3.3.2 + webprofile + 23.6.0 + UTF-8 + + + + jakarta.platform + jakarta.jakartaee-web-api + ${jakartaee.version} + provided + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + + + rest + + + cloud.piranha.maven.plugins + piranha-maven-plugin + ${piranha.version} + + + pre-integration-test + pre-integration-test + + start + + + + post-integration-test + post-integration-test + + stop + + + + + ${piranha.distribution} + + + + 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 + + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + +``` + +## Add the application class + +Add the Application class in the `src/main/java` directory, which allows you to +set the application path using the @ApplicationPath annotation. + +```java +package rest; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +@ApplicationPath("") +public class HelloRestApplication extends Application { +} +``` + +## Add the endpoint + +And we are adding a simple 'Hello REST!' endpoint that is listening on the +`/hellorest` path. + +```java +package rest; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +@RequestScoped +@Path("/hellorest") +public class HelloRestBean { + + @GET + public String hello() { + return "Hello REST!"; + } +} +``` + +## Add an integration test + +As we want to make sure the application gets tested before we release an +integration test is added which will be executed as part of the build. + +We'll add the integration test to the `src/test/java` directory. + +```java +package rest; + +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.assertTrue; +import org.junit.jupiter.api.Test; + +class HelloRestIT { + + @Test + void testHelloWorld() throws Exception { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest + .newBuilder(new URI("http://localhost:8080/rest/hellorest")) + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + assertTrue(response.body().contains("Hello REST!")); + } +} +``` + +## Test the application + +The application is setup to use JUnit to do integration testing using the +Piranha Maven plugin so when you are building the application it will also +execute an integration test validating the endpoint works. + +To build and test the application execute the following command: + +```bash + mvn install +``` + +## Deploy the application + +To deploy your application you will need 2 pieces. + +1. The Piranha Core Profile runtime JAR. +2. The WAR file you just produced. + +For the WAR file see the `target` directory. For the Piranha WEb Profile +distribution go to Maven Central. And then the following command line will +deploy your application: + +```bash + java -jar piranha-dist-webprofile.jar --war-file rest.war +``` + +## Conclusion + +As you can see getting started with Piranha Web Profile to create a REST service +is pretty easy. + +## References + +1. [Piranha Web Profile](index.html) +1. [Piranha Maven plugin documentation](../maven-plugin/index.html) diff --git a/docs/src/site/markdown/webprofile/create_a_pages_application.md b/docs/src/site/markdown/webprofile/create_a_pages_application.md new file mode 100644 index 0000000000..25cad9a320 --- /dev/null +++ b/docs/src/site/markdown/webprofile/create_a_pages_application.md @@ -0,0 +1,215 @@ +# Create a Pages application + +If you are looking to use Piranha Web Profile with Jakarta Page you have come to +the right place! + +In 5 steps you will learn how to use Jakarta Pages on Piranha Web Profile. They +are: + +1. Create the Maven POM file +1. Add the hellopages.jsp page +1. Add an integration test +1. Test the application +1. Deploy the application + +## Create the Maven POM file + +Create an empty directory to store your Maven project. Inside of that directory +create the ```pom.xml``` file with the content as below. + +```xml + + + + 4.0.0 + cloud.piranha.guides.webprofile + pages + 1-SNAPSHOT + war + Jakarta Pages webapplication + + 21 + 5.10.0 + 3.11.0 + 3.2.1 + 3.4.0 + webprofile + 23.10.0 + UTF-8 + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + + + pages + + + cloud.piranha.maven.plugins + piranha-maven-plugin + ${piranha.version} + + + pre-integration-test + pre-integration-test + + start + + + + post-integration-test + post-integration-test + + stop + + + + + ${piranha.distribution} + + + + 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 + + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + +``` + +## Add the Hello Pages JSP file + +Add the hellopages.jsp file in the `src/main/webapp` directory. + +```html +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + + +

Hello from Jakarta Pages!

+ + +``` + +## Add an integration test + +As we want to make sure the application gets tested before we release an +integration test is added which will be executed as part of the build. + +We'll add the integration test to the `src/test/java/hello` directory. + +```java +package hello; + +import java.net.URI; +import java.net.http.HttpClient; +import static java.net.http.HttpClient.Redirect.ALWAYS; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; +import java.time.Duration; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + +public class HelloPagesIT { + + @Test + public void testHelloPagesJsp() throws Exception { + HttpClient client = HttpClient + .newBuilder() + .connectTimeout(Duration.ofSeconds(60)) + .followRedirects(ALWAYS) + .build(); + HttpRequest request = HttpRequest + .newBuilder(new URI("http://localhost:8080/pages/hellopages.jsp")) + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + assertTrue(response.body().contains("Hello from Jakarta Pages!")); + } +} +``` + +## Test the application + +The application is setup to use JUnit to do integration testing using the +Piranha Maven plugin so when you are building the application it will also +execute an integration test validating the web application works. + +To build and test the application execute the following command: + +```bash + mvn install +``` + +## Deploy the application + +To deploy your application you will need 2 pieces. + +1. The Piranha Web Profile runtime JAR. +2. The WAR file you just produced. + +For the WAR file see the `target` directory. For the Piranha Web Profile +distribution go to Maven Central. And then the following command line will +deploy your application: + +```bash + java -jar piranha-dist-webprofile.jar --war-file pages.war +``` + +## Conclusion + +As you can see using Jakarta Pages on Piranha Web Profile is very easy! + +## External References + +1. [Jakarta Pages 3.1 specification](https://jakarta.ee/specifications/pages/3.1/) + diff --git a/docs/src/site/markdown/webprofile/index.md b/docs/src/site/markdown/webprofile/index.md new file mode 100644 index 0000000000..a041797798 --- /dev/null +++ b/docs/src/site/markdown/webprofile/index.md @@ -0,0 +1,44 @@ +# Piranha Web Profile + +Piranha Web Profile is our distribution that delivers Jakarta EE Web Profile +support. If you are looking for Jakarta EE Web Profile support this distribution +is the best match! + +The following list of components are available in the Piranha Web Profile +distribution: + +1. Jakarta Annotations +1. Jakarta Authentication +1. Jakarta Bean Validation +1. Jakarta Concurrency +1. Jakarta Contexts and Dependency Injection +1. Jakarta Debugging Support for Other Languages +1. Jakarta Dependency Injection +1. Jakarta Enterprise Beans Lite +1. Jakarta Expression Language +1. Jakarta Interceptors +1. Jakarta JSON Binding +1. Jakarta JSON Processing +1. Jakarta Persistence +1. Jakarta RESTful Web Services +1. Jakarta Security +1. Jakarta Server Faces +1. Jakarta Server Pages +1. Jakarta Servlet +1. Jakarta Standard Tag Library +1. Jakarta Transactions +1. Jakarta WebSocket + +## Documentation + +1. [Create a Faces application](create_a_faces_application.html) +1. [Create a Hello World application](create_a_hello_world_application.html) +1. [Create a Jakarta REST service](create_a_jakarta_rest_service.html) +1. [Create a Pages application](create_a_pages_application.html) +1. [Testing with JUnit5 and Playwright](testing_with_junit5_and_playwright.html) +1. [Testing with our container image](testing_with_our_container_image.html) + +## External Documentation + +1. [Jakarta EE 10 Web Profile Specification](https://jakarta.ee/specifications/webprofile/10/jakarta-webprofile-spec-10.0.pdf) +1. [Jakarta EE 10 Web Profile API documentation](https://jakarta.ee/specifications/webprofile/10/apidocs/) diff --git a/docs/src/site/markdown/webprofile/testing_with_junit5_and_playwright.md b/docs/src/site/markdown/webprofile/testing_with_junit5_and_playwright.md new file mode 100644 index 0000000000..b5a9e3a190 --- /dev/null +++ b/docs/src/site/markdown/webprofile/testing_with_junit5_and_playwright.md @@ -0,0 +1,293 @@ +# Testing with JUnit 5 and Playwright + +If you are looking to use Piranha Web Profile with JUnit 5 and Playwright +then this guide will setup you up quickly! + +In 8 steps you will learn how to do so. They are: + +1. Create the Maven POM file +1. Add the helloplaywright.xhtml page +1. Add the HelloBean.java file +1. Add the web.xml file +1. Add the beans.xml file +1. Add an integration test +1. Test the application +1. Deploy the application + +## Create the Maven POM file + +Create an empty directory to store your Maven project. Inside of that directory +create the ```pom.xml``` file with the content as below. + +```xml + + + + 4.0.0 + cloud.piranha.guides.webprofile + playwright + 1-SNAPSHOT + war + Testing with JUnit 5 and Playwright + + 10.0.0 + 21 + 5.10.0 + 3.11.0 + 3.1.2 + 3.4.0 + webprofile + 23.9.0 + 1.38.0 + UTF-8 + + + + jakarta.platform + jakarta.jakartaee-web-api + ${jakartaee.version} + provided + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + + com.microsoft.playwright + playwright + ${playwright.version} + test + + + + playwright + + + cloud.piranha.maven.plugins + piranha-maven-plugin + ${piranha.version} + + + pre-integration-test + pre-integration-test + + start + + + + post-integration-test + post-integration-test + + stop + + + + + ${piranha.distribution} + + + + 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 + + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + +``` + +## Add the helloplaywright.xhtml file + +Add the helloplaywright.xhtml file in the `src/main/webapp` directory. + +```html + + + + + + + Jakarta Faces application + + + +
Jakarta Faces application
+ + +
+
+
+ +``` + +## Add the HelloBean.java file + +Add the HelloBean.java file in the `src/main/java/hello` directory. + +```java +package hello; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Named; + +@Named(value = "helloBean") +@RequestScoped +public class HelloBean { + + private String hello = "Hello Playwright!"; + + public String getHello() { + return hello; + } + + public void setHello(String hello) { + this.hello = hello; + } +} +``` + +## Add the web.xml file + +Add the web.xml file in the `src/main/webapp/WEB-INF` directory. + +```xml + + + + + Faces Servlet + jakarta.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.xhtml + + +``` + +## Add the beans.xml file + +Add the beans.xml file in the `src/main/webapp/WEB-INF` directory. + +```xml + + + + +``` + +## Add an integration test + +As we want to make sure the application gets tested before we release an +integration test is added which will be executed as part of the build. + +We'll add the integration test to the `src/test/java` directory. + +```java +package hello; + +import com.microsoft.playwright.Browser; +import com.microsoft.playwright.BrowserType; +import com.microsoft.playwright.Page; +import com.microsoft.playwright.Playwright; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + +public class HelloIT { + + @Test + public void testHelloPlaywrightXhtml() throws Exception { + try (Playwright playwright = Playwright.create()) { + BrowserType chromium = playwright.chromium(); + try (Browser browser = chromium.launch()) { + Page page = browser.newPage(); + page.navigate("http://localhost:8080/playwright/helloplaywright.xhtml"); + assertTrue(page.content().contains("Hello Playwright!")); + } + } + } +} +``` + +## Test the application + +The application is setup to use JUnit to do integration testing using the +Piranha Maven plugin so when you are building the application it will also +execute an integration test validating the web application works. + +To build and test the application execute the following command: + +```bash + mvn install +``` + +## Deploy the application + +To deploy your application you will need 2 pieces. + +1. The Piranha Web Profile runtime JAR. +2. The WAR file you just produced. + +For the WAR file see the `target` directory. For the Piranha Web Profile +distribution go to Maven Central. And then the following command line will +deploy your application: + +```bash + java -jar piranha-dist-webprofile.jar --war-file playwright.war +``` + +## Conclusion + +As you can see using JUnit 5 and Playwright with Piranha Web Profile is easy! + diff --git a/docs/src/site/markdown/webprofile/testing_with_our_container_image.md b/docs/src/site/markdown/webprofile/testing_with_our_container_image.md new file mode 100644 index 0000000000..6b225cbda7 --- /dev/null +++ b/docs/src/site/markdown/webprofile/testing_with_our_container_image.md @@ -0,0 +1,235 @@ +# Testing with our container image + +If you are in container land this guide will show you how to use our container +image for testing. + +In 5 steps you will learn how to it. They are: + +1. Create the Maven POM file +1. Add the helloworld.html page +1. Add an integration test +1. Create the Dockerfile +1. Test the application + +## Create the Maven POM file + +Create an empty directory to store your Maven project. Inside of that directory create the ```pom.xml``` file with the content as below. + +```xml + + + + 4.0.0 + cloud.piranha.guides.webprofile + docker + 1-SNAPSHOT + war + Testing with our container image + + + 10.0.0 + 5.10.0-M1 + + 0.43.4 + 3.11.0 + 3.0.0 + 3.3.2 + + 21 + UTF-8 + + + + jakarta.platform + jakarta.jakartaee-web-api + ${jakartaee.version} + provided + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + + + image + + + io.fabric8 + docker-maven-plugin + ${docker-maven-plugin.version} + + + + image + + + + linux/amd64 + linux/arm64 + + + ${basedir} + src/main/docker/Dockerfile + + + + 8080:8080 + + + + http://localhost:8080/helloworld.html + + + + + + + + + + start + pre-integration-test + + build + start + + + + stop + post-integration-test + + stop + + + + + + 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 + + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + +``` + +## Add the Hello World HTML file + +Add the helloworld.html file in the `src/main/webapp` directory. + +```html + + + + + Hello World + + + + +
Hello World!
+ + +``` + +## Add an integration test + +As we want to make sure the application gets tested before we release an +integration test is added which will be executed as part of the build. + +We'll add the integration test to the `src/test/java` directory. + +```java +package helloworld; + +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.assertTrue; +import org.junit.jupiter.api.Test; + +class HelloWorldIT { + + @Test + void testHelloWorldHtml() throws Exception { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest + .newBuilder(new URI("http://localhost:8080/helloworld.html")) + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + assertTrue(response.body().contains("Hello World!")); + } +} +``` + +## Create the Dockerfile + +Create the `Dockerfile` in the `src/main/docker` directory with the following +content: + +```dockerfile +FROM ghcr.io/piranhacloud/webprofile:23.12.0 +USER piranha +COPY target/image.war /home/piranha/ROOT.war +CMD ["java", "-jar", "piranha-dist-webprofile.jar", "--war-file", "ROOT.war"] +``` + +## Test the application + +The application is setup to use the Docker Maven plugin to do integration +testing so when you are building the application it will also execute an +integration test validating the web application works. + +To build and test the application execute the following command: + +```bash + mvn install +``` + +## Conclusion + +As you can see getting testing with our container image is easy! + diff --git a/docs/src/site/site.xml b/docs/src/site/site.xml index 44996b347a..90a375d689 100644 --- a/docs/src/site/site.xml +++ b/docs/src/site/site.xml @@ -7,6 +7,7 @@ name="Piranha"> Piranha + https://piranha.cloud/ A cloud native extensible runtime @@ -16,20 +17,35 @@ - - - - - - - + + + + + + + + + - - - - + + + + + + + + + + + + + + + + +