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

Used embedded databases for testing

parent 230ab9d9
No related branches found
No related tags found
No related merge requests found
Pipeline #1094 passed
stages:
- build
- test
build: 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" stage: build
tags:
- docker
image: maven:3.6.3-openjdk-14
script:
- cp config.properties.example config.properties
- ./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-bom
- mvn clean install
- cd ../TASMAN-core
- mvn clean install
...@@ -14,9 +14,7 @@ See also the [CHANGELOG](CHANGELOG.md). ...@@ -14,9 +14,7 @@ See also the [CHANGELOG](CHANGELOG.md).
2. `chmod +x build.sh` 2. `chmod +x build.sh`
3. `./build.sh <command>`, commands are: 3. `./build.sh <command>`, commands are:
* **core** build only TASMAN core * **core** build only TASMAN core
* **test**: run tests; you need to create a `test.properties` file containing a configuration for connecting to a MySQL and a Postgres test database * **test**: run tests
* MySQL testing database needs to have `default-storage-engine = innodb` configured into `/etc/my.cnf`
* Postgres 9.3+ is required
* **glassfish**: build GlassFish war package * **glassfish**: build GlassFish war package
* **tomcat**: build Tomcat war package (using config.properties file) * **tomcat**: build Tomcat war package (using config.properties file)
* **embedded**: build embedded package (to be run _locally!_) * **embedded**: build embedded package (to be run _locally!_)
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
<maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.target>1.7</maven.compiler.target>
<netbeans.hint.license>inaf-license-netbeans</netbeans.hint.license> <netbeans.hint.license>inaf-license-netbeans</netbeans.hint.license>
<maven.test.skip>true</maven.test.skip>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
<artifactId>tasman-core</artifactId> <artifactId>tasman-core</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties>
<zonky.postgres-binaries.version>12.5.0</zonky.postgres-binaries.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.tomcat</groupId> <groupId>org.apache.tomcat</groupId>
...@@ -34,6 +38,19 @@ ...@@ -34,6 +38,19 @@
<version>9.3-1104-jdbc41</version> <version>9.3-1104-jdbc41</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </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> </dependencies>
<profiles> <profiles>
...@@ -57,18 +74,64 @@ ...@@ -57,18 +74,64 @@
</dependencies> </dependencies>
</profile> </profile>
<profile> <profile>
<id>test</id> <id>platform-linux</id>
<properties> <activation>
<maven.test.skip>false</maven.test.skip> <os>
</properties> <family>unix</family>
<build> </os>
<testResources> </activation>
<testResource> <dependencies>
<directory>src/test/resources</directory> <dependency>
<filtering>true</filtering> <groupId>io.zonky.test.postgres</groupId>
</testResource> <artifactId>embedded-postgres-binaries-linux-amd64</artifactId>
</testResources> <version>${zonky.postgres-binaries.version}</version>
</build> <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> </profile>
</profiles> </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> </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; ...@@ -28,8 +28,6 @@ import it.inaf.ia2.tsm.datalayer.Credentials;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.sql.Connection; import java.sql.Connection;
...@@ -39,7 +37,6 @@ import java.sql.Statement; ...@@ -39,7 +37,6 @@ import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
...@@ -68,29 +65,15 @@ public class TestAll { ...@@ -68,29 +65,15 @@ public class TestAll {
} }
@BeforeClass @BeforeClass
public static void setUpClass() throws SQLException, IOException { public static void setUpClass() throws Exception {
Properties props = new Properties();
try (InputStream in = TestAll.class.getClassLoader().getResourceAsStream("test.properties")) {
props.load(in);
}
dbWrappers = new ArrayList<>(); dbWrappers = new ArrayList<>();
// MYSQL // MYSQL
Credentials mysqlCredentials = new Credentials(DatabaseType.MYSQL); Credentials mysqlCredentials = EmbeddedDatabases.mariadbCredentials();
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"));
// POSTGRES // POSTGRES
Credentials postgresCredentials = new Credentials(DatabaseType.POSTGRES); Credentials postgresCredentials = EmbeddedDatabases.postgresCredentials();
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"));
DBWrapper dbWrapper = new DBWrapper(mysqlCredentials); DBWrapper dbWrapper = new DBWrapper(mysqlCredentials);
dbWrapper.testConnections(); dbWrapper.testConnections();
......
#!/bin/bash #!/bin/bash
config_file="config.properties" config_file="config.properties"
test_config_file="test.properties"
if [ ! -f "$config_file" ]; then if [ ! -f "$config_file" ]; then
echo "$config_file doesn't exist!" echo "$config_file doesn't exist!"
...@@ -27,7 +26,7 @@ function build_core { ...@@ -27,7 +26,7 @@ function build_core {
cd TASMAN-bom cd TASMAN-bom
mvn -q clean install mvn -q clean install
cd ../TASMAN-core cd ../TASMAN-core
mvn -q clean install mvn -q clean install -DskipTests
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}" echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1 exit 1
...@@ -40,7 +39,7 @@ function test_core { ...@@ -40,7 +39,7 @@ function test_core {
cd TASMAN-bom cd TASMAN-bom
mvn -q clean install mvn -q clean install
cd ../TASMAN-core cd ../TASMAN-core
$(add_properties "mvn clean install -P test" $test_config_file) mvn clean install
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}" echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1 exit 1
...@@ -53,7 +52,7 @@ function build_web_glassfish { ...@@ -53,7 +52,7 @@ function build_web_glassfish {
# build webapp # build webapp
cd TASMAN-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 if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}" echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1 exit 1
...@@ -67,7 +66,7 @@ function build_web_tomcat { ...@@ -67,7 +66,7 @@ function build_web_tomcat {
# build webapp # build webapp
cd TASMAN-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 if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}" echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1 exit 1
...@@ -81,7 +80,7 @@ function build_web_embedded { ...@@ -81,7 +80,7 @@ function build_web_embedded {
# build webapp # build webapp
cd TASMAN-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 if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}" echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1 exit 1
...@@ -93,7 +92,7 @@ function build_web_embedded { ...@@ -93,7 +92,7 @@ function build_web_embedded {
cd TASMAN-embedded cd TASMAN-embedded
war_file_path=`dirname ${PWD}`/TASMAN-webapp/target/tasman-webapp-*.war war_file_path=`dirname ${PWD}`/TASMAN-webapp/target/tasman-webapp-*.war
war_file_path=`ls $war_file_path` 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 if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}" echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1 exit 1
...@@ -107,7 +106,7 @@ function build_installer_package { ...@@ -107,7 +106,7 @@ function build_installer_package {
# build webapp # build webapp
cd TASMAN-webapp cd TASMAN-webapp
mvn -q clean install -P ServletContainer,Jetty mvn -q clean install -DskipTests -P ServletContainer,Jetty
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}" echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1 exit 1
...@@ -117,7 +116,7 @@ function build_installer_package { ...@@ -117,7 +116,7 @@ function build_installer_package {
# build embedded # build embedded
cd TASMAN-embedded cd TASMAN-embedded
mvn -q clean install mvn -q clean install -DskipTests
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "[ERROR] Error in ${FUNCNAME[0]}" echo "[ERROR] Error in ${FUNCNAME[0]}"
exit 1 exit 1
...@@ -162,10 +161,6 @@ case "$1" in ...@@ -162,10 +161,6 @@ case "$1" in
build_core build_core
;; ;;
"test") "test")
if [ ! -f "$test_config_file" ]; then
echo "$test_config_file doesn't exist!"
exit 1
fi
test_core test_core
;; ;;
"glassfish") "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