From e2a619c72b9b5ea7b7535cecb3aa17de566e0e34 Mon Sep 17 00:00:00 2001 From: arolfes Date: Fri, 17 Nov 2023 17:24:00 +0100 Subject: [PATCH] Closes #612: add wildfly test that wildflyApp is deployed --- docker-databases/docker-compose.yml | 8 + docker-databases/postgres_14/Dockerfile | 3 + docker-databases/prepare_db.bat | 43 + docker-databases/prepare_db.sh | 68 ++ pom.xml | 12 +- .../pom.xml | 170 ++++ .../src/main/resources/application.properties | 2 +- .../example/wildfly/AbstractAccTest.java | 93 +++ .../wildfly/TaskanaAdapterWildflyTest.java | 47 ++ .../src/test/resources/arquillian.xml | 21 + .../src/test/resources/int-test-jboss-web.xml | 8 + .../test/resources/int-test-standalone.xml | 789 ++++++++++++++++++ .../src/test/resources/int-test-web.xml | 41 + .../src/test/resources/module.xml | 15 + .../util/configureDS.script | 4 +- 15 files changed, 1318 insertions(+), 6 deletions(-) create mode 100644 docker-databases/docker-compose.yml create mode 100644 docker-databases/postgres_14/Dockerfile create mode 100644 docker-databases/prepare_db.bat create mode 100755 docker-databases/prepare_db.sh create mode 100644 taskana-adapter-camunda-wildfly-example/src/test/java/pro/taskana/adapter/example/wildfly/AbstractAccTest.java create mode 100644 taskana-adapter-camunda-wildfly-example/src/test/java/pro/taskana/adapter/example/wildfly/TaskanaAdapterWildflyTest.java create mode 100644 taskana-adapter-camunda-wildfly-example/src/test/resources/arquillian.xml create mode 100644 taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-jboss-web.xml create mode 100644 taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-standalone.xml create mode 100644 taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-web.xml create mode 100644 taskana-adapter-camunda-wildfly-example/src/test/resources/module.xml diff --git a/docker-databases/docker-compose.yml b/docker-databases/docker-compose.yml new file mode 100644 index 00000000..c0296ec9 --- /dev/null +++ b/docker-databases/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + taskana-postgres_14: + build: postgres_14 + ports: + - 50102:5432 + environment: + - POSTGRES_PASSWORD=postgres \ No newline at end of file diff --git a/docker-databases/postgres_14/Dockerfile b/docker-databases/postgres_14/Dockerfile new file mode 100644 index 00000000..effbc3fe --- /dev/null +++ b/docker-databases/postgres_14/Dockerfile @@ -0,0 +1,3 @@ +FROM postgres:14.7 +RUN localedef -i de_DE -c -f UTF-8 -A /usr/share/locale/locale.alias de_DE.UTF-8 +ENV LANG de_DE.utf8 \ No newline at end of file diff --git a/docker-databases/prepare_db.bat b/docker-databases/prepare_db.bat new file mode 100644 index 00000000..4f2d2657 --- /dev/null +++ b/docker-databases/prepare_db.bat @@ -0,0 +1,43 @@ +@ECHO OFF +SETLOCAL + +:MENU + ECHO. + ECHO ----------------------------------------------------- + ECHO PRESS a number to select your task - anything to EXIT. + ECHO ----------------------------------------------------- + ECHO. + ECHO 1 - Start POSTGRES 14 + ECHO 2 - Stop POSTGRES 14 + ECHO. + ECHO 3 - Stop all + ECHO. + SET /P MENU=Select task then press ENTER: + ECHO. + IF [%MENU%]==[1] GOTO START_POSTGRES_14 + IF [%MENU%]==[2] GOTO STOP_POSTGRES_14 + IF [%MENU%]==[3] GOTO STOP_ALL + EXIT /B + +:START_POSTGRES_14 + ECHO --- + ECHO docker-compose -f %~dp0/docker-compose.yml up -d taskana-postgres_14 + docker-compose -f %~dp0/docker-compose.yml up -d taskana-postgres_14 + + ECHO --- + GOTO MENU + +:STOP_POSTGRES_14 + ECHO --- + ECHO docker stop taskana-postgres_14 + ECHO docker-compose -f %~dp0/docker-compose.yml rm -f -s -v taskana-postgres_14 + docker-compose -f %~dp0/docker-compose.yml rm -f -s -v taskana-postgres_14 + ECHO --- + GOTO MENU + +:STOP_ALL + ECHO --- + ECHO docker-compose -f %~dp0/docker-compose.yml down -v + docker-compose -f %~dp0/docker-compose.yml down -v + ECHO --- + GOTO MENU diff --git a/docker-databases/prepare_db.sh b/docker-databases/prepare_db.sh new file mode 100755 index 00000000..1c836138 --- /dev/null +++ b/docker-databases/prepare_db.sh @@ -0,0 +1,68 @@ +#!/bin/bash +set -e #fail fast +trap "exit 1" TERM +export TOP_PID=$$ + +#H Usage: +#H %FILE% -h | %FILE% --help +#H +#H prints this help and exits +#H +#H %FILE% +#H +#H downloads and starts docker image for TASKANA unit tests. +#H +#H %FILE% stop [database] +#H +#H stops the database. +#H If no database was provided all databases are stopped. +#H +#H database: +#H - POSTGRES | POSTGRES_14 +# Arguments: +# $1: exit code +function helpAndExit() { + cat "$0" | grep "^#H" | cut -c4- | sed -e "s/%FILE%/$(basename "$0")/g" + exit "$1" +} + +# This function maps the database parameter (for this file) to the docker-compose service name. +# Arguments: +# $1: the database which should be mapped +function mapDBToDockerComposeServiceName() { + [[ -z "$1" || "$1" == "H2" ]] && return + case "$1" in + POSTGRES|POSTGRES_14) + echo "taskana-postgres_14" + ;; + *) + echo "unknown database '$1'" >&2 && kill -s TERM $TOP_PID + esac +} + +function main() { + [[ $# -eq 0 || "$1" == '-h' || "$1" == '--help' ]] && helpAndExit 0 + scriptDir=$(dirname "$0") + + case "$1" in + H2) + ;; + POSTGRES|POSTGRES_14) + docker-compose -f $scriptDir/docker-compose.yml up -d "$(mapDBToDockerComposeServiceName "$1")" + ;; + stop) + # this variable is necessary, so that the script can terminate properly + # when the provided database name does not match. PLEASE DO NOT INLINE! + local composeServiceName="$(mapDBToDockerComposeServiceName "$2")" + docker-compose -f $scriptDir/docker-compose.yml rm -f -s -v $composeServiceName + ;; + *) + echo "unknown database '$1'" >&2 + exit 1 + ;; + esac + + docker ps +} + +main "$@" diff --git a/pom.xml b/pom.xml index 4d508931..4a42b0ea 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,10 @@ 3.3.1 2.7.9 3.10.0.2594 + 4.0.0.Final + 7.9.Final + 3.3.1 + 3.6.1 3.5.13 3.0.2 @@ -76,9 +80,11 @@ 2.1.1 5.3.1 3.0.3.Final - 11.0.0.Final - 4.0.0.Final - 7.9.Final + + 27.0.1.Final + 1.7.1.Final + 5.0.1.Final + 1.0.1 0.2 diff --git a/taskana-adapter-camunda-wildfly-example/pom.xml b/taskana-adapter-camunda-wildfly-example/pom.xml index 933f3c50..d7fef82c 100644 --- a/taskana-adapter-camunda-wildfly-example/pom.xml +++ b/taskana-adapter-camunda-wildfly-example/pom.xml @@ -27,6 +27,20 @@ import pom + + org.wildfly.bom + wildfly-ee + ${version.wildfly} + import + pom + + + org.jboss.arquillian + arquillian-bom + ${version.arquillian} + import + pom + @@ -39,6 +53,10 @@ org.springframework.boot spring-boot-starter-tomcat + + org.springframework.boot + spring-boot-starter-logging + @@ -89,6 +107,15 @@ ${version.jakarta.servlet} provided + + + org.wildfly.arquillian + wildfly-arquillian-container-managed + ${version.arquillian.managed.wildfly} + provided + + + org.springframework.boot spring-boot-starter-test @@ -100,6 +127,51 @@ + + org.slf4j + slf4j-simple + test + + + org.junit.jupiter + junit-jupiter + test + + + org.junit.vintage + junit-vintage-engine + test + + + org.springframework + spring-test + test + + + org.springframework.boot + spring-boot-test + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-api-maven + test + @@ -177,7 +249,105 @@ maven-war-plugin ${version.maven-war-plugin} + + + org.apache.maven.plugins + maven-dependency-plugin + ${version.maven.dependency} + + + unpack-wildfly + process-test-classes + + unpack + + + + + org.wildfly + wildfly-dist + ${version.wildfly} + zip + false + ${project.build.directory} + + + + + + copy-postgres-db-driver + process-test-classes + + copy + + + + + org.postgresql + postgresql + + ${project.build.directory}/wildfly-${version.wildfly}/modules/system/layers/base/org/postgresql/postgresql/main + + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + ${version.maven.resources} + + + copy-postgres-module-xml + process-test-classes + + copy-resources + + + + ${project.build.directory}/wildfly-${version.wildfly}/modules/system/layers/base/org/postgresql/postgresql/main + + + + src/test/resources + + module.xml + + + + + + + copy-wildfly-config-xml + process-test-classes + + copy-resources + + + + ${project.build.directory}/wildfly-${version.wildfly}/standalone/configuration + + + + src/test/resources + + int-test-standalone.xml + + + + + + + + + + jboss + https://repository.jboss.org/nexus/content/groups/public-jboss/ + + diff --git a/taskana-adapter-camunda-wildfly-example/src/main/resources/application.properties b/taskana-adapter-camunda-wildfly-example/src/main/resources/application.properties index b4f66417..b303835b 100644 --- a/taskana-adapter-camunda-wildfly-example/src/main/resources/application.properties +++ b/taskana-adapter-camunda-wildfly-example/src/main/resources/application.properties @@ -30,7 +30,7 @@ taskana-system-connector-outbox-rest-api-user-password=pwd4OutboxRestUser #################################################################################### # taskana-connector properties ###################################################################################### -taskana.datasource.jndi-name=java:/TaskanaDS +taskana.datasource.jndi-name=java:jboss/datasources/TaskanaDS ####### cache static resources properties spring.web.resources.cache.cachecontrol.cache-private=true taskana.schemaName=TASKANA diff --git a/taskana-adapter-camunda-wildfly-example/src/test/java/pro/taskana/adapter/example/wildfly/AbstractAccTest.java b/taskana-adapter-camunda-wildfly-example/src/test/java/pro/taskana/adapter/example/wildfly/AbstractAccTest.java new file mode 100644 index 00000000..100fccd8 --- /dev/null +++ b/taskana-adapter-camunda-wildfly-example/src/test/java/pro/taskana/adapter/example/wildfly/AbstractAccTest.java @@ -0,0 +1,93 @@ +package pro.taskana.adapter.example.wildfly; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.ClassMode; +import org.springframework.test.context.ActiveProfiles; + +// DirtiesContext is required to make the integration tests run with embedded LDAP. +// Otherwise the LDAP server is not shut down correctly and will not come up again. (socket busy) +@DirtiesContext(classMode = ClassMode.AFTER_CLASS) +@ActiveProfiles({"test"}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class AbstractAccTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractAccTest.class); + + static { + Runtime.getRuntime().addShutdownHook(new Thread(AbstractAccTest::stopPostgresDb)); + + startPostgresDb(); + } + + private static void startPostgresDb() { + try { + boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows"); + ProcessBuilder builder = new ProcessBuilder(); + if (isWindows) { + builder.command( + "cmd.exe", + "/c", + "docker-compose -f ../docker-databases/docker-compose.yml up -d " + + "taskana-postgres_14"); + } else { + builder.command( + "sh", + "-c", + "docker-compose -f ../docker-databases/docker-compose.yml up -d " + + "taskana-postgres_14"); + } + Process process = builder.start(); + LOGGER.info("Starting POSTGRES..."); + int exitCode = process.waitFor(); + if (exitCode != 0) { + throw new RuntimeException("could not start postgres db!"); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static void stopPostgresDb() { + try { + boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows"); + ProcessBuilder builder = new ProcessBuilder(); + if (isWindows) { + builder.command( + "cmd.exe", "/c", "docker-compose -f ../docker-databases/docker-compose.yml down -v"); + } else { + builder.command( + "sh", "-c", "docker-compose -f ../docker-databases/docker-compose.yml down -v"); + } + Process process = builder.start(); + LOGGER.info("Stopping POSTGRES..."); + int exitCode = process.waitFor(); + if (exitCode != 0) { + throw new RuntimeException("could not start postgres db!"); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected String parseServerLog() throws Exception { + + // TO-DO: make log4j log into rollingFile from log4j.xml + File file = new File("target/wildfly-27.0.1.Final/standalone/log/server.log"); + + BufferedReader br = new BufferedReader(new FileReader(file)); + + String str; + StringBuilder stringBuilder = new StringBuilder(); + while ((str = br.readLine()) != null) { + stringBuilder.append(str); + } + return stringBuilder.toString(); + } + +} diff --git a/taskana-adapter-camunda-wildfly-example/src/test/java/pro/taskana/adapter/example/wildfly/TaskanaAdapterWildflyTest.java b/taskana-adapter-camunda-wildfly-example/src/test/java/pro/taskana/adapter/example/wildfly/TaskanaAdapterWildflyTest.java new file mode 100644 index 00000000..3c5801e5 --- /dev/null +++ b/taskana-adapter-camunda-wildfly-example/src/test/java/pro/taskana/adapter/example/wildfly/TaskanaAdapterWildflyTest.java @@ -0,0 +1,47 @@ +package pro.taskana.adapter.example.wildfly; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +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.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** This test class is configured to run with postgres DB. */ +@RunWith(Arquillian.class) +public class TaskanaAdapterWildflyTest extends AbstractAccTest { + + @Deployment(testable = false) + public static Archive createTestArchive() { + File[] files = + Maven.resolver() + .loadPomFromFile("pom.xml") + .importCompileAndRuntimeDependencies() + .resolve() + .withTransitivity() + .asFile(); + + return ShrinkWrap.create(WebArchive.class, "TaskanaAdapter.war") + .addPackages(true, "pro.taskana") + .addAsResource("taskana.properties") + .addAsResource("application.properties") + .addAsWebInfResource("int-test-web.xml", "web.xml") + .addAsWebInfResource("int-test-jboss-web.xml", "jboss-web.xml") + .addAsLibraries(files); + } + + @Test + @RunAsClient + public void deploy() throws Exception { + assertThat(parseServerLog()).contains( + "Caught exception while trying to retrieve CamundaTaskEvents" + + " from system with URL http://localhost:7001" + ); + } +} diff --git a/taskana-adapter-camunda-wildfly-example/src/test/resources/arquillian.xml b/taskana-adapter-camunda-wildfly-example/src/test/resources/arquillian.xml new file mode 100644 index 00000000..10043bef --- /dev/null +++ b/taskana-adapter-camunda-wildfly-example/src/test/resources/arquillian.xml @@ -0,0 +1,21 @@ + + + + + target/wildfly-27.0.1.Final + int-test-standalone.xml + + + + + + + --add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED + -Djava.util.logging.manager=org.jboss.logmanager.LogManager + + + + \ No newline at end of file diff --git a/taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-jboss-web.xml b/taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-jboss-web.xml new file mode 100644 index 00000000..93154584 --- /dev/null +++ b/taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-jboss-web.xml @@ -0,0 +1,8 @@ + + + /taskanaAdapterCamundaWildfly + taskanaAdapterApplicationDomain + diff --git a/taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-standalone.xml b/taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-standalone.xml new file mode 100644 index 00000000..8b62578f --- /dev/null +++ b/taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-standalone.xml @@ -0,0 +1,789 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE; + + h2 + + sa + sa + + + + jdbc:postgresql://localhost:50102/postgres + org.postgresql.Driver + postgresql + + postgres + postgres + + + false + + + + jdbc:postgresql://localhost:50102/postgres + org.postgresql.Driver + postgresql + + postgres + postgres + + + false + + + + + org.h2.jdbcx.JdbcDataSource + + + + org.postgresql.Driver + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${jboss.bind.address:127.0.0.1} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-web.xml b/taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-web.xml new file mode 100644 index 00000000..008337b9 --- /dev/null +++ b/taskana-adapter-camunda-wildfly-example/src/test/resources/int-test-web.xml @@ -0,0 +1,41 @@ + + + TaskanaAdapterWildflySpring + + COOKIE + + + index.html + + + + taskanaAdapter-web + /* + + + * + + + + + Public + /css/main.css + /css/bootstrap/4.1.3/bootstrap.min.css + /css/bootstrap/4.1.3/bootstrap.min.css.map + /img/logo.png + /logout + + + + + * + + + BASIC + taskanaAdapterApplicationDomain + + diff --git a/taskana-adapter-camunda-wildfly-example/src/test/resources/module.xml b/taskana-adapter-camunda-wildfly-example/src/test/resources/module.xml new file mode 100644 index 00000000..00aacf6e --- /dev/null +++ b/taskana-adapter-camunda-wildfly-example/src/test/resources/module.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/taskana-adapter-camunda-wildfly-example/util/configureDS.script b/taskana-adapter-camunda-wildfly-example/util/configureDS.script index f7da467d..796961fc 100644 --- a/taskana-adapter-camunda-wildfly-example/util/configureDS.script +++ b/taskana-adapter-camunda-wildfly-example/util/configureDS.script @@ -7,8 +7,8 @@ module add --name=org.postgres --resources=/Driver/postgresql-42.2.5.jar --depen /subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver) -/subsystem=datasources/data-source=TaskanaDS/:add(connection-url=jdbc:postgresql://localhost:50102/postgres,driver-name=postgres,jndi-name=java:/TaskanaDS,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=postgres,user-name=postgres) +/subsystem=datasources/data-source=TaskanaDS/:add(connection-url=jdbc:postgresql://localhost:50102/postgres,driver-name=postgres,jndi-name=java:jboss/datasources/TaskanaDS,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=postgres,user-name=postgres) -/subsystem=datasources/data-source=TaskanaAdapterDS/:add(connection-url=jdbc:postgresql://localhost:50102/postgres,driver-name=postgres,jndi-name=java:/TaskanaAdapterDS,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=postgres,user-name=postgres) +/subsystem=datasources/data-source=TaskanaAdapterDS/:add(connection-url=jdbc:postgresql://localhost:50102/postgres,driver-name=postgres,jndi-name=java:jboss/datasources/TaskanaAdapterDS,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=postgres,user-name=postgres) run-batch