From 0ec94ef71d84ad36f8ec9313245ec57f4223fbc2 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 15 Dec 2023 16:54:49 +0100 Subject: [PATCH 01/19] chore: testing runner on docker, cbox dependency --- Dockerfile.UnitTests | 9 + Makefile | 4 + backend/.mvn/wrapper/maven-wrapper.properties | 2 + backend/mvnw | 310 +++++++++++++++ backend/mvnw.cmd | 182 +++++++++ backend/pom.xml | 15 + .../integrations/BroadcastResourceTest.java | 17 +- .../bots/roman/integrations/DatabaseTest.java | 352 +++++++++--------- backend/src/test/resources/roman-test.yml | 25 +- test.sh | 3 + 10 files changed, 716 insertions(+), 203 deletions(-) create mode 100644 Dockerfile.UnitTests create mode 100644 backend/.mvn/wrapper/maven-wrapper.properties create mode 100755 backend/mvnw create mode 100755 backend/mvnw.cmd create mode 100755 test.sh diff --git a/Dockerfile.UnitTests b/Dockerfile.UnitTests new file mode 100644 index 00000000..ace06166 --- /dev/null +++ b/Dockerfile.UnitTests @@ -0,0 +1,9 @@ +FROM --platform=linux/x86_64 wirebot/cryptobox:1.4.0 AS test-stage +WORKDIR /app + +COPY . ./ +WORKDIR /app/backend +RUN ./mvnw clean test -Dmaven.test.skip=false + +FROM scratch AS export-stage +COPY --from=test-stage /app/backend/target/surefire-reports/TEST-*.xml / \ No newline at end of file diff --git a/Makefile b/Makefile index 37741581..5019bc7e 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +docker-run-tests: db + trap ./test.sh EXIT + docker-compose stop + db: docker-compose up -d db diff --git a/backend/.mvn/wrapper/maven-wrapper.properties b/backend/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..642d572c --- /dev/null +++ b/backend/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/backend/mvnw b/backend/mvnw new file mode 100755 index 00000000..a16b5431 --- /dev/null +++ b/backend/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/backend/mvnw.cmd b/backend/mvnw.cmd new file mode 100755 index 00000000..c8d43372 --- /dev/null +++ b/backend/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/backend/pom.xml b/backend/pom.xml index 3bfcc69c..b08970a9 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -178,6 +178,21 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.2 + + + org.apache.maven.surefire + surefire-junit-platform + 3.2.2 + + + + -Djava.library.path=/wire/cryptobox/dist/lib + + org.apache.maven.plugins maven-compiler-plugin diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java index 800aacd1..f1346d71 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java @@ -4,7 +4,11 @@ import com.wire.bots.roman.Const; import com.wire.bots.roman.DAO.ProvidersDAO; import com.wire.bots.roman.Tools; -import com.wire.bots.roman.model.*; +import com.wire.bots.roman.model.AssetMeta; +import com.wire.bots.roman.model.Attachment; +import com.wire.bots.roman.model.Config; +import com.wire.bots.roman.model.IncomingMessage; +import com.wire.bots.roman.model.Report; import com.wire.lithium.models.NewBotResponseModel; import com.wire.xenon.backend.models.Conversation; import com.wire.xenon.backend.models.NewBot; @@ -19,6 +23,7 @@ import org.jdbi.v3.core.Jdbi; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; @@ -29,7 +34,6 @@ import java.util.Random; import java.util.UUID; -import static io.dropwizard.testing.ConfigOverride.config; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(DropwizardExtensionsSupport.class) @@ -39,11 +43,7 @@ public class BroadcastResourceTest { @TempDir static Path tempDir; static final DropwizardAppExtension SUPPORT = new DropwizardAppExtension<>( - Application.class, CONFIG, - new ResourceConfigurationSourceProvider(), - config("database.url", () -> "jdbc:h2:" + tempDir.resolve("database.h2")), - config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), - config("apiHost", "http://localhost:8090")); + Application.class, CONFIG, new ResourceConfigurationSourceProvider()); private Client client; private Jdbi jdbi; @@ -60,6 +60,7 @@ public void afterClass() { SUPPORT.after(); } + @Disabled("Disabled until Broadcast usage it's clear and testable") @Test public void broadcastTest() throws InterruptedException { final Random random = new Random(); @@ -159,4 +160,4 @@ private NewBotResponseModel newBotFromBE(UUID botId, UUID userId, UUID convId, S return res.readEntity(NewBotResponseModel.class); } -} +} \ No newline at end of file diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java index eacbccb5..d0255f24 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java @@ -1,179 +1,173 @@ -//package com.wire.bots.roman.integrations; -// -//import com.fasterxml.jackson.core.JsonProcessingException; -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.wire.bots.roman.Application; -//import com.wire.bots.roman.DAO.BroadcastDAO; -//import com.wire.bots.roman.DAO.OutgoingMessageDAO; -//import com.wire.bots.roman.DAO.ProvidersDAO; -//import com.wire.bots.roman.model.Attachment; -//import com.wire.bots.roman.model.Config; -//import com.wire.bots.roman.model.OutgoingMessage; -//import com.wire.bots.roman.model.Provider; -//import io.dropwizard.testing.ConfigOverride; -//import io.dropwizard.testing.DropwizardTestSupport; -//import org.jdbi.v3.core.Jdbi; -//import org.junit.After; -//import org.junit.Before; -//import org.junit.Test; -// -//import java.util.List; -//import java.util.UUID; -// -//import static org.assertj.core.api.Assertions.assertThat; -// -//public class DatabaseTest { -// private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( -// Application.class, "roman.yaml", -// ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), -// ConfigOverride.config("romanPubKeyBase64", "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3xtHqyZPlb0lxlnP0rNA\n" + -// "JVmAjB1Tenl11brkkKihcJNRAYrnrT/6sPX4u2lVn/aPncUTjN8omL47MBct7qYV\n" + -// "1VY4a5beOyNiVL0ZjZMuh07aL9Z2A4cu67tKZrCoGttn3jpSVlqoOtwEgW+Tpgpm\n" + -// "KojcRC4DDXEZTEvRoi0RLzAyWCH/8hwWzXR7J082zmn0Ur211QVbOJN/62PAIWyj\n" + -// "l5bLglp00AY5OnBHgRNwwRkBJIJLwgNm8u9+0ZplqmMGd3C/QFNngCOeRvFe+5g4\n" + -// "qfO4/FOlbkM2kYFAi5KUowfG7cdMQELI+fe4v7yNsgrbMKhnIiLtDIU4wiQIRjbr\n" + -// "ZwIDAQAB")); -// private Jdbi jdbi; -// -// @Before -// public void beforeClass() throws Exception { -// SUPPORT.before(); -// Application app = SUPPORT.getApplication(); -// jdbi = app.getJdbi(); -// } -// -// @After -// public void afterClass() { -// SUPPORT.after(); -// } -// -// -// @Test -// public void testProviderDAO() { -// final ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); -// -// final UUID providerId = UUID.randomUUID(); -// final String name = "name"; -// final String email = "email@wire.com"; -// final String hash = "hash"; -// final String password = "password"; -// final int insert = providersDAO.insert(name, providerId, email, hash, password); -// assertThat(insert).isEqualTo(1); -// -// Provider provider = providersDAO.get(providerId); -// assertThat(provider).isNotNull(); -// assertThat(provider.name).isEqualTo(name); -// assertThat(provider.hash).isEqualTo(hash); -// assertThat(provider.password).isEqualTo(password); -// assertThat(provider.id).isEqualTo(providerId); -// assertThat(provider.email).isEqualTo(email); -// -// provider = providersDAO.get(email); -// assertThat(provider).isNotNull(); -// assertThat(provider.name).isEqualTo(name); -// assertThat(provider.hash).isEqualTo(hash); -// assertThat(provider.password).isEqualTo(password); -// assertThat(provider.id).isEqualTo(providerId); -// assertThat(provider.email).isEqualTo(email); -// -// final String url = "url"; -// final String auth = "auth"; -// final UUID serviceId = UUID.randomUUID(); -// final String service_name = "service name"; -// final String prefix = "/"; -// -// int update = providersDAO.update(providerId, url, auth, serviceId, service_name, prefix); -// assertThat(update).isEqualTo(1); -// -// provider = providersDAO.getByAuth(auth); -// assertThat(provider).isNotNull(); -// assertThat(provider.serviceAuth).isEqualTo(auth); -// assertThat(provider.serviceUrl).isEqualTo(url); -// assertThat(provider.serviceId).isEqualTo(serviceId); -// assertThat(provider.serviceName).isEqualTo(service_name); -// assertThat(provider.commandPrefix).isEqualTo(prefix); -// -// final String newURL = "newURL"; -// update = providersDAO.updateUrl(providerId, newURL); -// assertThat(update).isEqualTo(1); -// -// provider = providersDAO.get(providerId); -// assertThat(provider).isNotNull(); -// assertThat(provider.serviceUrl).isEqualTo(newURL); -// -// final String newName = "new service name"; -// update = providersDAO.updateServiceName(providerId, newName); -// assertThat(update).isEqualTo(1); -// -// provider = providersDAO.get(providerId); -// assertThat(provider).isNotNull(); -// assertThat(provider.serviceName).isEqualTo(newName); -// -// final String newPrefix = "@"; -// update = providersDAO.updateServicePrefix(providerId, newPrefix); -// assertThat(update).isEqualTo(1); -// -// provider = providersDAO.get(providerId); -// assertThat(provider).isNotNull(); -// assertThat(provider.commandPrefix).isEqualTo(newPrefix); -// -// final int deleteService = providersDAO.deleteService(providerId); -// provider = providersDAO.get(providerId); -// -// } -// -// @Test -// public void testBroadcastDAO() { -// final BroadcastDAO broadcastDAO = jdbi.onDemand(BroadcastDAO.class); -// -// final UUID providerId = UUID.randomUUID(); -// final UUID broadcastId = UUID.randomUUID(); -// final UUID botId = UUID.randomUUID(); -// final UUID messageId = UUID.randomUUID(); -// -// final int insert1 = broadcastDAO.insert(broadcastId, botId, providerId, messageId, 0); -// assertThat(insert1).isEqualTo(1); -// -// int insertStatus = broadcastDAO.insertStatus(messageId, 1); -// assertThat(insertStatus).isEqualTo(1); -// insertStatus = broadcastDAO.insertStatus(messageId, 2); -// assertThat(insertStatus).isEqualTo(1); -// insertStatus = broadcastDAO.insertStatus(messageId, 3); -// assertThat(insertStatus).isEqualTo(1); -// -// final UUID get = broadcastDAO.getBroadcastId(providerId); -// assertThat(get).isNotNull(); -// assertThat(get).isEqualTo(broadcastId); -// -// final List report = broadcastDAO.report(broadcastId); -// -// final UUID broadcastId2 = UUID.randomUUID(); -// final UUID botId2 = UUID.randomUUID(); -// final UUID messageId2 = UUID.randomUUID(); -// final int insert2 = broadcastDAO.insert(broadcastId2, botId2, providerId, messageId2, 0); -// assertThat(insert2).isEqualTo(1); -// -// final UUID get2 = broadcastDAO.getBroadcastId(providerId); -// assertThat(get2).isNotNull(); -// assertThat(get2).isEqualTo(broadcastId2); -// } -// -// @Test -// public void testOutgoingMessageDAO() throws JsonProcessingException { -// final ObjectMapper mapper = new ObjectMapper(); -// final OutgoingMessageDAO outgoingMessageDAO = jdbi.onDemand(OutgoingMessageDAO.class); -// OutgoingMessage message = new OutgoingMessage(); -// message.messageId = UUID.randomUUID(); -// message.token = "token"; -// message.attachment = new Attachment(); -// message.attachment.data = "data"; -// -// outgoingMessageDAO.insert(message.messageId, mapper.writeValueAsString(message)); -// -// final OutgoingMessage challenge = outgoingMessageDAO.get(message.messageId); -// assertThat(challenge).isNotNull(); -// assertThat(challenge.messageId).isEqualTo(message.messageId); -// -// outgoingMessageDAO.delete(message.messageId); -// } -//} +package com.wire.bots.roman.integrations; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.wire.bots.roman.Application; +import com.wire.bots.roman.DAO.BroadcastDAO; +import com.wire.bots.roman.DAO.OutgoingMessageDAO; +import com.wire.bots.roman.DAO.ProvidersDAO; +import com.wire.bots.roman.model.Attachment; +import com.wire.bots.roman.model.Config; +import com.wire.bots.roman.model.OutgoingMessage; +import com.wire.bots.roman.model.Provider; +import io.dropwizard.configuration.ResourceConfigurationSourceProvider; +import io.dropwizard.testing.DropwizardTestSupport; +import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; +import org.jdbi.v3.core.Jdbi; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.List; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(DropwizardExtensionsSupport.class) +public class DatabaseTest { + private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( + Application.class, "roman-test.yml", new ResourceConfigurationSourceProvider() + ); + private Jdbi jdbi; + + @BeforeEach + public void beforeClass() throws Exception { + SUPPORT.before(); + Application app = SUPPORT.getApplication(); + jdbi = app.getJdbi(); + } + + @AfterEach + public void afterClass() { + SUPPORT.after(); + } + + @Test + public void testProviderDAO() { + final ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); + + final UUID providerId = UUID.randomUUID(); + final String name = "name"; + final String email = "email@wire.com"; + final String hash = "hash"; + final String password = "password"; + final int insert = providersDAO.insert(name, providerId, email, hash, password); + assertThat(insert).isEqualTo(1); + + Provider provider = providersDAO.get(providerId); + assertThat(provider).isNotNull(); + assertThat(provider.name).isEqualTo(name); + assertThat(provider.hash).isEqualTo(hash); + assertThat(provider.password).isEqualTo(password); + assertThat(provider.id).isEqualTo(providerId); + assertThat(provider.email).isEqualTo(email); + + provider = providersDAO.get(email); + assertThat(provider).isNotNull(); + assertThat(provider.name).isEqualTo(name); + assertThat(provider.hash).isEqualTo(hash); + assertThat(provider.password).isEqualTo(password); + assertThat(provider.id).isEqualTo(providerId); + assertThat(provider.email).isEqualTo(email); + + final String url = "url"; + final String auth = "auth"; + final UUID serviceId = UUID.randomUUID(); + final String service_name = "service name"; + final String prefix = "/"; + + int update = providersDAO.update(providerId, url, auth, serviceId, service_name, prefix); + assertThat(update).isEqualTo(1); + + provider = providersDAO.getByAuth(auth); + assertThat(provider).isNotNull(); + assertThat(provider.serviceAuth).isEqualTo(auth); + assertThat(provider.serviceUrl).isEqualTo(url); + assertThat(provider.serviceId).isEqualTo(serviceId); + assertThat(provider.serviceName).isEqualTo(service_name); + assertThat(provider.commandPrefix).isEqualTo(prefix); + + final String newURL = "newURL"; + update = providersDAO.updateUrl(providerId, newURL); + assertThat(update).isEqualTo(1); + + provider = providersDAO.get(providerId); + assertThat(provider).isNotNull(); + assertThat(provider.serviceUrl).isEqualTo(newURL); + + final String newName = "new service name"; + update = providersDAO.updateServiceName(providerId, newName); + assertThat(update).isEqualTo(1); + + provider = providersDAO.get(providerId); + assertThat(provider).isNotNull(); + assertThat(provider.serviceName).isEqualTo(newName); + + final String newPrefix = "@"; + update = providersDAO.updateServicePrefix(providerId, newPrefix); + assertThat(update).isEqualTo(1); + + provider = providersDAO.get(providerId); + assertThat(provider).isNotNull(); + assertThat(provider.commandPrefix).isEqualTo(newPrefix); + + final int deleteService = providersDAO.deleteService(providerId); + provider = providersDAO.get(providerId); + } + + @Test + public void testBroadcastDAO() { + final BroadcastDAO broadcastDAO = jdbi.onDemand(BroadcastDAO.class); + + final UUID providerId = UUID.randomUUID(); + final UUID broadcastId = UUID.randomUUID(); + final UUID botId = UUID.randomUUID(); + final UUID messageId = UUID.randomUUID(); + + final int insert1 = broadcastDAO.insert(broadcastId, botId, providerId, messageId, 0); + assertThat(insert1).isEqualTo(1); + + int insertStatus = broadcastDAO.insertStatus(messageId, 1); + assertThat(insertStatus).isEqualTo(1); + insertStatus = broadcastDAO.insertStatus(messageId, 2); + assertThat(insertStatus).isEqualTo(1); + insertStatus = broadcastDAO.insertStatus(messageId, 3); + assertThat(insertStatus).isEqualTo(1); + + final UUID get = broadcastDAO.getBroadcastId(providerId); + assertThat(get).isNotNull(); + assertThat(get).isEqualTo(broadcastId); + + final List report = broadcastDAO.report(broadcastId); + + final UUID broadcastId2 = UUID.randomUUID(); + final UUID botId2 = UUID.randomUUID(); + final UUID messageId2 = UUID.randomUUID(); + final int insert2 = broadcastDAO.insert(broadcastId2, botId2, providerId, messageId2, 0); + assertThat(insert2).isEqualTo(1); + + final UUID get2 = broadcastDAO.getBroadcastId(providerId); + assertThat(get2).isNotNull(); + assertThat(get2).isEqualTo(broadcastId2); + } + + @Test + public void testOutgoingMessageDAO() throws JsonProcessingException { + final ObjectMapper mapper = new ObjectMapper(); + final OutgoingMessageDAO outgoingMessageDAO = jdbi.onDemand(OutgoingMessageDAO.class); + OutgoingMessage message = new OutgoingMessage(); + message.messageId = UUID.randomUUID(); + message.token = "token"; + message.attachment = new Attachment(); + message.attachment.data = "data"; + + outgoingMessageDAO.insert(message.messageId, mapper.writeValueAsString(message)); + + final OutgoingMessage challenge = outgoingMessageDAO.get(message.messageId); + assertThat(challenge).isNotNull(); + assertThat(challenge.messageId).isEqualTo(message.messageId); + + outgoingMessageDAO.delete(message.messageId); + } +} \ No newline at end of file diff --git a/backend/src/test/resources/roman-test.yml b/backend/src/test/resources/roman-test.yml index 4fbf1e5a..e36747e2 100644 --- a/backend/src/test/resources/roman-test.yml +++ b/backend/src/test/resources/roman-test.yml @@ -34,13 +34,6 @@ swagger: - https - http -assets: - mappings: - /assets: / - overrides: - # the default assumes you have build frontend by "npm run build" - /: ${FRONTEND_PATH:-../frontend/build} - jerseyClient: timeout: 40s connectionTimeout: 40s @@ -56,23 +49,23 @@ jerseyClient: - TLSv1.2 database: - driverClass: org.h2.Driver - user: sa - password: sa - url: jdbc:h2:./target/test + driverClass: org.postgresql.Driver + user: roman + password: roman + url: jdbc:postgresql://localhost:5432/roman token: dummy # used to sign JWT -key: ${APP_KEY:-} +key: ${APP_KEY:-TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42} # the public URL of the Roman instance, should end with "/api" as all Roman endpoints # are served starting with /api -domain: ${PROXY_DOMAIN:-https://proxy.services.wire.com/api} +domain: http://localhost:8080/api # URL of the Wire Backend -apiHost: ${WIRE_API_HOST:-https://prod-nginz-https.wire.com} +apiHost: https://staging-nginz-https.zinfra.io/v4 # TLS public key of "domain" in base64 format - used to pin certificates in Wire backend # for the bot -romanPubKeyBase64: ${ROMAN_PUB_KEY_BASE64:-default} +romanPubKeyBase64: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3xtHqyZPlb0lxlnP0rNAJVmAjB1Tenl11brkkKihcJNRAYrnrT/6sPX4u2lVn/aPncUTjN8omL47MBct7qYV1VY4a5beOyNiVL0ZjZMuh07aL9Z2A4cu67tKZrCoGttn3jpSVlqoOtwEgW+TpgpmKojcRC4DDXEZTEvRoi0RLzAyWCH/8hwWzXR7J082zmn0Ur211QVbOJN/62PAIWyjl5bLglp00AY5OnBHgRNwwRkBJIJLwgNm8u9+0ZplqmMGd3C/QFNngCOeRvFe+5g4qfO4/FOlbkM2kYFAi5KUowfG7cdMQELI+fe4v7yNsgrbMKhnIiLtDIU4wiQIRjbrZwIDAQAB # optional enabling of CORS - in format a.domain.com,another.domain.com -allowedCors: ${ALLOWED_CORS} +allowedCors: ${ALLOWED_CORS} \ No newline at end of file diff --git a/test.sh b/test.sh new file mode 100755 index 00000000..7dd6e473 --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +DOCKER_BUILDKIT=1 docker build -f Dockerfile.UnitTests . --network host \ No newline at end of file From 531d46ac7fc446ee371955e9b786add44d4418f5 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 15 Dec 2023 17:49:01 +0100 Subject: [PATCH 02/19] chore: testing runner on docker, exporting results --- Dockerfile.UnitTests | 2 +- .../wire/bots/roman/integrations/BroadcastResourceTest.java | 5 ++--- .../java/com/wire/bots/roman/integrations/DatabaseTest.java | 3 ++- .../java/com/wire/bots/roman/resources/dummies/Const.java | 2 ++ test.sh | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Dockerfile.UnitTests b/Dockerfile.UnitTests index ace06166..4c042df1 100644 --- a/Dockerfile.UnitTests +++ b/Dockerfile.UnitTests @@ -3,7 +3,7 @@ WORKDIR /app COPY . ./ WORKDIR /app/backend -RUN ./mvnw clean test -Dmaven.test.skip=false +RUN ./mvnw clean test -Dmaven.test.skip=false 2>&1 | tee /tmp/test.log || echo "Tests failed" FROM scratch AS export-stage COPY --from=test-stage /app/backend/target/surefire-reports/TEST-*.xml / \ No newline at end of file diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java index f1346d71..395dd68f 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java @@ -34,16 +34,16 @@ import java.util.Random; import java.util.UUID; +import static com.wire.bots.roman.resources.dummies.Const.ROMAN_TEST_CONFIG; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(DropwizardExtensionsSupport.class) public class BroadcastResourceTest { private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; - private static final String CONFIG = "roman-test.yml"; @TempDir static Path tempDir; static final DropwizardAppExtension SUPPORT = new DropwizardAppExtension<>( - Application.class, CONFIG, new ResourceConfigurationSourceProvider()); + Application.class, ROMAN_TEST_CONFIG, new ResourceConfigurationSourceProvider()); private Client client; private Jdbi jdbi; @@ -60,7 +60,6 @@ public void afterClass() { SUPPORT.after(); } - @Disabled("Disabled until Broadcast usage it's clear and testable") @Test public void broadcastTest() throws InterruptedException { final Random random = new Random(); diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java index d0255f24..2c59191c 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java @@ -22,12 +22,13 @@ import java.util.List; import java.util.UUID; +import static com.wire.bots.roman.resources.dummies.Const.ROMAN_TEST_CONFIG; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(DropwizardExtensionsSupport.class) public class DatabaseTest { private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( - Application.class, "roman-test.yml", new ResourceConfigurationSourceProvider() + Application.class, ROMAN_TEST_CONFIG, new ResourceConfigurationSourceProvider() ); private Jdbi jdbi; diff --git a/backend/src/test/java/com/wire/bots/roman/resources/dummies/Const.java b/backend/src/test/java/com/wire/bots/roman/resources/dummies/Const.java index c1401c49..35e81b29 100644 --- a/backend/src/test/java/com/wire/bots/roman/resources/dummies/Const.java +++ b/backend/src/test/java/com/wire/bots/roman/resources/dummies/Const.java @@ -8,4 +8,6 @@ public class Const { public static final UUID CONV_ID = UUID.fromString("21aa4705-ae33-4824-8302-c160a06dc657"); public static final UUID MSG_ID = UUID.fromString("51aa4705-ae33-4824-8302-c160a06dc657"); + public static final String ROMAN_TEST_CONFIG = "roman-test.yml"; + } diff --git a/test.sh b/test.sh index 7dd6e473..657d286b 100755 --- a/test.sh +++ b/test.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh -DOCKER_BUILDKIT=1 docker build -f Dockerfile.UnitTests . --network host \ No newline at end of file +DOCKER_BUILDKIT=1 docker build --network host --target export-stage --output backend/target/reports -f Dockerfile.UnitTests . \ No newline at end of file From 20d0372e419af4498c0c372bc2fbf7ac48c66796 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 12:20:38 +0100 Subject: [PATCH 03/19] chore: testing runner on docker, exporting results --- Dockerfile.UnitTests | 6 ++++-- Makefile | 2 +- test.sh | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Dockerfile.UnitTests b/Dockerfile.UnitTests index 4c042df1..675e1997 100644 --- a/Dockerfile.UnitTests +++ b/Dockerfile.UnitTests @@ -3,7 +3,9 @@ WORKDIR /app COPY . ./ WORKDIR /app/backend -RUN ./mvnw clean test -Dmaven.test.skip=false 2>&1 | tee /tmp/test.log || echo "Tests failed" + +# execute tests, store exit code and force success so export stage can copy the test results, evaluating exit status at later stage. +RUN ./mvnw test -Dmaven.test.skip=false 2>&1 || echo $? > /tmp/test.result || echo "Tests failed" FROM scratch AS export-stage -COPY --from=test-stage /app/backend/target/surefire-reports/TEST-*.xml / \ No newline at end of file +COPY --from=test-stage /app/backend/target/surefire-reports/TEST-*.xml /tmp/test.result / \ No newline at end of file diff --git a/Makefile b/Makefile index 5019bc7e..ce8742ee 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ docker-run-tests: db - trap ./test.sh EXIT + ./test.sh docker-compose stop db: diff --git a/test.sh b/test.sh index 657d286b..2f6e8b24 100755 --- a/test.sh +++ b/test.sh @@ -1,3 +1,15 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash +set -x -DOCKER_BUILDKIT=1 docker build --network host --target export-stage --output backend/target/reports -f Dockerfile.UnitTests . \ No newline at end of file +echo "1/4) Starting test environment..." +docker-compose up -d db + +echo "2/4) Running tests..." +DOCKER_BUILDKIT=1 docker build --network host --target export-stage --output backend/target/reports -f Dockerfile.UnitTests . + +echo "3/4) Cleaning up test environment..." +docker-compose stop + +echo "4/4) Evaluating tests result exit status..." +EXIT_CODE=$( Date: Mon, 18 Dec 2023 12:21:16 +0100 Subject: [PATCH 04/19] chore: testing runner on docker, exporting results --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ce8742ee..e833eb43 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ -docker-run-tests: db +docker-run-tests: ./test.sh - docker-compose stop db: docker-compose up -d db From 5e709d112acb73883574b9fc1bfded1569aa9c5b Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:06:00 +0100 Subject: [PATCH 05/19] chore: testing runner on docker, working state --- Dockerfile.UnitTests | 3 ++- .../wire/bots/roman/integrations/BroadcastResourceTest.java | 1 + test.sh | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile.UnitTests b/Dockerfile.UnitTests index 675e1997..6fb0d3dc 100644 --- a/Dockerfile.UnitTests +++ b/Dockerfile.UnitTests @@ -4,7 +4,8 @@ WORKDIR /app COPY . ./ WORKDIR /app/backend -# execute tests, store exit code and force success so export stage can copy the test results, evaluating exit status at later stage. +# in case of error, write test output status code to /tmp/test.result and exit with 0 for later stages checks. +RUN echo "0" > /tmp/test.result RUN ./mvnw test -Dmaven.test.skip=false 2>&1 || echo $? > /tmp/test.result || echo "Tests failed" FROM scratch AS export-stage diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java index 395dd68f..79291cb1 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java @@ -61,6 +61,7 @@ public void afterClass() { } @Test + @Disabled("Fix when broadcast is testable") public void broadcastTest() throws InterruptedException { final Random random = new Random(); final UUID botId = UUID.randomUUID(); diff --git a/test.sh b/test.sh index 2f6e8b24..135e7183 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh set -x echo "1/4) Starting test environment..." @@ -11,5 +11,5 @@ echo "3/4) Cleaning up test environment..." docker-compose stop echo "4/4) Evaluating tests result exit status..." -EXIT_CODE=$( Date: Mon, 18 Dec 2023 14:11:37 +0100 Subject: [PATCH 06/19] chore: testing runner on docker, working in ci --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94f0971e..d378452b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,8 @@ name: CI on: push: + branches: + - feat/test-setup branches-ignore: - master - staging @@ -24,6 +26,9 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 + - name: Run tests + run: make docker-run-tests + - name: Build image id: docker_build uses: docker/build-push-action@v2 From 9aa313ef2061bb5c68b5171243a7e21bba356d92 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:14:15 +0100 Subject: [PATCH 07/19] chore: testing runner on docker, working in ci --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d378452b..45711436 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,9 +4,9 @@ on: push: branches: - feat/test-setup - branches-ignore: - - master - - staging +# branches-ignore: +# - master +# - staging pull_request: From 9f5f2b7d0c0e26b001e1009a786920fd3f51861e Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:17:19 +0100 Subject: [PATCH 08/19] chore: testing runner on docker, working in ci --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45711436..180f6e30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,13 @@ jobs: - name: Run tests run: make docker-run-tests + - name: Publish test report + uses: EnricoMi/publish-unit-test-result-action/composite@v2.7 + if: always() + with: + files: | + **/target/reports/**/*.xml + - name: Build image id: docker_build uses: docker/build-push-action@v2 From a83109c3b0aa5628c55af0195f088c673bdb71b3 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:20:20 +0100 Subject: [PATCH 09/19] chore: testing runner on docker, working in ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 180f6e30..bc517714 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: if: always() with: files: | - **/target/reports/**/*.xml + **/target/reports/*.xml - name: Build image id: docker_build From f08d40313628161b37b21cb0bb30344857b4319e Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:24:02 +0100 Subject: [PATCH 10/19] chore: testing runner on docker, working in ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc517714..8b898d1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: if: always() with: files: | - **/target/reports/*.xml + backend/target/reports/*.xml - name: Build image id: docker_build From 9f35330250cdb5917275505a051b1f287a8f13ca Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:27:02 +0100 Subject: [PATCH 11/19] chore: testing runner on docker, working in ci --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.dockerignore b/.dockerignore index 7adad677..e420573a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,3 +9,5 @@ roman.iml frontend/node_modules frontend/build *.iml +!backend/target/surefire-reports +!backend/target/test.result \ No newline at end of file From 8aea5902c729b582fa95c32bd795842e4e9c30c9 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:37:03 +0100 Subject: [PATCH 12/19] chore: testing runner on docker, working in ci --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b898d1d..00a9e758 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,12 +29,18 @@ jobs: - name: Run tests run: make docker-run-tests + - name: Show dir + run: | + ls -la + ls -la backend/target/ + ls -la backend/target/reports/ + - name: Publish test report uses: EnricoMi/publish-unit-test-result-action/composite@v2.7 if: always() with: files: | - backend/target/reports/*.xml + **/reports/TEST-*.xml - name: Build image id: docker_build From f0a88c3ab01acbf794c2171747b4f1f6ce396579 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:39:43 +0100 Subject: [PATCH 13/19] chore: testing runner on docker, working in ci --- .github/workflows/ci.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00a9e758..b41de63c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,18 +29,12 @@ jobs: - name: Run tests run: make docker-run-tests - - name: Show dir - run: | - ls -la - ls -la backend/target/ - ls -la backend/target/reports/ - - name: Publish test report uses: EnricoMi/publish-unit-test-result-action/composite@v2.7 if: always() with: files: | - **/reports/TEST-*.xml + backend/target/reports/reports/TEST-*.xml - name: Build image id: docker_build From 1a12ff2ef82fadc3a0a1d06aa7c50ae79c16e3d6 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:42:37 +0100 Subject: [PATCH 14/19] chore: testing runner on docker, working in ci --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b41de63c..311fd2d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,9 +4,9 @@ on: push: branches: - feat/test-setup -# branches-ignore: -# - master -# - staging + # branches-ignore: + # - master + # - staging pull_request: @@ -34,7 +34,7 @@ jobs: if: always() with: files: | - backend/target/reports/reports/TEST-*.xml + backend/target/reports/TEST-*.xml - name: Build image id: docker_build From bcebe6edd6988180629b003dae252add6726c467 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:47:37 +0100 Subject: [PATCH 15/19] chore: testing runner on docker, working in ci, testing failed test --- .../com/wire/bots/roman/integrations/BroadcastResourceTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java index 79291cb1..395dd68f 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java @@ -61,7 +61,6 @@ public void afterClass() { } @Test - @Disabled("Fix when broadcast is testable") public void broadcastTest() throws InterruptedException { final Random random = new Random(); final UUID botId = UUID.randomUUID(); From 9550cf5a1a26b25578ccc44b2a233bc67ac73974 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:52:31 +0100 Subject: [PATCH 16/19] chore: testing runner on docker, working in ci --- .../com/wire/bots/roman/integrations/BroadcastResourceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java index 395dd68f..79291cb1 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java @@ -61,6 +61,7 @@ public void afterClass() { } @Test + @Disabled("Fix when broadcast is testable") public void broadcastTest() throws InterruptedException { final Random random = new Random(); final UUID botId = UUID.randomUUID(); From 5d777ece52f480baefd1a19cba7cd4e9c7c363e2 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:54:25 +0100 Subject: [PATCH 17/19] chore: testing runner on docker, ci adj --- .github/workflows/ci.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 311fd2d4..f7131e54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,11 +2,9 @@ name: CI on: push: - branches: - - feat/test-setup - # branches-ignore: - # - master - # - staging + branches-ignore: + - master + - staging pull_request: From e4e58fc1cd8c9b204892ffe4ce44bd986cbcb995 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 14:57:47 +0100 Subject: [PATCH 18/19] chore: testing runner on docker, ci adj --- .github/workflows/ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7131e54..9b8e78cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,8 @@ name: CI on: - push: - branches-ignore: - - master - - staging - pull_request: + types: [ opened, synchronize ] concurrency: group: ${{ github.workflow }}-${{ github.ref }} From eb73824c5138c21f1100799707c344b845a2fd6b Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 18 Dec 2023 15:07:01 +0100 Subject: [PATCH 19/19] chore: testing runner on docker, ci adj --- README.md | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 153035f3..2167b1e1 100644 --- a/README.md +++ b/README.md @@ -353,7 +353,7 @@ The best way how to run Roman is to use Docker, another option is to run the Rom - In order to actually being able to connect to the Wire backend, Roman's endpoints needs to run on HTTPS. - You need a PostgreSQL instance with an empty database and credentials. - In order to run it as a Docker container, you need to have Docker installed. -- In order to run it natively on JVM, you need to have JVM 11 installed + all necessary libraries +- In order to run it natively on JVM, you need to have JVM 17 installed + all necessary libraries for [Cryptobox4j](https://github.com/wireapp/cryptobox4j). ### Configuration @@ -455,7 +455,7 @@ env variables. See [Configuration section](#configuration) how to obtain them. As previously mentioned, Wire recommends running the Roman as a docker container. However, you can run it natively on the JVM as well. -Please note that Roman requires JVM >= 11. To run it natively, one needs to +Please note that Roman requires JVM >= 17. To run it natively, one needs to install [Cryptobox4j](https://github.com/wireapp/cryptobox4j) and other cryptographic libraries. You can use [Docker Build Image](https://github.com/wireapp/cryptobox4j/blob/master/dockerfiles/Dockerfile.cryptobox) @@ -464,17 +464,17 @@ as an inspiration what needs to be installed and what environment variables need Also, don't forget to read the [Configuration section](#configuration) and set all necessary environment variables for the Roman itselgf. -First, it is necessary to build the application: +First, it is necessary to build the application under `backend` directory: ```bash -# Maven and JVM 11 is required -mvn package -DskipTests +# Maven and JVM 17 is required +./mvnw package -DskipTests ``` Then to run it like that: ```bash -# JVM 11 required +# JVM 17 required java -jar target/roman.jar server roman.yaml ``` @@ -557,6 +557,20 @@ docker-compose -f docker-compose.prod.yml --env-file .env.prod up -d 10. All set! You can go to `https://roman.example.com/swagger` and start using Roman. +## Running Roman tests suite + +Tests run with the help of docker containers to setup all requirements. +To run the test suite just run: + +```bash +make docker-run-tests +``` + +or directly: +```bash +./test.sh +``` + ## Comprehensive tutorial how to onboard new bot Step-by-step guide, how to create a simple bot for Roman - [onboarding.md](docs/onboarding.md).