Skip to content
Snippets Groups Projects
Commit 4e84bcff authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Used embedded databases for testing

parent 230ab9d9
Branches
Tags
No related merge requests found
Pipeline #1089 failed
stages:
- build
- test
build:
script: "cd TASMAN-bom; mvn clean install; cd ../TASMAN-core; mvn clean install -P Test -Dmysql_host=localhost -Dmysql_port=3306 -Dmysql_user=tasman_tester -D mysql_password=tasman_tester -Dpostgres_host=localhost -Dpostgres_port=5432 -Dpostgres_user=tasman_tester -Dpostgres_password=tasman_tester -Dpostgres_database=tasman_test"
tags:
- docker
image: maven:3.6.3-openjdk-14
script: "./build.sh embedded"
test_backend:
stage: test
tags:
- docker
image: git.ia2.inaf.it:5050/ia2/ia2-devops/maven-otj-pg-embedded
script: "cd TASMAN-core; mvn clean install"
......@@ -13,7 +13,6 @@
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<netbeans.hint.license>inaf-license-netbeans</netbeans.hint.license>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencyManagement>
......
......@@ -11,6 +11,10 @@
<artifactId>tasman-core</artifactId>
<packaging>jar</packaging>
<properties>
<zonky.postgres-binaries.version>12.5.0</zonky.postgres-binaries.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
......@@ -34,6 +38,19 @@
<version>9.3-1104-jdbc41</version>
<scope>runtime</scope>
</dependency>
<!-- Embedded testing databases -->
<dependency>
<groupId>ch.vorburger.mariaDB4j</groupId>
<artifactId>mariaDB4j</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.opentable.components</groupId>
<artifactId>otj-pg-embedded</artifactId>
<version>0.13.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
......@@ -57,18 +74,64 @@
</dependencies>
</profile>
<profile>
<id>test</id>
<properties>
<maven.test.skip>false</maven.test.skip>
</properties>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
<id>platform-linux</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>io.zonky.test.postgres</groupId>
<artifactId>embedded-postgres-binaries-linux-amd64</artifactId>
<version>${zonky.postgres-binaries.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>platform-windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>io.zonky.test.postgres</groupId>
<artifactId>embedded-postgres-binaries-windows-amd64</artifactId>
<version>${zonky.postgres-binaries.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package it.inaf.ia2.tsm;
import ch.vorburger.mariadb4j.DB;
import ch.vorburger.mariadb4j.DBConfigurationBuilder;
import com.opentable.db.postgres.embedded.UncompressBundleDirectoryResolver;
import com.opentable.db.postgres.embedded.EmbeddedPostgres;
import com.opentable.db.postgres.embedded.PgBinaryResolver;
import it.inaf.ia2.tsm.datalayer.Credentials;
import it.inaf.ia2.tsm.datalayer.DatabaseType;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.core.io.ClassPathResource;
public class EmbeddedDatabases {
public static Credentials mariadbCredentials() throws Exception {
DBConfigurationBuilder configBuilder = DBConfigurationBuilder.newBuilder();
DB db = DB.newEmbeddedDB(configBuilder.build());
db.start();
Credentials mysqlCredentials = new Credentials(DatabaseType.MYSQL);
mysqlCredentials.setHostname("127.0.0.1");
mysqlCredentials.setPort(configBuilder.getPort());
mysqlCredentials.setUsername("root");
mysqlCredentials.setPassword("");
return mysqlCredentials;
}
public static Credentials postgresCredentials() throws Exception {
EmbeddedPostgres embeddedPg = EmbeddedPostgres.builder()
.setPgDirectoryResolver(new UncompressBundleDirectoryResolver(new CustomPostgresBinaryResolver()))
.start();
Credentials postgresCredentials = new Credentials(DatabaseType.POSTGRES);
postgresCredentials.setHostname("127.0.0.1");
postgresCredentials.setPort(embeddedPg.getPort());
postgresCredentials.setUsername("postgres");
postgresCredentials.setPassword("");
postgresCredentials.setDatabase("postgres");
return postgresCredentials;
}
private static class CustomPostgresBinaryResolver implements PgBinaryResolver {
/**
* Loads specific embedded Postgres version.
*/
@Override
public InputStream getPgBinary(String system, String architecture) throws IOException {
ClassPathResource resource = new ClassPathResource(String.format("postgres-%s-%s.txz", system.toLowerCase(), architecture));
return resource.getInputStream();
}
}
}
......@@ -28,8 +28,6 @@ import it.inaf.ia2.tsm.datalayer.Credentials;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
......@@ -39,7 +37,6 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import org.junit.After;
import org.junit.AfterClass;
......@@ -68,29 +65,15 @@ public class TestAll {
}
@BeforeClass
public static void setUpClass() throws SQLException, IOException {
Properties props = new Properties();
try (InputStream in = TestAll.class.getClassLoader().getResourceAsStream("test.properties")) {
props.load(in);
}
public static void setUpClass() throws Exception {
dbWrappers = new ArrayList<>();
// MYSQL
Credentials mysqlCredentials = new Credentials(DatabaseType.MYSQL);
mysqlCredentials.setHostname(props.getProperty("mysql_host"));
mysqlCredentials.setPort(Integer.parseInt(props.getProperty("mysql_port")));
mysqlCredentials.setUsername(props.getProperty("mysql_user"));
mysqlCredentials.setPassword(props.getProperty("mysql_password"));
Credentials mysqlCredentials = EmbeddedDatabases.mariadbCredentials();
// POSTGRES
Credentials postgresCredentials = new Credentials(DatabaseType.POSTGRES);
postgresCredentials.setHostname(props.getProperty("postgres_host"));
postgresCredentials.setPort(Integer.parseInt(props.getProperty("postgres_port")));
postgresCredentials.setUsername(props.getProperty("postgres_user"));
postgresCredentials.setPassword(props.getProperty("postgres_password"));
postgresCredentials.setDatabase(props.getProperty("postgres_database"));
Credentials postgresCredentials = EmbeddedDatabases.postgresCredentials();
DBWrapper dbWrapper = new DBWrapper(mysqlCredentials);
dbWrapper.testConnections();
......
#!/bin/bash
config_file="config.properties"
test_config_file="test.properties"
if [ ! -f "$config_file" ]; then
echo "$config_file doesn't exist!"
......@@ -27,7 +26,7 @@ function build_core {
cd TASMAN-bom
mvn -q clean install
cd ../TASMAN-core
mvn -q clean install
mvn -q clean install -DskipTests
if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1
......@@ -40,7 +39,7 @@ function test_core {
cd TASMAN-bom
mvn -q clean install
cd ../TASMAN-core
$(add_properties "mvn clean install -P test" $test_config_file)
mvn clean install
if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1
......@@ -53,7 +52,7 @@ function build_web_glassfish {
# build webapp
cd TASMAN-webapp
$(add_properties "mvn -q clean install" $config_file)
$(add_properties "mvn -q clean install -DskipTests" $config_file)
if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1
......@@ -67,7 +66,7 @@ function build_web_tomcat {
# build webapp
cd TASMAN-webapp
$(add_properties "mvn -q clean install -P ServletContainer" $config_file)
$(add_properties "mvn -q clean install -DskipTests -P ServletContainer" $config_file)
if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1
......@@ -81,7 +80,7 @@ function build_web_embedded {
# build webapp
cd TASMAN-webapp
$(add_properties "mvn -q clean install -P ServletContainer,Jetty" $config_file)
$(add_properties "mvn -q clean install -DskipTests -P ServletContainer,Jetty" $config_file)
if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1
......@@ -93,7 +92,7 @@ function build_web_embedded {
cd TASMAN-embedded
war_file_path=`dirname ${PWD}`/TASMAN-webapp/target/tasman-webapp-*.war
war_file_path=`ls $war_file_path`
mvn clean -q install -Dwar_file_path=$war_file_path
mvn clean -q install -DskipTests -Dwar_file_path=$war_file_path
if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1
......@@ -107,7 +106,7 @@ function build_installer_package {
# build webapp
cd TASMAN-webapp
mvn -q clean install -P ServletContainer,Jetty
mvn -q clean install -DskipTests -P ServletContainer,Jetty
if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1
......@@ -117,7 +116,7 @@ function build_installer_package {
# build embedded
cd TASMAN-embedded
mvn -q clean install
mvn -q clean install -DskipTests
if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1
......@@ -162,10 +161,6 @@ case "$1" in
build_core
;;
"test")
if [ ! -f "$test_config_file" ]; then
echo "$test_config_file doesn't exist!"
exit 1
fi
test_core
;;
"glassfish")
......
# MySQL test database
mysql_host=localhost
mysql_port=3306
mysql_user=
mysql_password=
# Postgres test database
postgres_host=localhost
postgres_port=5432
postgres_user=
postgres_password=
postgres_database=
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment