From f9e7a67bc10ff1b09f2f82fe11f70efd7d1972ed Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Thu, 7 Mar 2024 12:08:48 +0100 Subject: [PATCH] Add integration tests for Tomcat #435 --- clusterbench-ee10-web/pom.xml | 2 + integration-tests/pom.xml | 38 ++++ integration-tests/tomcat-10.1/pom.xml | 202 ++++++++++++++++++ .../it/tomcat/HttpSessionServletTomcatIT.java | 74 +++++++ .../src/test/resources/arquillian.xml | 20 ++ .../test/resources/tomcat/tomcat-users.xml | 15 ++ pom.xml | 6 + 7 files changed, 357 insertions(+) create mode 100644 integration-tests/pom.xml create mode 100644 integration-tests/tomcat-10.1/pom.xml create mode 100644 integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/HttpSessionServletTomcatIT.java create mode 100644 integration-tests/tomcat-10.1/src/test/resources/arquillian.xml create mode 100644 integration-tests/tomcat-10.1/src/test/resources/tomcat/tomcat-users.xml diff --git a/clusterbench-ee10-web/pom.xml b/clusterbench-ee10-web/pom.xml index 7aced306..7a8ab98d 100644 --- a/clusterbench-ee10-web/pom.xml +++ b/clusterbench-ee10-web/pom.xml @@ -91,6 +91,8 @@ war + + true true diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml new file mode 100644 index 00000000..234654f0 --- /dev/null +++ b/integration-tests/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + + + org.jboss.test + clusterbench + 9.0.0.Final-SNAPSHOT + + + clusterbench-it-parent + pom + + + + + org.jboss.arquillian + arquillian-bom + ${version.org.jboss.arquillian} + import + pom + + + + + + + tomcat-10.1 + + + \ No newline at end of file diff --git a/integration-tests/tomcat-10.1/pom.xml b/integration-tests/tomcat-10.1/pom.xml new file mode 100644 index 00000000..3532d3a3 --- /dev/null +++ b/integration-tests/tomcat-10.1/pom.xml @@ -0,0 +1,202 @@ + + + + + 4.0.0 + + + org.jboss.test + clusterbench-it-parent + 9.0.0.Final-SNAPSHOT + + + clusterbench-it-tomcat-10.1 + jar + + + ${project.build.directory}/apache-tomcat-${version.org.apache.tomcat} + + + + + org.jboss.test + clusterbench-ee10-web + ${project.version} + classes + test + + + junit + junit + test + + + org.apache.httpcomponents + httpclient + test + + + org.jboss.arquillian.container + arquillian-tomcat-managed-8 + 1.1.0.Final + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + + jakarta.servlet + jakarta.servlet-api + test + + + + + + + src/test/resources + + arquillian.xml + + true + + + src/test/resources/tomcat + ${catalina.home}/conf + + * + + true + + + src/test/java + + **/*.properties + **/*.xml + + true + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-war + generate-test-resources + + copy + + + + + org.jboss.test + clusterbench-ee10-web + ${project.version} + war + true + tomcat + ${project.build.directory} + + + true + + + + unpack-tomcat + generate-test-resources + + unpack + + + + + org.apache.tomcat + tomcat + ${version.org.apache.tomcat} + zip + true + ${project.build.directory} + ** + + + + + + + + org.apache.maven.plugins + maven-clean-plugin + + + clean-tomcat-webapps + pre-integration-test + + clean + + + true + + + ${catalina.home}/webapps + + ROOT/** + docs/** + examples/** + + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + + + copy-tomcat-1 + pre-integration-test + + copy-resources + + + ${project.build.directory}/tomcat-1 + + + ${catalina.home} + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + smoke-test + integration-test + + integration-test + verify + + + false + + + + + + + + + \ No newline at end of file diff --git a/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/HttpSessionServletTomcatIT.java b/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/HttpSessionServletTomcatIT.java new file mode 100644 index 00000000..9f8915b5 --- /dev/null +++ b/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/HttpSessionServletTomcatIT.java @@ -0,0 +1,74 @@ +/* + * Copyright The ClusterBench Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.jboss.test.clusterbench.it.tomcat; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.net.URL; +import java.util.Arrays; +import java.util.Optional; + +import org.apache.http.Header; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.importer.ZipImporter; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.clusterbench.web.session.HttpSessionServlet; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * @author Radoslav Husar + */ +@RunWith(Arquillian.class) +@RunAsClient +public class HttpSessionServletTomcatIT { + + @Deployment(testable = false) + public static Archive deployment() { + return ShrinkWrap + .create(ZipImporter.class, "clusterbench.war") + .importFrom(new File("target/clusterbench-ee10-web-tomcat.war")) + .as(WebArchive.class); + } + + @Test + public void test(@ArquillianResource(HttpSessionServlet.class) URL baseURL) throws Exception { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpGet httpGet = new HttpGet(baseURL.toURI() + "/session"); + System.out.println(httpGet); + + try (CloseableHttpResponse response = httpClient.execute(httpGet)) { + assertEquals(200, response.getStatusLine().getStatusCode()); + + String responseBody = EntityUtils.toString(response.getEntity()); + assertEquals("0", responseBody); + + // Also ensure session is created + Optional
header = Arrays.stream(response.getAllHeaders()).filter(h -> Arrays.stream(h.getElements()).anyMatch(e -> e.getName().equals("JSESSIONID"))).findAny(); + assertTrue(header.isPresent()); + } + + try (CloseableHttpResponse response = httpClient.execute(httpGet)) { + assertEquals(200, response.getStatusLine().getStatusCode()); + + String responseBody = EntityUtils.toString(response.getEntity()); + assertEquals("1", responseBody); + } + } + } +} diff --git a/integration-tests/tomcat-10.1/src/test/resources/arquillian.xml b/integration-tests/tomcat-10.1/src/test/resources/arquillian.xml new file mode 100644 index 00000000..7e9e094c --- /dev/null +++ b/integration-tests/tomcat-10.1/src/test/resources/arquillian.xml @@ -0,0 +1,20 @@ + + + + + + + + ${project.build.directory}/tomcat-1 + 8089 + 8080 + --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED + admin + admin + + + + diff --git a/integration-tests/tomcat-10.1/src/test/resources/tomcat/tomcat-users.xml b/integration-tests/tomcat-10.1/src/test/resources/tomcat/tomcat-users.xml new file mode 100644 index 00000000..f0a2ccac --- /dev/null +++ b/integration-tests/tomcat-10.1/src/test/resources/tomcat/tomcat-users.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index bbde6273..146dd010 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ clusterbench-ee10-ejb clusterbench-ee10-web clusterbench-ee10-ear + integration-tests @@ -44,7 +45,12 @@ 31.0.1.Final 6.0.0.Final 4.2.2.Final + + + 10.1.15 5.10.0 + 1.8.0.Final + true