From 3ba62901b1f617eb26fe2af86899dcf746c2bf83 Mon Sep 17 00:00:00 2001
From: Joze RIHTARSIC <joze.RIHTARSIC@ext.ec.europa.eu>
Date: Fri, 13 May 2022 18:57:35 +0200
Subject: [PATCH] Add unit tests

---
 smp-docker/images/build-docker-images.sh      |  9 +++++++
 .../images/tomcat-mysql-smp-sml/Dockerfile    |  2 ++
 .../images/tomcat-mysql-smp-sml/README.md     | 24 +++++++++++++++----
 .../images/tomcat-mysql-smp-sml/entrypoint.sh |  6 +++--
 .../edelivery/smp/config/DatabaseConfig.java  |  5 ----
 5 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/smp-docker/images/build-docker-images.sh b/smp-docker/images/build-docker-images.sh
index 174e9bdbd..79753c8ba 100755
--- a/smp-docker/images/build-docker-images.sh
+++ b/smp-docker/images/build-docker-images.sh
@@ -53,6 +53,7 @@ while getopts v:o:s:c:p: option; do
   esac
 done
 
+
 if [[ -z "${SMP_VERSION}" ]]; then
   # get version from setup file
   echo "Get version from the pom: $(pwd)"
@@ -65,11 +66,14 @@ if [[ -z "${SMP_VERSION}" ]]; then
 
 fi
 
+SMP_PLUGIN_EXAMPLE="../../smp-examples/smp-spi-example/target/smp-spi-example-$SMP_VERSION.jar"
+
 DIRNAME=$(dirname "$0")
 cd "$DIRNAME"
 DIRNAME="$(pwd -P)"
 echo "*****************************************************************"
 echo "* SMP artefact folders: $SMP_ARTEFACTS, (Clear folder after build: $SMP_ARTEFACTS_CLEAR )"
+echo "* Plugin example: $SMP_PLUGIN_EXAMPLE "
 echo "* Build SMP image for version $SMP_VERSION"
 echo "* Oracle artefact folders: $ORACLE_ARTEFACTS"
 echo "*****************************************************************"
@@ -151,6 +155,11 @@ validateAndPrepareArtefacts() {
     cp "${SMP_ARTEFACTS}/smp-${SMP_VERSION}-setup.zip" ./tomcat-mysql-smp-sml/artefacts/smp-setup.zip
   fi
 
+  if [[ ! -f "${SMP_PLUGIN_EXAMPLE}" ]]; then
+    echo "SMP SPI plugin  '${SMP_PLUGIN_EXAMPLE}' not found. Skip plugin!"
+  else
+    cp "${SMP_PLUGIN_EXAMPLE}" ./tomcat-mysql-smp-sml/artefacts/smp-spi-example.jar
+  fi
 }
 
 # -----------------------------------------------------------------------------
diff --git a/smp-docker/images/tomcat-mysql-smp-sml/Dockerfile b/smp-docker/images/tomcat-mysql-smp-sml/Dockerfile
index 133ff6156..2429ef129 100755
--- a/smp-docker/images/tomcat-mysql-smp-sml/Dockerfile
+++ b/smp-docker/images/tomcat-mysql-smp-sml/Dockerfile
@@ -132,6 +132,8 @@ RUN unzip /tmp/artefacts/smp-setup.zip -d /tmp/    \
     && mv /tmp/bdmsl-webapp-$SML_VERSION /tmp/sml-setup \
     && cp /tmp/sml-setup/encriptionPrivateKey.private  /opt/smlconf/encriptionPrivateKey.private \
     && cp /tmp/sml-setup/keystore.jks /opt/smlconf/keystore.jk \
+    && mkdir $SMP_HOME/apache-tomcat-$TOMCAT_VERSION/smp-libs \
+    && mv /tmp/artefacts/*.jar $SMP_HOME/apache-tomcat-$TOMCAT_VERSION/smp-libs \
     && chmod u+x /sbin/entrypoint.sh
 
 
diff --git a/smp-docker/images/tomcat-mysql-smp-sml/README.md b/smp-docker/images/tomcat-mysql-smp-sml/README.md
index b923fd6fa..0db205978 100755
--- a/smp-docker/images/tomcat-mysql-smp-sml/README.md
+++ b/smp-docker/images/tomcat-mysql-smp-sml/README.md
@@ -4,12 +4,15 @@ Image uses latest version of eDelivery SMP setup on tomcat, mysql ubuntu
 
 # Image build
 
-docker build -t smp .
+    docker build -t smp .
 
 # Run container based on smp image
-docker run --name smp -it --rm -p [http-port]:8080 -v [local volume]:/data smp
+  
+    docker run --name smp -it --rm -p [http-port]:8080  edelivery-docker.devops.tech.ec.europa.eu/edeliverytest/smp-sml-tomcat-mysql
+
 example:
-docker run --name smp --rm -it -p 8080:8080 -v  /opt/dockerdata/smp:/data smp smp
+
+    docker run --name smp --rm -it -p 8080:8080  edelivery-docker.devops.tech.ec.europa.eu/edeliverytest/smp-sml-tomcat-mysql:4.2-SNAPSHOT
 
 ## SMP (param: -p 8080:8080 )
 url: http://localhost:8080/smp
@@ -20,9 +23,22 @@ url: jdbc:mysql://localhost:3306/smp
 Username: smp
 Password: smp
 
-## Volume (-v /opt/dockerdata/sml:/data)
+## Volume (-v /opt/docker-data/smp:/data)
 Mysql database files and tomcat configuration (and logs) can be externalized for experimenting with different SMP settings.
 
+    docker run --name smp --rm -it -p 8080:8080  -v /opt/docker-data/smp:/data edelivery-docker.devops.tech.ec.europa.eu/edeliverytest/smp-sml-tomcat-mysql:4.2-SNAPSHOT
+
+# Start docker with pre-init data  
+1. copy init sql script to folder (create folder)
+  
+    ./db-scripts
+
+example:
+        
+    curl -k https://ec.europa.eu/digital-building-blocks/code/projects/EDELIVERY/repos/smp/raw/smp-soapui-tests/groovy/mysql-4.1_integration_test_data.sql?at=refs%2Fheads%2Fdevelopment --output ./db-scripts/mysql5innodb-data.sql
+
+Then start the docker as:
 
+    docker run --name smp --rm -it -p 8080:8080  -v - db-scripts:/tmp/custom-data/ edelivery-docker.devops.tech.ec.europa.eu/edeliverytest/smp-sml-tomcat-mysql:4.2-SNAPSHOT 
 
 
diff --git a/smp-docker/images/tomcat-mysql-smp-sml/entrypoint.sh b/smp-docker/images/tomcat-mysql-smp-sml/entrypoint.sh
index 7a4a0f4de..d34689053 100755
--- a/smp-docker/images/tomcat-mysql-smp-sml/entrypoint.sh
+++ b/smp-docker/images/tomcat-mysql-smp-sml/entrypoint.sh
@@ -83,6 +83,8 @@ init_smp_properties() {
     echo "[INFO] init smp properties:"
 
     { echo "# SMP init parameters"
+      echo "libraries.folder=$SMP_HOME/apache-tomcat-$TOMCAT_VERSION/smp-libs"
+      echo "bdmsl.integration.logical.address=${SMP_LOGICAL_ADDRESS:-http://localhost:8080/smp/}"
       echo "authentication.blueCoat.enabled=true"
       echo "bdmsl.integration.enabled=true"
       echo "bdmsl.integration.physical.address=0.0.0.0"
@@ -202,8 +204,8 @@ addOrReplaceProperties() {
     for property in "${array[@]}"; do
       read -r key value <<<"$property"
       # escape regex chars and remove trailing and leading spaces..
-      keyRE="$(printf '%s' "${key// }" | sed 's/[.[\*^$()+?{|]/\\&/g')"
-      propertyRE="$(printf '%s' "${property// }" | sed 's/[.[\*^$()+?{|/]/\\&/g')"
+      keyRE="$(printf '%s' "${key// }" | sed 's/[[\*^$()+?{|]/\\&/g')"
+      propertyRE="$(printf '%s' "${property// }" | sed 's/[[\*^$()+?{|/]/\\&/g')"
 
       echo "replace or add property: [$keyRE] with value [$propertyRE]"
       # replace key line and commented #key line with new property
diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/DatabaseConfig.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/DatabaseConfig.java
index 353730246..69ac211a8 100644
--- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/DatabaseConfig.java
+++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/DatabaseConfig.java
@@ -13,13 +13,10 @@
 
 package eu.europa.ec.edelivery.smp.config;
 
-import eu.europa.ec.edelivery.smp.exceptions.ErrorCode;
 import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
 import eu.europa.ec.edelivery.smp.logging.SMPLogger;
 import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory;
-import eu.europa.ec.edelivery.smp.utils.ExtLibraryClassLoader;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
@@ -36,8 +33,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 import javax.naming.NamingException;
 import javax.persistence.EntityManagerFactory;
 import javax.sql.DataSource;
-import java.io.File;
-import java.net.MalformedURLException;
 import java.util.Properties;
 
 import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.INTERNAL_ERROR;
-- 
GitLab