Skip to content

Commit

Permalink
Feature/134 update junit (#168)
Browse files Browse the repository at this point in the history
* wip: update junit4 to junit5

Signed-off-by: Daniel Kubányi <[email protected]>

* wip: update junit4 to junit5

Signed-off-by: Daniel Kubányi <[email protected]>

* wip: update junit4 to junit5

Signed-off-by: Daniel Kubányi <[email protected]>

* wip: update junit4 to junit5

Signed-off-by: Daniel Kubányi <[email protected]>

* wip: update junit4 to junit5

Signed-off-by: Daniel Kubányi <[email protected]>

* chore: cleanup

Signed-off-by: Daniel Kubányi <[email protected]>

* fix: jarTest

Signed-off-by: Daniel Kubányi <[email protected]>

* fix: PublisherStepDb2LocalTest

* feat: use junit5 in integration tests

---------

Signed-off-by: Daniel Kubányi <[email protected]>
  • Loading branch information
dkubanyi authored Aug 26, 2024
1 parent 48c80c3 commit 35bc50e
Show file tree
Hide file tree
Showing 83 changed files with 1,449 additions and 1,515 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ If you want to do some further testing with standalone jobs or use the plugin on
Debugging the Docker image tests can be harder than debugging unit and jar tests. The `docker run` / `start-gretl.sh` command is printed on the console when the test is running. Use this command to run the test in the console manually. Most probably you will get more information.

### Unit tests
Unit tests with "heavy" dependencies like PostgreSQL are categorized (`ch.so.agi.gretl.testutil.DbTest`) and can be run with `./gradlew gretl:dbTest`. This will manage the PostgreSQL database with the [Testcontainers framework](https://www.testcontainers.org) . Testcontainers start a docker container before every test method or every test class.

Unit tests with "heavy" dependencies like PostgreSQL are categorized (`ch.so.agi.gretl.testutil.TestTags.DB_TEST`) and
can be run with `./gradlew gretl:dbTest`. This will manage the PostgreSQL database with
the [Testcontainers framework](https://www.testcontainers.org) . Testcontainers start a docker container before every
test method or every test class.

### Integration tests
The integrations are used for testing the resulting Jar file (`jarTest`) and the Docker image (`imageTest`).
Expand Down
8 changes: 6 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ sqliteJdbcVersion = "3.8.11.2"
derbyVersion = "10.13.1.1"
oracleVersion = "19.3.0.0"
duckdbVersion = "0.9.2"
junitVersion = "4.12"
junitVersion = "5.10.3"
junitTestContainersVersion = "1.19.8"
mockFtpServerVersion = "2.7.1"
mockWebServerVersion = "4.11.0"
testContainersVersion = "1.15.3"
Expand Down Expand Up @@ -71,7 +72,10 @@ sqlite-jdbc = {group = "org.xerial", name = "sqlite-jdbc", version.ref = "sqlite
derby = {group = "org.apache.derby", name = "derby", version.ref = "derbyVersion"}
oracle = { group = "com.oracle.ojdbc", name = "ojdbc8", version.ref = "oracleVersion"}
duckdb = { group = "org.duckdb", name = "duckdb_jdbc", version.ref = "duckdbVersion"}
junit = { group = "junit", name = "junit", version.ref = "junitVersion" }
junit = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junitVersion" }
junitEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junitVersion" }
junitTestContainers = { group = "org.testcontainers", name = "junit-jupiter", version.ref = "junitTestContainersVersion" }
junitTestContainersPostgres = { group = "org.testcontainers", name = "postgresql", version.ref = "junitTestContainersVersion" }
mock-ftp-server = { group = "org.mockftpserver", name = "MockFtpServer", version.ref = "mockFtpServerVersion" }
mock-web-server = { group = "com.squareup.okhttp3", name ="mockwebserver", version.ref = "mockWebServerVersion"}
test-containers-base = { group = "org.testcontainers", name = "testcontainers", version.ref = "testContainersVersion"}
Expand Down
50 changes: 26 additions & 24 deletions gretl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ configurations.all {
}

Properties properties = new Properties()
File propFile=project.file('user.properties')
if(propFile.exists()){
File propFile = project.file('user.properties')
if (propFile.exists()){
properties.load(propFile.newDataInputStream())
}
def dburl = System.getProperty('dburl',properties.get('dburl'))
def dbusr = System.getProperty('dbusr',properties.get('dbusr'))
def dbpwd = System.getProperty('dbpwd',properties.get('dbpwd'))
def ftpurl = System.getProperty('ftpurl',properties.get('ftpurl'))
def ftpusr = System.getProperty('ftpusr',properties.get('ftpusr'))
def ftppwd = System.getProperty('ftppwd',properties.get('ftppwd'))
def dburl = System.getProperty('dburl', properties.get('dburl'))
def dbusr = System.getProperty('dbusr', properties.get('dbusr'))
def dbpwd = System.getProperty('dbpwd', properties.get('dbpwd'))
def ftpurl = System.getProperty('ftpurl', properties.get('ftpurl'))
def ftpusr = System.getProperty('ftpusr', properties.get('ftpusr'))
def ftppwd = System.getProperty('ftppwd', properties.get('ftppwd'))

configurations.all {
resolutionStrategy {
Expand Down Expand Up @@ -110,14 +110,18 @@ dependencies {
api libs.freemarker

api libs.sftp.fs

runtimeOnly libs.postgresql
runtimeOnly libs.sqlite.jdbc
runtimeOnly libs.derby
runtimeOnly libs.duckdb
runtimeOnly libs.oracle

testImplementation libs.junit
testImplementation libs.junitTestContainers
testImplementation libs.junitTestContainersPostgres
testRuntimeOnly libs.junitEngine

testImplementation libs.test.containers.base
testImplementation libs.test.containers.postgresql

Expand Down Expand Up @@ -154,7 +158,7 @@ pluginBundle {
}
}

tasks.register('setupPluginUpload'){
tasks.register('setupPluginUpload') {
description = "Converts Gradle plugin publish key and secret from environment variable to system property. (Workaround)"
doLast {
def key=System.env.gradlePublishKey
Expand All @@ -174,43 +178,41 @@ tasks.publishPlugins.dependsOn tasks.setupPluginUpload

test {
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
useJUnit{
useJUnitPlatform {
// Exclude all Tests with dependency to a db server (pg, oracle, ..)
excludeCategories 'ch.so.agi.gretl.testutil.DbTest'
excludeCategories 'ch.so.agi.gretl.testutil.SftpTest'
excludeCategories 'ch.so.agi.gretl.testutil.S3Test'
excludeTags 'dbTest', 'sftpTest', 's3Test'
}
}

tasks.register('dbTest', Test){
tasks.register('dbTest', Test) {
dependsOn 'compileJava', 'compileTestJava'
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = 'Runs all unit tests with dependency to a db server (pg, oracle, ...).'
useJUnit {
includeCategories 'ch.so.agi.gretl.testutil.DbTest'
useJUnitPlatform {
includeTags 'dbTest'
}
}

tasks.register('sftpTest', Test){
tasks.register('sftpTest', Test) {
dependsOn 'compileJava', 'compileTestJava'
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = 'Runs all unit tests with dependency to a SFTP server'
useJUnit {
includeCategories 'ch.so.agi.gretl.testutil.SftpTest'
useJUnitPlatform {
includeTags 'sftpTest'
}
}

def s3AccessKey = System.getProperty('s3AccessKey',properties.get('s3AccessKey'))
def s3SecretKey = System.getProperty('s3SecretKey',properties.get('s3SecretKey'))
def s3BucketName = System.getProperty('s3BucketName',properties.get('s3BucketName'))

tasks.register('s3Test', Test){
tasks.register('s3Test', Test) {
dependsOn 'compileJava', 'compileTestJava'
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = 'Runs all unit tests with dependency to AWS S3.'

useJUnit {
includeCategories 'ch.so.agi.gretl.testutil.S3Test'
useJUnitPlatform {
includeTags 's3Test'
}
}

Expand Down
25 changes: 12 additions & 13 deletions gretl/integration-test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ sourceSets {
* Task for executing the integration tests. It references the
* classes and runtime classpath of the integration test source set.
*/
tasks.register('jarTest', Test){
tasks.register('jarTest', Test) {
description = 'Runs integration tests against the installed gretl jar.'
group = LifecycleBasePlugin.VERIFICATION_GROUP

useJUnit {
excludeCategories 'ch.so.agi.gretl.testutil.QgisReachableTest'
excludeCategories 'ch.so.agi.gretl.testutil.S3Test'
useJUnitPlatform {
excludeTags 'qgisReachableTest', 's3Test'
}

systemProperty('GRETL_TESTTYPE', 'jar')
Expand All @@ -41,12 +40,12 @@ tasks.register('jarTest', Test){
jvmArgs '-Xmx1g'
}

tasks.register('jarS3Test', Test){
tasks.register('jarS3Test', Test) {
description = 'Runs the S3 integration tests against the installed gretl jar.'
group = LifecycleBasePlugin.VERIFICATION_GROUP

useJUnit {
includeCategories 'ch.so.agi.gretl.testutil.S3Test'
useJUnitPlatform {
includeTags 's3Test'
}

systemProperty('GRETL_TESTTYPE', 'jar')
Expand All @@ -58,12 +57,12 @@ tasks.register('jarS3Test', Test){
jvmArgs '-Xmx1g'
}

tasks.register('imageTest', Test){
tasks.register('imageTest', Test) {
description = 'Runs integration tests against the installed gretl docker image.'
group = LifecycleBasePlugin.VERIFICATION_GROUP

useJUnit {
excludeCategories 'ch.so.agi.gretl.testutil.S3Test'
useJUnitPlatform {
excludeTags 's3Test'
}

systemProperty('GRETL_TESTTYPE', 'image')
Expand All @@ -74,12 +73,12 @@ tasks.register('imageTest', Test){
classpath += sourceSets.integrationTest.runtimeClasspath
}

tasks.register('imageS3Test', Test){
tasks.register('imageS3Test', Test) {
description = 'Runs S3 integration tests against the installed gretl docker image.'
group = LifecycleBasePlugin.VERIFICATION_GROUP

useJUnit {
includeCategories 'ch.so.agi.gretl.testutil.S3Test'
useJUnitPlatform {
includeTags 's3Test'
}

systemProperty('GRETL_TESTTYPE', 'image')
Expand Down
18 changes: 8 additions & 10 deletions gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2chTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package ch.so.agi.gretl.jobs;

import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import ch.so.agi.gretl.util.GradleVariable;
import ch.so.agi.gretl.util.IntegrationTestUtil;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.junit.Test;

import ch.so.agi.gretl.util.GradleVariable;
import ch.so.agi.gretl.util.IntegrationTestUtil;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class Av2chTest {
@Test
Expand All @@ -23,10 +22,9 @@ public void transformation_Ok() throws Exception {
File resultFile = new File("src/integrationTest/jobs/Av2ch/output/254900.itf");

long resultSize = resultFile.length();
assertTrue("Size of result file is wrong.", resultSize > 580000);
assertTrue(resultSize > 580000, "Size of result file is wrong.");

String resultString = new String(Files.readAllBytes(resultFile.toPath()), StandardCharsets.ISO_8859_1);

assertThat(resultString, containsString("DM01 Interlis Converter"));
assertThat(resultString, containsString("MODL DM01AVCH24LV95D"));
assertThat(resultString, containsString("TABL LFP3Nachfuehrung"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import ch.so.agi.gretl.util.GradleVariable;
import ch.so.agi.gretl.util.IntegrationTestUtil;
import org.junit.Test;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

import java.io.File;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class Av2geobauTest {
@Test
public void simple() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package ch.so.agi.gretl.jobs;

import static org.junit.Assert.assertEquals;

import java.io.FileInputStream;
import java.nio.file.Paths;

import ch.so.agi.gretl.util.GradleVariable;
import ch.so.agi.gretl.util.IntegrationTestUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import ch.so.agi.gretl.util.GradleVariable;
import ch.so.agi.gretl.util.IntegrationTestUtil;
import java.io.FileInputStream;
import java.nio.file.Paths;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Csv2ExcelTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package ch.so.agi.gretl.jobs;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.nio.file.Paths;

import ch.so.agi.gretl.util.GradleVariable;
import ch.so.agi.gretl.util.IntegrationTestUtil;
import org.apache.avro.generic.GenericRecord;
import org.apache.hadoop.conf.Configuration;
import org.apache.parquet.avro.AvroParquetReader;
import org.apache.parquet.hadoop.ParquetReader;
import org.apache.parquet.hadoop.util.HadoopInputFile;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import ch.so.agi.gretl.util.GradleVariable;
import ch.so.agi.gretl.util.IntegrationTestUtil;
import java.nio.file.Paths;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Csv2ParquetTest {
private static final Configuration testConf = new Configuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
import ch.so.agi.gretl.util.GradleVariable;
import ch.so.agi.gretl.util.IntegrationTestUtil;
import ch.so.agi.gretl.util.IntegrationTestUtilSql;

import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.PostgisContainerProvider;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.wait.strategy.Wait;

import static org.junit.Assert.*;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.io.File;
import java.sql.Connection;
import java.sql.Statement;

import static org.junit.jupiter.api.Assertions.assertEquals;

@Testcontainers
public class CsvExportTest {

@ClassRule
public static PostgreSQLContainer postgres =
(PostgreSQLContainer) new PostgisContainerProvider()
.newInstance().withDatabaseName("gretl")
.withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER)
.withInitScript("init_postgresql.sql")
.waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2));
@Container
public static PostgreSQLContainer<?> postgres =
(PostgreSQLContainer<?>) new PostgisContainerProvider().newInstance()
.withDatabaseName("gretl")
.withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER)
.withInitScript("init_postgresql.sql")
.waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2));

@Test
public void exportOk() throws Exception {
Expand Down
Loading

0 comments on commit 35bc50e

Please sign in to comment.