From 35bc50ef0d5b664bcae7e10f971f252a6751b81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kub=C3=A1nyi?= Date: Mon, 26 Aug 2024 07:05:44 +0200 Subject: [PATCH] Feature/134 update junit (#168) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * wip: update junit4 to junit5 Signed-off-by: Daniel Kubányi * wip: update junit4 to junit5 Signed-off-by: Daniel Kubányi * wip: update junit4 to junit5 Signed-off-by: Daniel Kubányi * wip: update junit4 to junit5 Signed-off-by: Daniel Kubányi * wip: update junit4 to junit5 Signed-off-by: Daniel Kubányi * chore: cleanup Signed-off-by: Daniel Kubányi * fix: jarTest Signed-off-by: Daniel Kubányi * fix: PublisherStepDb2LocalTest * feat: use junit5 in integration tests --------- Signed-off-by: Daniel Kubányi --- README.md | 6 +- gradle/libs.versions.toml | 8 +- gretl/build.gradle | 50 ++-- gretl/integration-test.gradle | 25 +- .../java/ch/so/agi/gretl/jobs/Av2chTest.java | 18 +- .../ch/so/agi/gretl/jobs/Av2geobauTest.java | 6 +- .../ch/so/agi/gretl/jobs/Csv2ExcelTest.java | 14 +- .../ch/so/agi/gretl/jobs/Csv2ParquetTest.java | 12 +- .../ch/so/agi/gretl/jobs/CsvExportTest.java | 26 +- .../ch/so/agi/gretl/jobs/CsvImportTest.java | 29 +- .../so/agi/gretl/jobs/CsvValidatorTest.java | 5 +- .../java/ch/so/agi/gretl/jobs/CurlTest.java | 51 ++-- .../jobs/DatabaseDocumentExportTest.java | 33 +-- .../ch/so/agi/gretl/jobs/Db2DbTaskTest.java | 80 +++--- .../agi/gretl/jobs/DbDriverContainedTest.java | 18 +- .../ch/so/agi/gretl/jobs/Gpkg2DxfTest.java | 10 +- .../ch/so/agi/gretl/jobs/Gpkg2ShpTest.java | 16 +- .../ch/so/agi/gretl/jobs/GpkgExportTest.java | 35 ++- .../ch/so/agi/gretl/jobs/GpkgImportTest.java | 27 +- .../so/agi/gretl/jobs/GpkgValidatorTest.java | 7 +- .../java/ch/so/agi/gretl/jobs/GzipTest.java | 13 +- .../so/agi/gretl/jobs/Ili2gpkgImportTest.java | 20 +- .../gretl/jobs/Ili2pgDeleteDatasetsTest.java | 43 +-- .../so/agi/gretl/jobs/Ili2pgDeleteTest.java | 53 ++-- .../gretl/jobs/Ili2pgExportDatasetsTest.java | 56 ++-- .../gretl/jobs/Ili2pgImportFileSetTest.java | 43 +-- .../gretl/jobs/Ili2pgImportSchemaTest.java | 44 ++- .../agi/gretl/jobs/Ili2pgReplaceFileTest.java | 46 ++- .../gretl/jobs/Ili2pgValidateDatasetTest.java | 38 +-- .../so/agi/gretl/jobs/Ili2pgValidateTest.java | 38 +-- .../so/agi/gretl/jobs/IliValidatorTest.java | 6 +- .../ch/so/agi/gretl/jobs/JsonImportTest.java | 52 ++-- .../so/agi/gretl/jobs/MetaPublisherTest.java | 11 +- .../agi/gretl/jobs/OgdMetaPublisherTest.java | 15 +- .../gretl/jobs/PostgisRasterExportTest.java | 33 +-- .../ch/so/agi/gretl/jobs/PublisherTest.java | 7 +- .../agi/gretl/jobs/S3Bucket2BucketTest.java | 77 +++-- .../ch/so/agi/gretl/jobs/S3DownloadTest.java | 59 ++-- .../ch/so/agi/gretl/jobs/S3UploadTest.java | 115 +++----- .../ch/so/agi/gretl/jobs/ShpExportTest.java | 44 ++- .../ch/so/agi/gretl/jobs/ShpImportTest.java | 29 +- .../so/agi/gretl/jobs/ShpValidatorTest.java | 15 +- .../gretl/jobs/SqlExecutorTaskDuckDbTest.java | 10 +- .../agi/gretl/jobs/SqlExecutorTaskTest.java | 58 ++-- .../so/agi/gretl/jobs/XslTransformerTest.java | 10 +- .../testutil/DbDriversReachableTest.java | 7 - .../agi/gretl/testutil/QgisReachableTest.java | 7 - .../agi/gretl/logging/GradleLoggerTest.java | 22 +- .../steps/AbstractPublisherStepTest.java | 267 +++++++++--------- .../so/agi/gretl/steps/Csv2ExcelStepTest.java | 20 +- .../agi/gretl/steps/Csv2ParquetStepTest.java | 60 ++-- .../steps/DatabaseDocumentExportStepTest.java | 75 +++-- .../ch/so/agi/gretl/steps/Db2DbStepTest.java | 107 +++---- .../so/agi/gretl/steps/Gpkg2DxfStepTest.java | 21 +- .../so/agi/gretl/steps/Gpkg2ShpStepTest.java | 39 ++- .../ch/so/agi/gretl/steps/GzipStepTest.java | 19 +- .../agi/gretl/steps/JsonImportStepTest.java | 26 +- .../MetaPublisherStepTestFile2LocalTest.java | 30 +- .../gretl/steps/OgdMetaPublisherStepTest.java | 17 +- .../steps/PostgisRasterExportStepTest.java | 33 ++- .../steps/PublisherStepDb2LocalTest.java | 259 ++++++++--------- .../steps/PublisherStepFile2RemoteTest.java | 22 +- .../gretl/steps/S3Bucket2BucketStepTest.java | 20 +- .../agi/gretl/steps/S3DownloadStepTest.java | 27 +- .../so/agi/gretl/steps/S3UploadStepTest.java | 23 +- .../agi/gretl/steps/SqlExecutorStepTest.java | 35 ++- .../gretl/steps/XslTransformerStepTest.java | 25 +- .../java/ch/so/agi/gretl/testutil/DbTest.java | 6 - .../so/agi/gretl/testutil/FileListTest.java | 12 +- .../java/ch/so/agi/gretl/testutil/S3Test.java | 5 - .../so/agi/gretl/testutil/S3TestHelper.java | 1 - .../ch/so/agi/gretl/testutil/SftpTest.java | 6 - .../ch/so/agi/gretl/testutil/SftpUriTest.java | 17 +- .../ch/so/agi/gretl/testutil/TestTags.java | 9 + .../ch/so/agi/gretl/testutil/TestUtil.java | 20 +- .../ch/so/agi/gretl/util/DbConnectorTest.java | 2 +- .../gretl/util/FileStylingDefinitionTest.java | 29 +- .../ch/so/agi/gretl/util/GroomingTest.java | 105 ++++--- .../so/agi/gretl/util/SimiSvcClientMock.java | 1 + .../so/agi/gretl/util/SimiSvcClientTest.java | 52 ++-- .../ch/so/agi/gretl/util/SqlReaderTest.java | 30 +- .../gretl/util/metapublisher/RegionsTest.java | 36 ++- .../util/publisher/PublicationLogTest.java | 61 ++-- 83 files changed, 1449 insertions(+), 1515 deletions(-) delete mode 100755 gretl/src/integrationTest/java/ch/so/agi/gretl/testutil/DbDriversReachableTest.java delete mode 100644 gretl/src/integrationTest/java/ch/so/agi/gretl/testutil/QgisReachableTest.java delete mode 100755 gretl/src/test/java/ch/so/agi/gretl/testutil/DbTest.java delete mode 100644 gretl/src/test/java/ch/so/agi/gretl/testutil/S3Test.java delete mode 100644 gretl/src/test/java/ch/so/agi/gretl/testutil/SftpTest.java create mode 100644 gretl/src/test/java/ch/so/agi/gretl/testutil/TestTags.java diff --git a/README.md b/README.md index 80746fd8..6cb88b5a 100644 --- a/README.md +++ b/README.md @@ -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`). diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index dae1c4c7..b0f0adc7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" @@ -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"} diff --git a/gretl/build.gradle b/gretl/build.gradle index eb3fc1a0..0bea6b6a 100755 --- a/gretl/build.gradle +++ b/gretl/build.gradle @@ -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 { @@ -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 @@ -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 @@ -174,29 +178,27 @@ 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' } } @@ -204,13 +206,13 @@ 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' } } diff --git a/gretl/integration-test.gradle b/gretl/integration-test.gradle index d1906cf8..1eeafbe1 100644 --- a/gretl/integration-test.gradle +++ b/gretl/integration-test.gradle @@ -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') @@ -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') @@ -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') @@ -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') diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2chTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2chTest.java index 2f00c817..a19239ef 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2chTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2chTest.java @@ -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 @@ -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")); diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2geobauTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2geobauTest.java index f8195f81..7f2e00f1 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2geobauTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2geobauTest.java @@ -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 { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Csv2ExcelTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Csv2ExcelTest.java index 335ea078..c6e45eaf 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Csv2ExcelTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Csv2ExcelTest.java @@ -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 { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Csv2ParquetTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Csv2ParquetTest.java index 0f0f982e..a7b860ba 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Csv2ParquetTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Csv2ParquetTest.java @@ -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(); diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvExportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvExportTest.java index c8af2236..770c27a8 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvExportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvExportTest.java @@ -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 { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvImportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvImportTest.java index 93ce28b8..3e0d47f8 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvImportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvImportTest.java @@ -4,31 +4,30 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; import ch.so.agi.gretl.util.IntegrationTestUtilSql; - -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.math.BigDecimal; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; -import org.junit.Assert; -import org.junit.ClassRule; +import static org.junit.jupiter.api.Assertions.*; +@Testcontainers public class CsvImportTest { - @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 importOk() throws Exception { @@ -62,7 +61,7 @@ public void importOk() throws Exception { assertEquals("rot",rs.getString(4)); assertEquals(new java.sql.Date(2017-1900,9-1,21),rs.getDate(5)); assertEquals(new java.sql.Timestamp(2016-1900,8-1,22,13,15,22,450000000),rs.getTimestamp(6)); - assertEquals(true,rs.getBoolean(7)); + assertTrue(rs.getBoolean(7)); if(rs.next()) { fail(); } @@ -106,7 +105,7 @@ public void importOk_batchSize() throws Exception { assertEquals("rot",rs.getString(4)); assertEquals(new java.sql.Date(2017-1900,9-1,21),rs.getDate(5)); assertEquals(new java.sql.Timestamp(2016-1900,8-1,22,13,15,22,450000000),rs.getTimestamp(6)); - assertEquals(true,rs.getBoolean(7)); + assertTrue(rs.getBoolean(7)); if(rs.next()) { fail(); } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvValidatorTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvValidatorTest.java index 60e073d2..4d6f2473 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvValidatorTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CsvValidatorTest.java @@ -2,9 +2,9 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CsvValidatorTest { @Test @@ -17,5 +17,4 @@ public void validationFail() throws Exception { GradleVariable[] gvs = null; // {GradleVariable.newGradleProperty(TestUtilSql.VARNAME_PG_CON_URI, TestUtilSql.PG_CON_URI)}; assertEquals(1,IntegrationTestUtil.runJob("src/integrationTest/jobs/CsvValidatorFail", gvs,new StringBuffer(),new StringBuffer())); } - } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CurlTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CurlTest.java index baf835ac..c2599d93 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CurlTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CurlTest.java @@ -1,36 +1,31 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Base64; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; - import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import okio.Buffer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Base64; -public class CurlTest { +class CurlTest { private MockWebServer mockWebServer; - @Before + @BeforeEach public void setup() throws IOException { this.mockWebServer = new MockWebServer(); this.mockWebServer.start(); } - @After + @AfterEach public void tearDown() throws IOException { this.mockWebServer.shutdown(); } @@ -50,17 +45,16 @@ public void geodienste_Ok() throws Exception { // Validate result RecordedRequest recordedRequest = mockWebServer.takeRequest(); - assertEquals("/data_agg/interlis/import", recordedRequest.getPath()); - assertEquals(recordedRequest.getHeader("Authorization").split(" ")[1].trim(), - Base64.getEncoder().encodeToString(("fooUser:barPwd").getBytes())); + Assertions.assertEquals("/data_agg/interlis/import", recordedRequest.getPath()); + Assertions.assertEquals(recordedRequest.getHeader("Authorization").split(" ")[1].trim(), Base64.getEncoder().encodeToString(("fooUser:barPwd").getBytes())); Buffer bodyBuffer = recordedRequest.getBody(); long bodyBufferSize = bodyBuffer.size(); String bodyContent = bodyBuffer.readUtf8(); - assertTrue(bodyBufferSize>500L); - assertTrue(bodyContent.contains("name=\"topic\"")); - assertTrue(bodyContent.contains("npl_waldgrenzen")); - assertTrue(bodyContent.contains("name=\"lv95_file\"; filename=\"test.xtf.zip\"")); + Assertions.assertTrue(bodyBufferSize>500L); + Assertions.assertTrue(bodyContent.contains("name=\"topic\"")); + Assertions.assertTrue(bodyContent.contains("npl_waldgrenzen")); + Assertions.assertTrue(bodyContent.contains("name=\"lv95_file\"; filename=\"test.xtf.zip\"")); } @Test @@ -73,7 +67,7 @@ public void geodienste_Fail() throws Exception { // Run GRETL task GradleVariable[] gvs = { GradleVariable.newGradleProperty("mockWebServerPort", String.valueOf(mockWebServer.getPort())) }; - assertEquals(1, IntegrationTestUtil.runJob("src/integrationTest/jobs/CurlGeodienste", gvs, new StringBuffer(), new StringBuffer())); + Assertions.assertEquals(1, IntegrationTestUtil.runJob("src/integrationTest/jobs/CurlGeodienste", gvs, new StringBuffer(), new StringBuffer())); } @Test @@ -90,10 +84,9 @@ public void planregister_Ok() throws Exception { // Validate result RecordedRequest recordedRequest = mockWebServer.takeRequest(); - assertEquals("/typo3/api/digiplan", recordedRequest.getPath()); - assertEquals(recordedRequest.getHeader("Authorization").split(" ")[1].trim(), - Base64.getEncoder().encodeToString(("fooUser:barPwd").getBytes())); - assertTrue(recordedRequest.getBodySize()>600L); + Assertions.assertEquals("/typo3/api/digiplan", recordedRequest.getPath()); + Assertions.assertEquals(recordedRequest.getHeader("Authorization").split(" ")[1].trim(), Base64.getEncoder().encodeToString(("fooUser:barPwd").getBytes())); + Assertions.assertTrue(recordedRequest.getBodySize()>600L); } @Test @@ -104,8 +97,8 @@ public void downloadFile_Ok() throws Exception { // Validate result String content = new String(Files.readAllBytes(Paths.get("src/integrationTest/jobs/CurlDownload/README.md"))); - assertTrue(content.contains("_GRETL_")); - assertTrue(content.contains("Licencse")); + Assertions.assertTrue(content.contains("_GRETL_")); + Assertions.assertTrue(content.contains("Licencse")); } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/DatabaseDocumentExportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/DatabaseDocumentExportTest.java index bcef79f8..81a1b87e 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/DatabaseDocumentExportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/DatabaseDocumentExportTest.java @@ -1,29 +1,30 @@ package ch.so.agi.gretl.jobs; -import java.io.File; -import java.sql.Connection; -import java.sql.Statement; - import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Test; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import java.io.File; +import java.sql.Connection; +import java.sql.Statement; +@Testcontainers public class DatabaseDocumentExportTest { - @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 { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Db2DbTaskTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Db2DbTaskTest.java index 69182d3b..6e2d103a 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Db2DbTaskTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Db2DbTaskTest.java @@ -4,27 +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.Assert; -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 org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; import java.sql.Statement; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@Testcontainers public class Db2DbTaskTest { - @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)); /* * Tests if fetchSize parameter is working. @@ -59,25 +60,24 @@ public void fetchSizeParameterTest() throws Exception { String countDestSql = String.format("select count(*) from %s.target_data", schemaName); int countDest = IntegrationTestUtilSql.execCountQuery(con, countDestSql); - Assert.assertEquals( - "Rowcount in table source_data must be equal to rowcount in table target_data", + assertEquals( 2, - countDest); + countDest, + "Rowcount in table source_data must be equal to rowcount in table target_data" + ); } finally { IntegrationTestUtilSql.closeCon(con); } } - - - - - /* -Test's that a chain of statements executes properly and results in the correct -number of inserts (corresponding to the last statement) - 1. Statement transfers rows from a to b - 2. Statement transfers rows from b to a -*/ + + /** + * Test's that a chain of statements executes properly and results in the correct number of inserts + * (corresponding to the last statement) + * 1. Statement transfers rows from a to b + * 2. Statement transfers rows from b to a + * @throws Exception + */ @Test public void taskChainTest() throws Exception { String schemaName = "db2dbTaskChain".toLowerCase(); @@ -97,10 +97,11 @@ public void taskChainTest() throws Exception { String countDestSql = String.format("select count(*) from %s.albums_dest", schemaName); int countDest = IntegrationTestUtilSql.execCountQuery(con, countDestSql); - Assert.assertEquals( - "Rowcount in table albums_src must be equal to rowcount in table albums_dest", + assertEquals( countSrc, - countDest); + countDest, + "Rowcount in table albums_src must be equal to rowcount in table albums_dest" + ); } finally { IntegrationTestUtilSql.closeCon(con); @@ -109,7 +110,6 @@ public void taskChainTest() throws Exception { /** * Test's if the sql-files can be configured using a relative path. - * * The relative path relates to the location of the build.gradle file * of the corresponding gretl job. */ @@ -133,10 +133,11 @@ public void relativePathTest() throws Exception{ String countDestSql = String.format("select count(*) from %s.albums_dest", schemaName); int countDest = IntegrationTestUtilSql.execCountQuery(con, countDestSql); - Assert.assertEquals( - "Rowcount in table albums_src must be equal to rowcount in table albums_dest", + assertEquals( countSrc, - countDest); + countDest, + "Rowcount in table albums_src must be equal to rowcount in table albums_dest" + ); } finally { IntegrationTestUtilSql.closeCon(con); @@ -168,15 +169,17 @@ public void deleteDestTableContent() throws Exception{ String countDestSql = String.format("select count(*) from %s.albums_dest", schemaName); int countDest = IntegrationTestUtilSql.execCountQuery(con, countDestSql); - Assert.assertEquals( - "Rowcount in table albums_src must be equal to rowcount in table albums_dest", + assertEquals( countSrc, - countDest); + countDest, + "Rowcount in table albums_src must be equal to rowcount in table albums_dest" + ); } finally { IntegrationTestUtilSql.closeCon(con); } } + @Test public void parameter() throws Exception{ String schemaName = "parameterList".toLowerCase(); @@ -203,7 +206,7 @@ public void parameter() throws Exception{ String countDestSql = String.format("select count(*) from %s.dest", schemaName); int countDest = IntegrationTestUtilSql.execCountQuery(con, countDestSql); - Assert.assertEquals(2,countDest); + assertEquals(2, countDest); } finally { IntegrationTestUtilSql.closeCon(con); @@ -239,9 +242,8 @@ public void parameterList() throws Exception{ String countDestSql = String.format("select count(*) from %s.dest", schemaName); int countDest = IntegrationTestUtilSql.execCountQuery(con, countDestSql); - Assert.assertEquals(5,countDest); - } - finally { + assertEquals(5,countDest); + } finally { IntegrationTestUtilSql.closeCon(con); } } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/DbDriverContainedTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/DbDriverContainedTest.java index 981e8bcb..aa350e61 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/DbDriverContainedTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/DbDriverContainedTest.java @@ -1,28 +1,30 @@ package ch.so.agi.gretl.jobs; +import ch.so.agi.gretl.testutil.TestTags; 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 ch.so.agi.gretl.testutil.DbDriversReachableTest; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.OracleContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +@Testcontainers public class DbDriverContainedTest { - @ClassRule + + @Container public static OracleContainer oracle = new OracleContainer("epiclabs/docker-oracle-xe-11g") .withUsername("system").withPassword("oracle"); - @Category(DbDriversReachableTest.class) @Test + @Tag(TestTags.DB_DRIVERS_REACHABLE_TEST) public void SqliteDriverContainedTest() throws Exception { IntegrationTestUtil.runJob("src/integrationTest/jobs/DbTasks_SqliteLibsPresent"); } - @Category(DbDriversReachableTest.class) @Test + @Tag(TestTags.DB_DRIVERS_REACHABLE_TEST) public void OracleDriverContainedTest() throws Exception { GradleVariable[] gvs = {GradleVariable.newGradleProperty(IntegrationTestUtilSql.VARNAME_ORA_CON_URI, oracle.getJdbcUrl())}; IntegrationTestUtil.runJob("src/integrationTest/jobs/DbTasks_OracleLibsPresent", gvs); diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Gpkg2DxfTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Gpkg2DxfTest.java index 2539285a..fe7f737f 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Gpkg2DxfTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Gpkg2DxfTest.java @@ -1,16 +1,16 @@ package ch.so.agi.gretl.jobs; -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.nio.file.Files; import java.nio.file.Paths; -import org.junit.Test; - -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; +import static org.junit.jupiter.api.Assertions.assertTrue; public class Gpkg2DxfTest { + @Test public void export_Ok() throws Exception { String TEST_OUT = "src/integrationTest/jobs/Gpkg2Dxf/out/"; diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Gpkg2ShpTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Gpkg2ShpTest.java index dcc3908b..691dfadf 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Gpkg2ShpTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Gpkg2ShpTest.java @@ -1,20 +1,20 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import org.geotools.data.FileDataStore; +import org.geotools.data.FileDataStoreFinder; +import org.geotools.data.simple.SimpleFeatureSource; +import org.junit.jupiter.api.Test; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; -import org.geotools.data.FileDataStore; -import org.geotools.data.FileDataStoreFinder; -import org.geotools.data.simple.SimpleFeatureSource; -import org.junit.Test; - -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; public class Gpkg2ShpTest { + @Test public void export_Ok() throws Exception { String TEST_OUT = "src/integrationTest/jobs/Gpkg2Shp/out/"; diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgExportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgExportTest.java index 7b2a261f..d2956367 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgExportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgExportTest.java @@ -6,33 +6,31 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; import ch.so.agi.gretl.util.IntegrationTestUtilSql; - -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.nio.file.Files; import java.nio.file.Paths; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import org.junit.ClassRule; +import java.sql.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +@Testcontainers public class GpkgExportTest { - @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 exportTableOk() throws Exception { @@ -138,8 +136,7 @@ public void exportTablesOk() throws Exception { } } - } - finally { + } finally { IntegrationTestUtilSql.closeCon(con); } } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgImportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgImportTest.java index e07264c0..2f741f77 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgImportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgImportTest.java @@ -4,30 +4,30 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; import ch.so.agi.gretl.util.IntegrationTestUtilSql; - -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.sql.Connection; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; -import org.junit.ClassRule; +import static org.junit.jupiter.api.Assertions.assertEquals; +@Testcontainers public class GpkgImportTest { - @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 importOk() throws Exception { @@ -65,8 +65,7 @@ public void importOk() throws Exception { } rs.close(); s1.close(); - } - finally { + } finally { IntegrationTestUtilSql.closeCon(con); } } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgValidatorTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgValidatorTest.java index 94af0ca9..5dde0117 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgValidatorTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GpkgValidatorTest.java @@ -2,20 +2,21 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class GpkgValidatorTest { + @Test public void validationOk() throws Exception { GradleVariable[] gvs = null; IntegrationTestUtil.runJob("src/integrationTest/jobs/GpkgValidator", gvs); } + @Test public void validationFail() throws Exception { GradleVariable[] gvs = null; // {GradleVariable.newGradleProperty(TestUtilSql.VARNAME_PG_CON_URI, TestUtilSql.PG_CON_URI)}; assertEquals(1,IntegrationTestUtil.runJob("src/integrationTest/jobs/GpkgValidatorFail", gvs,new StringBuffer(),new StringBuffer())); } - } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GzipTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GzipTest.java index 46e93796..a0b4837a 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GzipTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/GzipTest.java @@ -1,7 +1,9 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; -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.io.FileInputStream; @@ -10,13 +12,10 @@ import java.nio.file.Files; import java.util.zip.GZIPInputStream; -import org.junit.Test; - -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; - +import static org.junit.jupiter.api.Assertions.assertTrue; public class GzipTest { + @Test public void compress_file_Ok() throws Exception { // Run GRETL task diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2gpkgImportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2gpkgImportTest.java index d12f0a4f..ae8f20d0 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2gpkgImportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2gpkgImportTest.java @@ -1,26 +1,19 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import ch.ehi.ili2db.base.DbNames; +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.file.Files; import java.nio.file.Paths; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import org.junit.Test; - -import ch.ehi.ili2db.base.DbNames; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; +import static org.junit.jupiter.api.Assertions.*; public class Ili2gpkgImportTest { @@ -64,6 +57,7 @@ public void importOk() throws Exception { } } } + @Test public void importFileSet() throws Exception { Files.deleteIfExists(Paths.get("src/integrationTest/jobs/Ili2gpkgImportFileSet/Beispiel2.gpkg")); diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgDeleteDatasetsTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgDeleteDatasetsTest.java index 97c7af2d..f8a4787f 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgDeleteDatasetsTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgDeleteDatasetsTest.java @@ -1,34 +1,36 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.*; +import ch.ehi.ili2db.base.DbNames; +import ch.so.agi.gretl.testutil.TestUtil; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.PostgisContainerProvider; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.HashSet; -import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Test; -import org.testcontainers.containers.PostgisContainerProvider; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.containers.wait.strategy.Wait; - -import ch.ehi.ili2db.base.DbNames; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +@Testcontainers public class Ili2pgDeleteDatasetsTest { - @ClassRule - public static PostgreSQLContainer postgres = - (PostgreSQLContainer) new PostgisContainerProvider() - .newInstance().withDatabaseName("gretl") - .withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER) - .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) - .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) + .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) + .withInitScript("init_postgresql.sql") + .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); @Test public void deleteOk() throws Exception { @@ -59,5 +61,4 @@ public void deleteOk() throws Exception { IntegrationTestUtilSql.closeCon(con); } } - } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgDeleteTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgDeleteTest.java index 2f5f1e01..7540c0a0 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgDeleteTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgDeleteTest.java @@ -1,39 +1,36 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.net.URI; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.Statement; - +import ch.ehi.ili2db.gui.Config; +import ch.ehi.ili2pg.PgMain; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Test; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; -import ch.ehi.ili2db.base.Ili2db; -import ch.ehi.ili2db.gui.Config; -import ch.ehi.ili2pg.PgMain; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +@Testcontainers public class Ili2pgDeleteTest { - @ClassRule - public static PostgreSQLContainer postgres = - (PostgreSQLContainer) new PostgisContainerProvider() - .newInstance().withDatabaseName("gretl") - .withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER) - .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) - .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) + .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) + .withInitScript("init_postgresql.sql") + .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); @Test public void deleteDataset_Ok() throws Exception { @@ -48,13 +45,13 @@ public void deleteDataset_Ok() throws Exception { Statement s = con.createStatement(); ResultSet rs = s.executeQuery("SELECT count(*) AS anzahl FROM dm01.lfp3"); - if(!rs.next()) { + if (!rs.next()) { fail(); } - assertTrue(rs.getInt(1)==0); + assertEquals(0, rs.getInt(1)); - if(rs.next()) { + if (rs.next()) { fail(); } } finally { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgExportDatasetsTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgExportDatasetsTest.java index 13118fff..55b0c1b0 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgExportDatasetsTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgExportDatasetsTest.java @@ -1,43 +1,31 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.*; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.Statement; -import java.util.HashSet; - +import ch.interlis.iom_j.xtf.XtfReader; +import ch.interlis.iox.*; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Test; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; -import ch.ehi.ili2db.base.DbNames; -import ch.interlis.iom.IomObject; -import ch.interlis.iom_j.xtf.XtfReader; -import ch.interlis.iox.EndBasketEvent; -import ch.interlis.iox.EndTransferEvent; -import ch.interlis.iox.IoxEvent; -import ch.interlis.iox.IoxException; -import ch.interlis.iox.ObjectEvent; -import ch.interlis.iox.StartBasketEvent; -import ch.interlis.iox.StartTransferEvent; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +@Testcontainers public class Ili2pgExportDatasetsTest { - @ClassRule - public static PostgreSQLContainer postgres = - (PostgreSQLContainer) new PostgisContainerProvider() - .newInstance().withDatabaseName("gretl") - .withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER) - .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) - .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) + .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) + .withInitScript("init_postgresql.sql") + .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); @Test public void exportOk() throws Exception { @@ -55,15 +43,15 @@ public void exportOk() throws Exception { private void assertXtfFile(java.io.File file) throws IoxException { XtfReader reader=new XtfReader(file); - assertTrue(reader.read() instanceof StartTransferEvent); - assertTrue(reader.read() instanceof StartBasketEvent); + assertInstanceOf(StartTransferEvent.class, reader.read()); + assertInstanceOf(StartBasketEvent.class, reader.read()); IoxEvent event=reader.read(); while(event instanceof ObjectEvent) { event=reader.read(); } - assertTrue(event instanceof EndBasketEvent); - assertTrue(reader.read() instanceof EndTransferEvent); + assertInstanceOf(EndBasketEvent.class, event); + assertInstanceOf(EndTransferEvent.class, reader.read()); } } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgImportFileSetTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgImportFileSetTest.java index 81f9d1e5..8ce85e83 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgImportFileSetTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgImportFileSetTest.java @@ -1,34 +1,36 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.*; +import ch.ehi.ili2db.base.DbNames; +import ch.so.agi.gretl.testutil.TestUtil; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.PostgisContainerProvider; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.HashSet; -import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Test; -import org.testcontainers.containers.PostgisContainerProvider; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.containers.wait.strategy.Wait; - -import ch.ehi.ili2db.base.DbNames; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +@Testcontainers public class Ili2pgImportFileSetTest { - @ClassRule - public static PostgreSQLContainer postgres = - (PostgreSQLContainer) new PostgisContainerProvider() - .newInstance().withDatabaseName("gretl") - .withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER) - .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) - .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) + .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) + .withInitScript("init_postgresql.sql") + .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); @Test public void importOk() throws Exception { @@ -61,5 +63,4 @@ public void importOk() throws Exception { IntegrationTestUtilSql.closeCon(con); } } - } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgImportSchemaTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgImportSchemaTest.java index 82558fff..f7cc0ff7 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgImportSchemaTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgImportSchemaTest.java @@ -1,33 +1,34 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.Statement; - import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Test; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +@Testcontainers public class Ili2pgImportSchemaTest { - @ClassRule - public static PostgreSQLContainer postgres = - (PostgreSQLContainer) new PostgisContainerProvider() - .newInstance().withDatabaseName("gretl") - .withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER) - .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) - .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) + .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) + .withInitScript("init_postgresql.sql") + .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); @Test public void schemaImportOk() throws Exception { @@ -64,7 +65,6 @@ public void schemaImportOk() throws Exception { if(rs.next()) { fail(); } - } finally { IntegrationTestUtilSql.closeCon(con); } @@ -106,8 +106,6 @@ public void schemaImport_Options1_Ok() throws Exception { if(rs.next()) { fail(); } - - } finally { IntegrationTestUtilSql.closeCon(con); } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgReplaceFileTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgReplaceFileTest.java index 959c3b7a..cf6a0b5c 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgReplaceFileTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgReplaceFileTest.java @@ -1,34 +1,36 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.*; +import ch.ehi.ili2db.base.DbNames; +import ch.so.agi.gretl.testutil.TestUtil; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.PostgisContainerProvider; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.HashSet; -import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Test; -import org.testcontainers.containers.PostgisContainerProvider; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.containers.wait.strategy.Wait; - -import ch.ehi.ili2db.base.DbNames; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +@Testcontainers public class Ili2pgReplaceFileTest { - @ClassRule - public static PostgreSQLContainer postgres = - (PostgreSQLContainer) new PostgisContainerProvider() - .newInstance().withDatabaseName("gretl") - .withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER) - .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) - .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) + .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) + .withInitScript("init_postgresql.sql") + .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); @Test public void importLocalFile_Ok() throws Exception { @@ -55,7 +57,6 @@ public void importLocalFile_Ok() throws Exception { assertTrue(datasets.contains("A_Dataset")); rs.close(); s.close(); - } finally { IntegrationTestUtilSql.closeCon(con); } @@ -91,11 +92,8 @@ public void importIlidataFile_Ok() throws Exception { assertTrue(datasets.contains("2549")); rs.close(); s.close(); - } finally { IntegrationTestUtilSql.closeCon(con); } } - - } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgValidateDatasetTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgValidateDatasetTest.java index 33c4a4f1..a4966d2b 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgValidateDatasetTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgValidateDatasetTest.java @@ -1,32 +1,34 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.nio.file.Files; -import java.nio.file.Paths; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Test; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +@Testcontainers public class Ili2pgValidateDatasetTest { - @ClassRule - public static PostgreSQLContainer postgres = - (PostgreSQLContainer) new PostgisContainerProvider() - .newInstance().withDatabaseName("gretl") - .withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER) - .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) - .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) + .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) + .withInitScript("init_postgresql.sql") + .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); @Test public void validateSingleDataset_Ok() throws Exception { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgValidateTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgValidateTest.java index f5805e11..47dac549 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgValidateTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Ili2pgValidateTest.java @@ -1,32 +1,34 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.nio.file.Files; -import java.nio.file.Paths; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Test; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +@Testcontainers public class Ili2pgValidateTest { - @ClassRule - public static PostgreSQLContainer postgres = - (PostgreSQLContainer) new PostgisContainerProvider() - .newInstance().withDatabaseName("gretl") - .withUsername(IntegrationTestUtilSql.PG_CON_DDLUSER) - .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) - .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) + .withPassword(IntegrationTestUtilSql.PG_CON_DDLPASS) + .withInitScript("init_postgresql.sql") + .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); @Test public void validateData_Ok() throws Exception { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/IliValidatorTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/IliValidatorTest.java index 52d052f6..da52d57d 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/IliValidatorTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/IliValidatorTest.java @@ -2,11 +2,13 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; -import static org.junit.Assert.*; public class IliValidatorTest { + @Test public void validationOk() throws Exception { GradleVariable[] gvs = null; diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/JsonImportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/JsonImportTest.java index 095c7ada..3460c737 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/JsonImportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/JsonImportTest.java @@ -1,39 +1,38 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.math.BigDecimal; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.Statement; - import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Test; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +@Testcontainers public class JsonImportTest { - private static String dbusr = "ddluser"; - private static String dbpwd = "ddluser"; - private static String dbdatabase = "gretl"; - - @ClassRule - public static PostgreSQLContainer postgres = - (PostgreSQLContainer) new PostgisContainerProvider() - .newInstance().withDatabaseName(dbdatabase) - .withUsername(dbusr) - .withPassword(dbpwd) - .withInitScript("init_postgresql.sql") - .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); + private static final String dbusr = "ddluser"; + private static final String dbpwd = "ddluser"; + private static final String dbdatabase = "gretl"; + + @Container + public static PostgreSQLContainer postgres = + (PostgreSQLContainer) new PostgisContainerProvider().newInstance() + .withDatabaseName(dbdatabase) + .withUsername(dbusr) + .withPassword(dbpwd) + .withInitScript("init_postgresql.sql") + .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); @Test public void importJsonObject_Ok() throws Exception { @@ -135,5 +134,4 @@ public void importJsonArray_Ok() throws Exception { IntegrationTestUtilSql.closeCon(con); } } - } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/MetaPublisherTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/MetaPublisherTest.java index 8ca9a090..2672659b 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/MetaPublisherTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/MetaPublisherTest.java @@ -1,18 +1,17 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertTrue; -import java.io.File; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import org.junit.jupiter.api.Test; + import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.util.Date; -import org.junit.Test; - -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MetaPublisherTest { public static final String PATH_ELE_ROOT = "build"; diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/OgdMetaPublisherTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/OgdMetaPublisherTest.java index b361ddcc..8ba7e263 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/OgdMetaPublisherTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/OgdMetaPublisherTest.java @@ -1,19 +1,16 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import ch.ehi.basics.settings.Settings; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import org.interlis2.validator.Validator; +import org.junit.jupiter.api.Test; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import org.interlis2.validator.Validator; -import org.junit.Test; - -import ch.ehi.basics.settings.Settings; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; - +import static org.junit.jupiter.api.Assertions.assertTrue; public class OgdMetaPublisherTest { @Test diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/PostgisRasterExportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/PostgisRasterExportTest.java index f1299e45..7002526c 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/PostgisRasterExportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/PostgisRasterExportTest.java @@ -1,34 +1,31 @@ package ch.so.agi.gretl.jobs; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.testcontainers.containers.PostgisContainerProvider; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.containers.wait.strategy.Wait; - import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; import ch.so.agi.gretl.util.IntegrationTestUtilSql; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.PostgisContainerProvider; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.io.File; import java.nio.file.Files; -import java.sql.Connection; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +@Testcontainers public class PostgisRasterExportTest { - @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 exportTiff() throws Exception { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/PublisherTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/PublisherTest.java index a579afea..7f4eb85d 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/PublisherTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/PublisherTest.java @@ -2,11 +2,8 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; - -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -24,6 +21,7 @@ public void simple() throws Exception { GradleVariable[] gvs = null; IntegrationTestUtil.runJob(jobDirectory, gvs); } + @Test public void regions() throws Exception { String jobDirectory = "src/integrationTest/jobs/PublisherRegions"; @@ -44,5 +42,4 @@ private Path copyFileFromResourcesToJob(String jobDirectory, String resourceSubD Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); return to; } - } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3Bucket2BucketTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3Bucket2BucketTest.java index bb48ce67..c37e0884 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3Bucket2BucketTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3Bucket2BucketTest.java @@ -1,57 +1,45 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -//import com.amazonaws.auth.AWSStaticCredentialsProvider; -//import com.amazonaws.auth.BasicAWSCredentials; -//import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration; -//import com.amazonaws.services.s3.AmazonS3; -//import com.amazonaws.services.s3.AmazonS3ClientBuilder; -//import com.amazonaws.services.s3.model.ObjectListing; -//import com.amazonaws.services.s3.model.S3Object; -//import com.amazonaws.services.s3.model.S3ObjectSummary; - -import ch.so.agi.gretl.testutil.S3Test; +import ch.so.agi.gretl.testutil.S3TestHelper; +import ch.so.agi.gretl.testutil.TestTags; import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; -import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; -import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; -import software.amazon.awssdk.regions.Region; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; import software.amazon.awssdk.services.s3.model.ListObjectsRequest; import software.amazon.awssdk.services.s3.model.ListObjectsResponse; import software.amazon.awssdk.services.s3.model.S3Object; -public class S3Bucket2BucketTest { - private String s3AccessKey = System.getProperty("s3AccessKey"); - private String s3SecretKey = System.getProperty("s3SecretKey"); - private String s3SourceBucket = "ch.so.agi.gretl.test"; - private String s3TargetBucket = "ch.so.agi.gretl.test-copy"; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class S3Bucket2BucketTest { + private final S3TestHelper s3TestHelper; + private final String s3AccessKey; + private final String s3SecretKey; + private final String s3SourceBucket; + private final String s3TargetBucket; + + public S3Bucket2BucketTest() { + this.s3AccessKey = System.getProperty("s3AccessKey"); + this.s3SecretKey = System.getProperty("s3SecretKey"); + this.s3SourceBucket = "ch.so.agi.gretl.test"; + this.s3TargetBucket = "ch.so.agi.gretl.test-copy"; + + String s3Endpoint = "https://s3.eu-central-1.amazonaws.com"; + String s3Region = "eu-central-1"; + this.s3TestHelper = new S3TestHelper(this.s3AccessKey, this.s3SecretKey, s3Region, s3Endpoint); + } @Test - @Category(S3Test.class) - public void uploadDirectory_Ok() throws Exception { - AwsCredentialsProvider creds = StaticCredentialsProvider.create(AwsBasicCredentials.create(s3AccessKey, s3SecretKey)); - Region region = Region.of("eu-central-1"); - S3Client s3client = S3Client.builder() - .credentialsProvider(creds) - .region(region) - .endpointOverride(URI.create("https://s3.eu-central-1.amazonaws.com")) - .build(); + @Tag(TestTags.S3_TEST) + void uploadDirectory_Ok() throws Exception { + S3Client s3client = s3TestHelper.getS3Client(); s3client.deleteObject(DeleteObjectRequest.builder().bucket(s3TargetBucket).key("foo.txt").build()); s3client.deleteObject(DeleteObjectRequest.builder().bucket(s3TargetBucket).key("bar.txt").build()); @@ -76,15 +64,14 @@ public void uploadDirectory_Ok() throws Exception { List objects = res.contents(); List keyList = new ArrayList(); - for (ListIterator iterVals = objects.listIterator(); iterVals.hasNext(); ) { - S3Object myObject = iterVals.next(); + for (S3Object myObject : objects) { keyList.add(myObject.key()); } assertTrue(keyList.contains("foo.txt")); assertTrue(keyList.contains("bar.txt")); assertTrue(keyList.contains("download.txt")); - assertTrue(keyList.size() == 3); + assertEquals(3, keyList.size()); // Remove uploaded files from buckets. s3client.deleteObject(DeleteObjectRequest.builder().bucket(s3SourceBucket).key("foo.txt").build()); diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3DownloadTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3DownloadTest.java index a31d3d35..ee89306a 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3DownloadTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3DownloadTest.java @@ -1,36 +1,43 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertTrue; +import ch.so.agi.gretl.testutil.S3TestHelper; +import ch.so.agi.gretl.testutil.TestTags; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.core.ResponseInputStream; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.GetObjectRequest; +import software.amazon.awssdk.services.s3.model.GetObjectResponse; import java.io.BufferedReader; import java.io.InputStreamReader; -import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.junit.jupiter.api.Assertions.assertTrue; -import ch.so.agi.gretl.testutil.S3Test; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; -import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; -import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; -import software.amazon.awssdk.core.ResponseInputStream; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.s3.S3Client; -import software.amazon.awssdk.services.s3.model.GetObjectRequest; -import software.amazon.awssdk.services.s3.model.GetObjectResponse; +class S3DownloadTest { + private final S3TestHelper s3TestHelper; + private final String s3AccessKey; + private final String s3SecretKey; + private final String s3BucketName; + + public S3DownloadTest() { + this.s3AccessKey = System.getProperty("s3AccessKey"); + this.s3SecretKey = System.getProperty("s3SecretKey"); + this.s3BucketName = System.getProperty("s3BucketName"); + + String s3Endpoint = "https://s3.eu-central-1.amazonaws.com"; + String s3Region = "eu-central-1"; + this.s3TestHelper = new S3TestHelper(this.s3AccessKey, this.s3SecretKey, s3Region, s3Endpoint); + } -public class S3DownloadTest { - private String s3AccessKey = System.getProperty("s3AccessKey"); - private String s3SecretKey = System.getProperty("s3SecretKey"); - private String s3BucketName = System.getProperty("s3BucketName"); @Test - @Category(S3Test.class) - public void downloadFile_Ok() throws Exception { + @Tag(TestTags.S3_TEST) + void downloadFile_Ok() throws Exception { // Download single file from a directory. GradleVariable[] gvs = { GradleVariable.newGradleProperty("s3AccessKey", s3AccessKey), @@ -39,14 +46,8 @@ public void downloadFile_Ok() throws Exception { }; IntegrationTestUtil.runJob("src/integrationTest/jobs/S3DownloadFile", gvs); - // Check result. - AwsCredentialsProvider creds = StaticCredentialsProvider.create(AwsBasicCredentials.create(s3AccessKey, s3SecretKey)); - Region region = Region.of("eu-central-1"); - S3Client s3client = S3Client.builder() - .credentialsProvider(creds) - .region(region) - .endpointOverride(URI.create("https://s3.eu-central-1.amazonaws.com")) - .build(); + // Check result. + S3Client s3client = s3TestHelper.getS3Client(); GetObjectRequest getObjectRequest = GetObjectRequest.builder() .bucket(s3BucketName) diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3UploadTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3UploadTest.java index 69bbc822..c915cee6 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3UploadTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/S3UploadTest.java @@ -1,51 +1,45 @@ package ch.so.agi.gretl.jobs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import ch.so.agi.gretl.testutil.S3TestHelper; +import ch.so.agi.gretl.testutil.TestTags; +import ch.so.agi.gretl.util.GradleVariable; +import ch.so.agi.gretl.util.IntegrationTestUtil; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.core.ResponseInputStream; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.*; import java.io.BufferedReader; -import java.io.InputStream; import java.io.InputStreamReader; -import java.net.URI; import java.util.ArrayList; import java.util.List; -import java.util.ListIterator; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -import ch.so.agi.gretl.testutil.S3Test; -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; -import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; -import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; -import software.amazon.awssdk.core.ResponseInputStream; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.s3.S3Client; -import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; -import software.amazon.awssdk.services.s3.model.GetObjectRequest; -import software.amazon.awssdk.services.s3.model.GetObjectResponse; -import software.amazon.awssdk.services.s3.model.ListObjectsRequest; -import software.amazon.awssdk.services.s3.model.ListObjectsResponse; -import software.amazon.awssdk.services.s3.model.S3Object; - -public class S3UploadTest { - private String s3AccessKey = System.getProperty("s3AccessKey"); - private String s3SecretKey = System.getProperty("s3SecretKey"); - private String s3BucketName = System.getProperty("s3BucketName"); +class S3UploadTest { + private final S3TestHelper s3TestHelper; + private final String s3AccessKey; + private final String s3SecretKey; + private final String s3BucketName; - @Test - @Category(S3Test.class) - public void uploadDirectory_Ok() throws Exception { - AwsCredentialsProvider creds = StaticCredentialsProvider.create(AwsBasicCredentials.create(s3AccessKey, s3SecretKey)); - Region region = Region.of("eu-central-1"); - S3Client s3client = S3Client.builder() - .credentialsProvider(creds) - .region(region) - .endpointOverride(URI.create("https://s3.eu-central-1.amazonaws.com")) - .build(); + public S3UploadTest() { + this.s3AccessKey = System.getProperty("s3AccessKey"); + this.s3SecretKey = System.getProperty("s3SecretKey"); + this.s3BucketName = System.getProperty("s3BucketName"); + + String s3Region = "eu-central-1"; + String s3Endpoint = "https://s3.eu-central-1.amazonaws.com"; + this.s3TestHelper = new S3TestHelper(this.s3AccessKey, this.s3SecretKey, s3Region, s3Endpoint); + } + + @Test + @Tag(TestTags.S3_TEST) + void uploadDirectory_Ok() throws Exception { + S3Client s3client = s3TestHelper.getS3Client(); s3client.deleteObject(DeleteObjectRequest.builder().bucket(s3BucketName).key("foo.txt").build()); s3client.deleteObject(DeleteObjectRequest.builder().bucket(s3BucketName).key("bar.txt").build()); @@ -67,10 +61,9 @@ public void uploadDirectory_Ok() throws Exception { List objects = res.contents(); List keyList = new ArrayList(); - for (ListIterator iterVals = objects.listIterator(); iterVals.hasNext(); ) { - S3Object myValue = iterVals.next(); + for (S3Object myValue : objects) { keyList.add(myValue.key()); - } + } assertTrue(keyList.contains("foo.txt")); assertTrue(keyList.contains("bar.txt")); @@ -81,16 +74,10 @@ public void uploadDirectory_Ok() throws Exception { } @Test - @Category(S3Test.class) - public void uploadFileTree_Ok() throws Exception { + @Tag(TestTags.S3_TEST) + void uploadFileTree_Ok() throws Exception { // Check result. - AwsCredentialsProvider creds = StaticCredentialsProvider.create(AwsBasicCredentials.create(s3AccessKey, s3SecretKey)); - Region region = Region.of("eu-central-1"); - S3Client s3client = S3Client.builder() - .credentialsProvider(creds) - .region(region) - .endpointOverride(URI.create("https://s3.eu-central-1.amazonaws.com")) - .build(); + S3Client s3client = s3TestHelper.getS3Client(); // Remove uploaded files from bucket. s3client.deleteObject(DeleteObjectRequest.builder().bucket(s3BucketName).key("foo.csv").build()); @@ -112,16 +99,15 @@ public void uploadFileTree_Ok() throws Exception { ListObjectsResponse res = s3client.listObjects(listObjects); List objects = res.contents(); - - List keyList = new ArrayList(); - for (ListIterator iterVals = objects.listIterator(); iterVals.hasNext(); ) { - S3Object myValue = iterVals.next(); + + List keyList = new ArrayList<>(); + for (S3Object myValue : objects) { keyList.add(myValue.key()); - } + } assertTrue(keyList.contains("foo.csv")); assertTrue(keyList.contains("bar.csv")); - assertTrue(keyList.size() == 3); // TODO 3 wegen download.txt + assertEquals(3, keyList.size()); // TODO 3 wegen download.txt // Remove uploaded files from bucket. s3client.deleteObject(DeleteObjectRequest.builder().bucket(s3BucketName).key("foo.csv").build()); @@ -129,16 +115,9 @@ public void uploadFileTree_Ok() throws Exception { } @Test - @Category(S3Test.class) - public void uploadFile_Ok() throws Exception { - AwsCredentialsProvider creds = StaticCredentialsProvider.create(AwsBasicCredentials.create(s3AccessKey, s3SecretKey)); - Region region = Region.of("eu-central-1"); - S3Client s3client = S3Client.builder() - .credentialsProvider(creds) - .region(region) - .endpointOverride(URI.create("https://s3.eu-central-1.amazonaws.com")) - .build(); - + @Tag(TestTags.S3_TEST) + void uploadFile_Ok() throws Exception { + S3Client s3client = s3TestHelper.getS3Client(); s3client.deleteObject(DeleteObjectRequest.builder().bucket(s3BucketName).key("bar.txt").build()); // Upload single file from a directory. @@ -164,14 +143,14 @@ public void uploadFile_Ok() throws Exception { } @Test - @Category(S3Test.class) - public void uploadFile_Fail() throws Exception { + @Tag(TestTags.S3_TEST) + void uploadFile_Fail() throws Exception { // Upload single file from a directory. GradleVariable[] gvs = { GradleVariable.newGradleProperty("s3AccessKey", "login"), GradleVariable.newGradleProperty("s3SecretKey", "password"), GradleVariable.newGradleProperty("s3BucketName", s3BucketName) }; - assertEquals(1, IntegrationTestUtil.runJob("src/integrationTest/jobs/S3UploadFileFail", gvs, new StringBuffer(), new StringBuffer())); + Assertions.assertEquals(1, IntegrationTestUtil.runJob("src/integrationTest/jobs/S3UploadFileFail", gvs, new StringBuffer(), new StringBuffer())); } } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpExportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpExportTest.java index 0e431aba..9ad60b29 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpExportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpExportTest.java @@ -5,41 +5,36 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; import ch.so.agi.gretl.util.IntegrationTestUtilSql; - -import org.junit.Test; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Point; +import org.geotools.data.FileDataStore; +import org.geotools.data.FileDataStoreFinder; +import org.geotools.data.simple.SimpleFeatureIterator; +import org.geotools.data.simple.SimpleFeatureSource; +import org.junit.jupiter.api.Test; import org.opengis.feature.simple.SimpleFeature; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; - -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Point; - -import static org.junit.Assert.*; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.io.File; -import java.math.BigDecimal; import java.sql.Connection; -import java.sql.ResultSet; import java.sql.Statement; -import java.text.SimpleDateFormat; -import org.geotools.data.FileDataStore; -import org.geotools.data.FileDataStoreFinder; -import org.geotools.data.simple.SimpleFeatureIterator; -import org.geotools.data.simple.SimpleFeatureSource; -import org.junit.Assert; -import org.junit.ClassRule; +import static org.junit.jupiter.api.Assertions.assertEquals; +@Testcontainers public class ShpExportTest { - @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 { @@ -91,8 +86,7 @@ public void exportOk() throws Exception { featureCollectionIter.close(); dataStore.dispose(); } - } - finally { + } finally { IntegrationTestUtilSql.closeCon(con); } } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpImportTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpImportTest.java index 2ab7d8ff..494c16d4 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpImportTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpImportTest.java @@ -4,31 +4,31 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; import ch.so.agi.gretl.util.IntegrationTestUtilSql; - -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.math.BigDecimal; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; -import org.junit.Assert; -import org.junit.ClassRule; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +@Testcontainers public class ShpImportTest { - @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 importOk() throws Exception { @@ -68,8 +68,7 @@ public void importOk() throws Exception { } rs.close(); s1.close(); - } - finally { + } finally { IntegrationTestUtilSql.closeCon(con); } } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpValidatorTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpValidatorTest.java index 8a8ff7b9..5e3b6a3c 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpValidatorTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/ShpValidatorTest.java @@ -2,9 +2,9 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ShpValidatorTest { @Test @@ -15,7 +15,14 @@ public void validationOk() throws Exception { @Test public void validationFail() throws Exception { GradleVariable[] gvs = null; // {GradleVariable.newGradleProperty(TestUtilSql.VARNAME_PG_CON_URI, TestUtilSql.PG_CON_URI)}; - assertEquals(1,IntegrationTestUtil.runJob("src/integrationTest/jobs/ShpValidatorFail", gvs,new StringBuffer(),new StringBuffer())); + assertEquals( + 1, + IntegrationTestUtil.runJob( + "src/integrationTest/jobs/ShpValidatorFail", + gvs, + new StringBuffer(), + new StringBuffer() + ) + ); } - } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/SqlExecutorTaskDuckDbTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/SqlExecutorTaskDuckDbTest.java index 7f80d737..ad11e5d9 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/SqlExecutorTaskDuckDbTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/SqlExecutorTaskDuckDbTest.java @@ -1,14 +1,14 @@ package ch.so.agi.gretl.jobs; -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.nio.file.Files; import java.nio.file.Paths; -import org.junit.Test; - -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; +import static org.junit.jupiter.api.Assertions.assertTrue; public class SqlExecutorTaskDuckDbTest { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/SqlExecutorTaskTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/SqlExecutorTaskTest.java index a2362fbf..99e635d3 100755 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/SqlExecutorTaskTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/SqlExecutorTaskTest.java @@ -4,36 +4,38 @@ import ch.so.agi.gretl.util.GradleVariable; import ch.so.agi.gretl.util.IntegrationTestUtil; import ch.so.agi.gretl.util.IntegrationTestUtilSql; -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Ignore; -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 org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.sql.Connection; -import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.SQLException; import java.sql.Statement; import java.util.HashSet; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Testcontainers public class SqlExecutorTaskTest { - @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)); - - /* - Tests that a chain of statements executes properly - 1. statement: fill the source table with rows - 2. statement: execute the "insert into select from" statement - */ + @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)); + + /** + * Tests that a chain of statements executes properly + * 1. statement: fill the source table with rows + * 2. statement: execute the "insert into select from" statement + * @throws Exception + */ @Test public void taskChainTest() throws Exception { String schemaName = "sqlExecuterTaskChain".toLowerCase(); @@ -58,8 +60,8 @@ public void taskChainTest() throws Exception { int countSrc = IntegrationTestUtilSql.execCountQuery(con, countSrcSql); int countDest = IntegrationTestUtilSql.execCountQuery(con, countDestSql); - Assert.assertEquals("Rowcount in destination table must be equal to rowcount in source table", countSrc, countDest); - Assert.assertTrue("Rowcount in destination table must be greater than zero", countDest > 0); + assertEquals(countSrc, countDest, "Rowcount in destination table must be equal to rowcount in source table"); + assertTrue(countDest > 0, "Rowcount in destination table must be greater than zero"); } finally { IntegrationTestUtilSql.closeCon(con); @@ -68,7 +70,6 @@ public void taskChainTest() throws Exception { /** * Tests if the sql-files can be configured using a relative path. - * * The relative path relates to the location of the build.gradle file * of the corresponding gretl job. */ @@ -119,8 +120,8 @@ public void parameter() throws Exception{ String title=rs.getString(1); titles.add(title); } - Assert.assertEquals(1,titles.size()); - Assert.assertTrue(titles.contains("ele1")); + assertEquals(1, titles.size()); + assertTrue(titles.contains("ele1")); } finally { IntegrationTestUtilSql.closeCon(con); @@ -154,11 +155,10 @@ public void parameterList() throws Exception{ String title=rs.getString(1); titles.add(title); } - Assert.assertEquals(2,titles.size()); - Assert.assertTrue(titles.contains("ele1")); - Assert.assertTrue(titles.contains("ele2")); - } - finally { + assertEquals(2, titles.size()); + assertTrue(titles.contains("ele1")); + assertTrue(titles.contains("ele2")); + } finally { IntegrationTestUtilSql.closeCon(con); } } diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/XslTransformerTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/XslTransformerTest.java index 8dfe6f8e..13755b5c 100644 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/XslTransformerTest.java +++ b/gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/XslTransformerTest.java @@ -1,15 +1,15 @@ package ch.so.agi.gretl.jobs; -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.file.Files; import java.nio.file.Paths; -import org.junit.Test; - -import ch.so.agi.gretl.util.GradleVariable; -import ch.so.agi.gretl.util.IntegrationTestUtil; +import static org.junit.jupiter.api.Assertions.assertTrue; public class XslTransformerTest { diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/testutil/DbDriversReachableTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/testutil/DbDriversReachableTest.java deleted file mode 100755 index 3c0308b4..00000000 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/testutil/DbDriversReachableTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package ch.so.agi.gretl.testutil; - -/** - * Marker for all integration tests that depend - * on database servers. - */ -public interface DbDriversReachableTest {} \ No newline at end of file diff --git a/gretl/src/integrationTest/java/ch/so/agi/gretl/testutil/QgisReachableTest.java b/gretl/src/integrationTest/java/ch/so/agi/gretl/testutil/QgisReachableTest.java deleted file mode 100644 index d84f4221..00000000 --- a/gretl/src/integrationTest/java/ch/so/agi/gretl/testutil/QgisReachableTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package ch.so.agi.gretl.testutil; - -/** - * Marker for all integration tests that depend - * on sogis/qgis-server-base. - */ -public interface QgisReachableTest {} \ No newline at end of file diff --git a/gretl/src/test/java/ch/so/agi/gretl/logging/GradleLoggerTest.java b/gretl/src/test/java/ch/so/agi/gretl/logging/GradleLoggerTest.java index 94934a6a..ba436ac7 100755 --- a/gretl/src/test/java/ch/so/agi/gretl/logging/GradleLoggerTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/logging/GradleLoggerTest.java @@ -2,17 +2,11 @@ import org.gradle.api.logging.LogLevel; import org.gradle.internal.logging.events.LogEvent; -import org.gradle.internal.logging.events.OutputEvent; import org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext; -import org.junit.*; +import org.junit.jupiter.api.Test; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; - -import java.util.logging.Logger; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test-Class for Logger-Class @@ -40,8 +34,8 @@ public void logInfoTest() throws Exception { try { log.info("$Info-Logger-Test$"); LogEvent event = (LogEvent) collector.getEvent(0); - Assert.assertEquals(LogLevel.INFO, event.getLogLevel()); - Assert.assertEquals(event.getMessage(), "$Info-Logger-Test$"); + assertEquals(LogLevel.INFO, event.getLogLevel()); + assertEquals(event.getMessage(), "$Info-Logger-Test$"); } finally { resetSystemOutAndErr(); } @@ -52,8 +46,8 @@ public void logErrorTest() throws Exception { try { log.error("$Error-Logger-Test$", new RuntimeException("Test Exception")); LogEvent event = (LogEvent) collector.getEvent(0); - Assert.assertEquals(LogLevel.ERROR, event.getLogLevel()); - Assert.assertEquals(event.getMessage(), "$Error-Logger-Test$"); + assertEquals(LogLevel.ERROR, event.getLogLevel()); + assertEquals(event.getMessage(), "$Error-Logger-Test$"); } finally { resetSystemOutAndErr(); } @@ -64,8 +58,8 @@ public void logDebugTest() throws Exception { try { log.debug("$Debug-Logger-Test$"); LogEvent event = (LogEvent) collector.getEvent(0); - Assert.assertEquals(LogLevel.DEBUG, event.getLogLevel()); - Assert.assertEquals(event.getMessage(), "$Debug-Logger-Test$"); + assertEquals(LogLevel.DEBUG, event.getLogLevel()); + assertEquals(event.getMessage(), "$Debug-Logger-Test$"); } finally { resetSystemOutAndErr(); } diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/AbstractPublisherStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/AbstractPublisherStepTest.java index 3ac9673e..edee30ef 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/AbstractPublisherStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/AbstractPublisherStepTest.java @@ -5,8 +5,7 @@ import ch.so.agi.gretl.logging.LogEnvironment; import ch.so.agi.gretl.util.SimiSvcClientMock; import org.interlis2.validator.Validator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; @@ -15,20 +14,22 @@ import java.nio.file.Paths; import java.util.*; +import static org.junit.jupiter.api.Assertions.*; + public abstract class AbstractPublisherStepTest { public static final String SRC_TEST_DATA = "src/test/resources/data/publisher"; public static final String SRC_TEST_DATA_FILES = SRC_TEST_DATA + "/files"; public static final String SRC_TEST_DATA_ILI = SRC_TEST_DATA + "/ili"; - protected final static String SRC_DATA_IDENT = "ch.so.agi.vermessung.edit"; - protected final static Date SRC_DATA_DATE_0 = new GregorianCalendar(2021, Calendar.DECEMBER, 2).getTime(); - protected final static Date SRC_DATA_DATE_1 = new GregorianCalendar(2021, Calendar.DECEMBER, 3).getTime(); - protected final static Date SRC_DATA_DATE_2 = new GregorianCalendar(2021, Calendar.DECEMBER, 4).getTime(); - protected final static String SRC_DATA_SIMPLE_FILENAME = "SimpleCoord23a.xtf"; - protected final static String SRC_DATA_AV_FILENAME = "av_test.itf"; - protected final static String SRC_GROOM_FILENAME = "groomTest.json"; - protected final static String SRC_ILI_SIMPLE_FILENAME = "SimpleCoord23.ili"; - protected final static String SRC_ILI_AV_FILENAME = "DM.01-AV-CH_LV95_24d_ili1.ili"; - protected final static String ILI_DIRS = new File(SRC_TEST_DATA_ILI).getAbsolutePath(); + protected static final String SRC_DATA_IDENT = "ch.so.agi.vermessung.edit"; + protected static final Date SRC_DATA_DATE_0 = new GregorianCalendar(2021, Calendar.DECEMBER, 2).getTime(); + protected static final Date SRC_DATA_DATE_1 = new GregorianCalendar(2021, Calendar.DECEMBER, 3).getTime(); + protected static final Date SRC_DATA_DATE_2 = new GregorianCalendar(2021, Calendar.DECEMBER, 4).getTime(); + protected static final String SRC_DATA_SIMPLE_FILENAME = "SimpleCoord23a.xtf"; + protected static final String SRC_DATA_AV_FILENAME = "av_test.itf"; + protected static final String SRC_GROOM_FILENAME = "groomTest.json"; + protected static final String SRC_ILI_SIMPLE_FILENAME = "SimpleCoord23.ili"; + protected static final String SRC_ILI_AV_FILENAME = "DM.01-AV-CH_LV95_24d_ili1.ili"; + protected static final String ILI_DIRS = new File(SRC_TEST_DATA_ILI).getAbsolutePath(); protected final Path localTestOut = Paths.get("build").resolve("out"); protected GretlLogger log; @@ -59,22 +60,22 @@ public void file_allNew() throws Exception { step.publishDatasetFromFile(SRC_DATA_DATE_0,SRC_DATA_IDENT,sourcePath,false,targetPath,null,null,null,null,null,settings,localTestOut, simiSvc); // verify - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_LEAFLET_HTML))); - Assert.assertEquals(SRC_DATA_IDENT, simiSvc.getNotifiedDataIdent()); - Assert.assertEquals(SRC_DATA_DATE_0, simiSvc.getNotifiedPublishDate()); - Assert.assertNull(simiSvc.getNotifiedRegions()); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_LEAFLET_HTML))); + assertEquals(SRC_DATA_IDENT, simiSvc.getNotifiedDataIdent()); + assertEquals(SRC_DATA_DATE_0, simiSvc.getNotifiedPublishDate()); + assertNull(simiSvc.getNotifiedRegions()); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } @Test @@ -96,25 +97,25 @@ public void file_allNew_userFormat() throws Exception { step.publishDatasetFromFile(SRC_DATA_DATE_0,SRC_DATA_IDENT,sourcePath,true,targetPath,null,null,null,null,null,settings,localTestOut, simiSvc); // verify - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".dxf.zip"))); - Assert.assertFalse(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".shp.zip"))); - Assert.assertFalse(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".gpkg.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".dxf.zip"))); + assertFalse(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".shp.zip"))); + assertFalse(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".gpkg.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_LEAFLET_HTML))); - Assert.assertEquals(SRC_DATA_IDENT, simiSvc.getNotifiedDataIdent()); - Assert.assertEquals(SRC_DATA_DATE_0, simiSvc.getNotifiedPublishDate()); - Assert.assertNull(simiSvc.getNotifiedRegions()); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_LEAFLET_HTML))); + assertEquals(SRC_DATA_IDENT, simiSvc.getNotifiedDataIdent()); + assertEquals(SRC_DATA_DATE_0, simiSvc.getNotifiedPublishDate()); + assertNull(simiSvc.getNotifiedRegions()); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } @Test public void file_allNew_groom() throws Exception { @@ -140,22 +141,22 @@ public void file_allNew_groom() throws Exception { step.publishDatasetFromFile(SRC_DATA_DATE_0,SRC_DATA_IDENT,sourcePath,false,targetPath,null,null,null,null,groomFile,settings,localTestOut, simiSvc); // verify - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT + ".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT + ".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_LEAFLET_HTML))); - Assert.assertEquals(SRC_DATA_IDENT, simiSvc.getNotifiedDataIdent()); - Assert.assertEquals(SRC_DATA_DATE_0, simiSvc.getNotifiedPublishDate()); - Assert.assertNull(simiSvc.getNotifiedRegions()); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_LEAFLET_HTML))); + assertEquals(SRC_DATA_IDENT, simiSvc.getNotifiedDataIdent()); + assertEquals(SRC_DATA_DATE_0, simiSvc.getNotifiedPublishDate()); + assertNull(simiSvc.getNotifiedRegions()); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } @Test public void file_allNew_noGroomFile_fail() throws Exception { @@ -180,7 +181,7 @@ public void file_allNew_noGroomFile_fail() throws Exception { try { PublisherStep step = new PublisherStep(); step.publishDatasetFromFile(SRC_DATA_DATE_0,SRC_DATA_IDENT,sourcePath,false,targetPath,null,null,null,null,groomFile,settings,localTestOut, simiSvc); - Assert.fail(); + fail(); } catch (IOException ex) { // ok, expected log.error("file_allNew_noGroomFile_fail", ex); @@ -208,26 +209,26 @@ public void file_regionsRegEx() throws Exception { step.publishDatasetFromFile(SRC_DATA_DATE_0,SRC_DATA_IDENT,sourcePath,false,targetPath,"[0-9][0-9][0-9][0-9]",null,publishedRegions,null,null,settings,localTestOut, null); // verify - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertEquals(2,publishedRegions.size()); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertEquals(2,publishedRegions.size()); for (String controlRegion : new String[] {"2501","2502"}) { - Assert.assertTrue(publishedRegions.contains(controlRegion)); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+SRC_DATA_IDENT+".itf.zip"))); + assertTrue(publishedRegions.contains(controlRegion)); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+SRC_DATA_IDENT+".itf.zip"))); } final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } @Test public void file_regionsList() throws Exception { - Path targetFolder=getTargetPath().resolve(SRC_DATA_IDENT); + Path targetFolder = getTargetPath().resolve(SRC_DATA_IDENT); // prepare // delete output folder if (Files.exists(targetFolder)) { @@ -247,20 +248,20 @@ public void file_regionsList() throws Exception { step.publishDatasetFromFile(SRC_DATA_DATE_0,SRC_DATA_IDENT,sourcePath,false,targetPath,null,regions,publishedRegions,null,null,settings,localTestOut, null); // verify - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertEquals(1,publishedRegions.size()); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertEquals(1,publishedRegions.size()); for(String controlRegion:new String[] {"2501"}) { - Assert.assertTrue(publishedRegions.contains(controlRegion)); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+SRC_DATA_IDENT+".itf.zip"))); + assertTrue(publishedRegions.contains(controlRegion)); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+SRC_DATA_IDENT+".itf.zip"))); } final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } @Test public void file_regionsUpdate() throws Exception { @@ -284,7 +285,7 @@ public void file_regionsUpdate() throws Exception { regions.add("2501"); List publishedRegions = new ArrayList<>(); step.publishDatasetFromFile(SRC_DATA_DATE_1,SRC_DATA_IDENT,sourcePath,false,targetPath,null,regions,publishedRegions,null,null,settings,localTestOut, null); - Assert.assertEquals(1,publishedRegions.size()); + assertEquals(1,publishedRegions.size()); } // incremental second publication @@ -301,35 +302,35 @@ public void file_regionsUpdate() throws Exception { // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertTrue(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertEquals(1,publishedRegions.size()); // nur die neu publizierte Region! (Nicht: alle nun publizierten Regionen) - Assert.assertEquals("2502",publishedRegions.get(0)); + assertTrue(Files.exists(targetFolderAktuell)); + assertTrue(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertEquals(1,publishedRegions.size()); // nur die neu publizierte Region! (Nicht: alle nun publizierten Regionen) + assertEquals("2502",publishedRegions.get(0)); for (String controlRegion:new String[] {"2501","2502"}) { - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+SRC_DATA_IDENT+".itf.zip"))); } final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_1), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_1), PublisherStep.readPublishDate(targetFolderAktuell)); } // verify history { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderHistoryRoot = targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY); final Path targetFolderHistory = targetFolderHistoryRoot.resolve(PublisherStep.getDateTag(SRC_DATA_DATE_0)); - Assert.assertTrue(Files.exists(targetFolderHistory)); - Assert.assertTrue(Files.exists(targetFolderHistory.resolve("2501."+SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderHistory)); + assertTrue(Files.exists(targetFolderHistory.resolve("2501."+SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderHistory.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderHistory)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderHistory)); } } @@ -354,29 +355,29 @@ public void file_firstHistory() throws Exception { step.publishDatasetFromFile(SRC_DATA_DATE,SRC_DATA_IDENT,sourceFile,false,targetPath,null,null,null,null,null,settings,localTestOut, null); // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertTrue(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertTrue(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE), PublisherStep.readPublishDate(targetFolderAktuell)); } // verify history { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderHistoryRoot = targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY); final Path targetFolderHistory = targetFolderHistoryRoot.resolve(PublisherStep.getDateTag(SRC_DATA_DATE_0)); - Assert.assertTrue(Files.exists(targetFolderHistory)); - Assert.assertTrue(Files.exists(targetFolderHistory.resolve(SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderHistory)); + assertTrue(Files.exists(targetFolderHistory.resolve(SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderHistory.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderHistory)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderHistory)); } } @Test @@ -401,31 +402,31 @@ public void file_groomHistory() throws Exception { // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertTrue(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertTrue(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE), PublisherStep.readPublishDate(targetFolderAktuell)); } // verify history { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderHistoryRoot = targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY); final Path targetFolderHistory1 = targetFolderHistoryRoot.resolve(PublisherStep.getDateTag(SRC_DATA_DATE_1)); - Assert.assertFalse(Files.exists(targetFolderHistory1)); + assertFalse(Files.exists(targetFolderHistory1)); final Path targetFolderHistory = targetFolderHistoryRoot.resolve(PublisherStep.getDateTag(SRC_DATA_DATE_0)); - Assert.assertTrue(Files.exists(targetFolderHistory)); - Assert.assertTrue(Files.exists(targetFolderHistory.resolve(SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderHistory)); + assertTrue(Files.exists(targetFolderHistory.resolve(SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderHistory.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderHistory)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderHistory)); } } @Test @@ -455,16 +456,16 @@ public void file_overwriteAktuell() throws Exception { step.publishDatasetFromFile(SRC_DATA_DATE,SRC_DATA_IDENT,sourceFile,false,targetPath,null,null,null,null,null,settings,localTestOut, null); // verify { - Assert.assertTrue(Files.exists(targetFolder)); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); - Assert.assertFalse(Files.exists(unexpectedTargetFile)); + assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(SRC_DATA_IDENT+".itf.zip"))); + assertFalse(Files.exists(unexpectedTargetFile)); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE), PublisherStep.readPublishDate(targetFolderAktuell)); } } @Test @@ -487,9 +488,9 @@ public void file_newExistingHistory_fail() throws Exception { try { step.publishDatasetFromFile(SRC_DATA_DATE_0,SRC_DATA_IDENT,sourceFile,false,targetPath,null,null,null,null,null,settings,localTestOut, null); - Assert.fail(); + fail(); } catch (IllegalArgumentException ex) { - Assert.assertEquals("neuer Stand (2021-12-02) existiert auch schon als History",ex.getMessage()); + assertEquals("neuer Stand (2021-12-02) existiert auch schon als History",ex.getMessage()); } } } diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/Csv2ExcelStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/Csv2ExcelStepTest.java index f3903c57..4020a428 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/Csv2ExcelStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/Csv2ExcelStepTest.java @@ -8,22 +8,21 @@ import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.interlis2.validator.Validator; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.FileInputStream; import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class Csv2ExcelStepTest { - - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - + + @TempDir + public Path folder; + @Test public void encoding_iso_8859_1_Ok() throws Exception { // Prepare @@ -35,14 +34,13 @@ public void encoding_iso_8859_1_Ok() throws Exception { settings.setValue(Validator.SETTING_MODELNAMES, "SO_HBA_Gebaeude_20230111"); File csvFile = TestUtil.getResourceFile(TestUtil.SAP_GEBAEUDE_CSV_PATH); - Path outputPath = folder.newFolder().toPath(); // Run Csv2ExcelStep csv2excelStep = new Csv2ExcelStep(); - csv2excelStep.execute(csvFile.toPath(), outputPath, settings); + csv2excelStep.execute(csvFile.toPath(), folder, settings); // Validate - FileInputStream fis = new FileInputStream(Paths.get(outputPath.toFile().getAbsolutePath(), "20230124_sap_Gebaeude.xlsx").toFile()); + FileInputStream fis = new FileInputStream(Paths.get(folder.toFile().getAbsolutePath(), "20230124_sap_Gebaeude.xlsx").toFile()); XSSFWorkbook workbook = new XSSFWorkbook(fis); XSSFSheet sheet = workbook.getSheetAt(0); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/Csv2ParquetStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/Csv2ParquetStepTest.java index 0ca7d082..0dfd944a 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/Csv2ParquetStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/Csv2ParquetStepTest.java @@ -1,16 +1,8 @@ package ch.so.agi.gretl.steps; -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; - +import ch.ehi.basics.settings.Settings; +import ch.interlis.iom_j.csv.CsvReader; +import ch.interlis.ioxwkf.dbtools.IoxWkfConfig; import ch.so.agi.gretl.testutil.TestUtil; import org.apache.avro.generic.GenericRecord; import org.apache.commons.io.FilenameUtils; @@ -19,20 +11,23 @@ import org.apache.parquet.hadoop.ParquetReader; import org.apache.parquet.hadoop.util.HadoopInputFile; import org.interlis2.validator.Validator; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; -import ch.ehi.basics.settings.Settings; -import ch.interlis.iom_j.csv.CsvReader; -import ch.interlis.ioxwkf.dbtools.IoxWkfConfig; +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.*; +import java.time.format.DateTimeFormatter; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class Csv2ParquetStepTest { + private static final Configuration testConf = new Configuration(); - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + + @TempDir + public Path folder; @Test public void encoding_iso_8859_1_Ok() throws Exception { @@ -45,15 +40,14 @@ public void encoding_iso_8859_1_Ok() throws Exception { settings.setValue(Validator.SETTING_MODELNAMES, "SO_HBA_Gebaeude_20230111"); File csvFile = TestUtil.getResourceFile(TestUtil.SAP_GEBAEUDE_CSV_PATH); - Path outputPath = folder.newFolder().toPath(); // Run Csv2ParquetStep csv2parquetStep = new Csv2ParquetStep(); - csv2parquetStep.execute(csvFile.toPath(), outputPath, settings); + csv2parquetStep.execute(csvFile.toPath(), folder, settings); // Validate org.apache.hadoop.fs.Path resultFile = new org.apache.hadoop.fs.Path(Paths - .get(outputPath.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); + .get(folder.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); try (ParquetReader reader = AvroParquetReader .builder(HadoopInputFile.fromPath(resultFile, testConf)).build() @@ -73,15 +67,14 @@ public void date_datatypes_handling_Ok() throws Exception { settings.setValue(Validator.SETTING_MODELNAMES, "Date_202306016"); File csvFile = TestUtil.getResourceFile(TestUtil.DATE_DATATYPES_CSV_PATH); - Path outputPath = folder.newFolder().toPath(); // Run Csv2ParquetStep csv2parquetStep = new Csv2ParquetStep(); - csv2parquetStep.execute(csvFile.toPath(), outputPath, settings); + csv2parquetStep.execute(csvFile.toPath(), folder, settings); // Validate org.apache.hadoop.fs.Path resultFile = new org.apache.hadoop.fs.Path(Paths - .get(outputPath.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); + .get(folder.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); try (ParquetReader reader = AvroParquetReader .builder(HadoopInputFile.fromPath(resultFile, testConf)).build() @@ -117,15 +110,14 @@ public void model_set_Ok() throws Exception { settings.setValue(Validator.SETTING_MODELNAMES, "SO_AFU_Bewilligte_Erdwaermeanlagen_20230616"); File csvFile = TestUtil.getResourceFile(TestUtil.BEWILLIGTE_ERDWAERMEANLAGEN_CSV_PATH); - Path outputPath = folder.newFolder().toPath(); // Run Csv2ParquetStep csv2parquetStep = new Csv2ParquetStep(); - csv2parquetStep.execute(csvFile.toPath(), outputPath, settings); + csv2parquetStep.execute(csvFile.toPath(), folder, settings); // Validate org.apache.hadoop.fs.Path resultFile = new org.apache.hadoop.fs.Path(Paths - .get(outputPath.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); + .get(folder.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); try (ParquetReader reader = AvroParquetReader .builder(HadoopInputFile.fromPath(resultFile, testConf)).build() @@ -162,15 +154,14 @@ public void no_model_set_Ok() throws Exception { settings.setValue(IoxWkfConfig.SETTING_VALUESEPARATOR, ";"); File csvFile = TestUtil.getResourceFile(TestUtil.BEWILLIGTE_ERDWAERMEANLAGEN_CSV_PATH); - Path outputPath = folder.newFolder().toPath(); // Run Csv2ParquetStep csv2parquetStep = new Csv2ParquetStep(); - csv2parquetStep.execute(csvFile.toPath(), outputPath, settings); + csv2parquetStep.execute(csvFile.toPath(), folder, settings); // Validate org.apache.hadoop.fs.Path resultFile = new org.apache.hadoop.fs.Path(Paths - .get(outputPath.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); + .get(folder.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); try (ParquetReader reader = AvroParquetReader .builder(HadoopInputFile.fromPath(resultFile, testConf)).build() @@ -206,15 +197,14 @@ public void custom_config_and_no_model_set_Ok() throws Exception { settings.setValue(IoxWkfConfig.SETTING_VALUESEPARATOR, ";"); File csvFile = TestUtil.getResourceFile(TestUtil.BEWILLIGTE_ERDWAERMEANLAGEN_SEMIKOLON_HOCHKOMMA_CSV_PATH); - Path outputPath = folder.newFolder().toPath(); // Run Csv2ParquetStep csv2parquetStep = new Csv2ParquetStep(); - csv2parquetStep.execute(csvFile.toPath(), outputPath, settings); + csv2parquetStep.execute(csvFile.toPath(), folder, settings); // Validate org.apache.hadoop.fs.Path resultFile = new org.apache.hadoop.fs.Path(Paths - .get(outputPath.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); + .get(folder.toString(), FilenameUtils.getBaseName(csvFile.toPath().toString()) + ".parquet").toString()); try (ParquetReader reader = AvroParquetReader .builder(HadoopInputFile.fromPath(resultFile, testConf)).build() diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/DatabaseDocumentExportStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/DatabaseDocumentExportStepTest.java index 154af11c..30045063 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/DatabaseDocumentExportStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/DatabaseDocumentExportStepTest.java @@ -1,28 +1,34 @@ package ch.so.agi.gretl.steps; +import ch.so.agi.gretl.api.Connector; +import ch.so.agi.gretl.logging.GretlLogger; +import ch.so.agi.gretl.logging.LogEnvironment; +import ch.so.agi.gretl.testutil.TestUtil; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.testcontainers.containers.PostgisContainerProvider; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + import java.io.File; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.sql.Connection; import java.sql.Statement; -import org.junit.*; -import org.junit.rules.TemporaryFolder; -import org.testcontainers.containers.PostgisContainerProvider; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.containers.wait.strategy.Wait; - -import ch.so.agi.gretl.api.Connector; -import ch.so.agi.gretl.logging.GretlLogger; -import ch.so.agi.gretl.logging.LogEnvironment; -import ch.so.agi.gretl.testutil.TestUtil; - -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +@Testcontainers public class DatabaseDocumentExportStepTest { - @ClassRule - public static PostgreSQLContainer postgres = + @Container + public PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgisContainerProvider().newInstance() .withDatabaseName(TestUtil.PG_DB_NAME) .withUsername(TestUtil.PG_DDLUSR_USR) @@ -36,8 +42,8 @@ public class DatabaseDocumentExportStepTest { private final String columnName; private Connector connector; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; public DatabaseDocumentExportStepTest() { this.log = LogEnvironment.getLogger(this.getClass()); @@ -45,18 +51,18 @@ public DatabaseDocumentExportStepTest() { this.tableName = "fachapplikation_rechtsvorschrift_link"; this.columnName = "multimedia_link"; } - + // TODO: // Die mühsamen self-signed Zertifikate des AIO können schlecht getestet werden. A) Nur intern B) Filenamen können sich ändern. // https://artplus.verw.rootso.org/MpWeb-apSolothurnDenkmal/download/2W8v0qRZQBC0ahDnZGut3Q?mode=gis // Manuell getestet... - @Before + @BeforeEach public void before() throws Exception { this.connector = new Connector(postgres.getJdbcUrl(), TestUtil.PG_DDLUSR_USR, TestUtil.PG_DDLUSR_PWD); } - @After + @AfterEach public void after() throws Exception { if (!this.connector.isClosed()) { this.connector.close(); @@ -65,8 +71,6 @@ public void after() throws Exception { @Test public void exportDocuments_Ok() throws Exception { - File targetDir = folder.newFolder(); - try (Connection con = connector.connect(); Statement stmt = con.createStatement()) { con.setAutoCommit(false); initializeSchema(con, stmt); @@ -74,9 +78,9 @@ public void exportDocuments_Ok() throws Exception { con.commit(); DatabaseDocumentExportStep databaseDocumentExport = new DatabaseDocumentExportStep(); - databaseDocumentExport.execute(connector, schemaName+"."+tableName, columnName, targetDir.getAbsolutePath(), "ada_", "pdf"); + databaseDocumentExport.execute(connector, schemaName+"."+tableName, columnName, folder.toAbsolutePath().toString(), "ada_", "pdf"); - File resultFile = Paths.get(targetDir.getAbsolutePath(), "ada_ilimodels.xml.pdf").toFile(); + File resultFile = Paths.get(folder.toAbsolutePath().toString(), "ada_ilimodels.xml.pdf").toFile(); assertTrue(resultFile.exists()); assertTrue(resultFile.length() > 60L); @@ -89,8 +93,6 @@ public void exportDocuments_Ok() throws Exception { // https://stackoverflow.com/questions/1884230/httpurlconnection-doesnt-follow-redirect-from-http-to-https @Test public void exportDocuments_Fail() throws Exception { - File targetDir = folder.newFolder(); - try (Connection con = connector.connect(); Statement stmt = con.createStatement()) { con.setAutoCommit(false); initializeSchema(con, stmt); @@ -98,18 +100,16 @@ public void exportDocuments_Fail() throws Exception { con.commit(); DatabaseDocumentExportStep databaseDocumentExport = new DatabaseDocumentExportStep(); - databaseDocumentExport.execute(connector, schemaName+"."+tableName, columnName, targetDir.getAbsolutePath(), "ada_", "pdf"); + databaseDocumentExport.execute(connector, schemaName+"."+tableName, columnName, folder.toAbsolutePath().toString(), "ada_", "pdf"); - File resultFile = Paths.get(targetDir.getAbsolutePath(), "ada_ilimodels.xml.pdf").toFile(); + File resultFile = Paths.get(folder.toAbsolutePath().toString(), "ada_ilimodels.xml.pdf").toFile(); assertFalse(resultFile.exists()); } } - @Test + @Test public void exportDocuments_WithoutPrefix_Ok() throws Exception { - File targetDir = folder.newFolder(); - - log.debug("targetDir: " + targetDir.getAbsolutePath()); + log.debug("targetDir: " + folder.toAbsolutePath()); try (Connection con = connector.connect(); Statement stmt = con.createStatement()) { con.setAutoCommit(false); @@ -119,9 +119,9 @@ public void exportDocuments_WithoutPrefix_Ok() throws Exception { con.commit(); DatabaseDocumentExportStep databaseDocumentExport = new DatabaseDocumentExportStep(); - databaseDocumentExport.execute(connector, schemaName+"."+tableName, columnName, targetDir.getAbsolutePath(), null, "pdf"); + databaseDocumentExport.execute(connector, schemaName+"."+tableName, columnName, folder.toAbsolutePath().toString(), null, "pdf"); - File resultFile = Paths.get(targetDir.getAbsolutePath(), "ilimodels.xml.pdf").toFile(); + File resultFile = Paths.get(folder.toAbsolutePath().toString(), "ilimodels.xml.pdf").toFile(); assertTrue(resultFile.exists()); assertTrue(resultFile.length() > 60L); @@ -130,10 +130,9 @@ public void exportDocuments_WithoutPrefix_Ok() throws Exception { } } - @Test + @Test public void exportDocuments_WithoutFileNameExtension_Ok() throws Exception { - File targetDir = folder.newFolder(); - log.debug("targetDir: " + targetDir.getAbsolutePath()); + log.debug("targetDir: " + folder.toAbsolutePath()); try (Connection con = connector.connect(); Statement stmt = con.createStatement()) { con.setAutoCommit(false); @@ -142,9 +141,9 @@ public void exportDocuments_WithoutFileNameExtension_Ok() throws Exception { con.commit(); DatabaseDocumentExportStep databaseDocumentExport = new DatabaseDocumentExportStep(); - databaseDocumentExport.execute(connector, schemaName+"."+tableName, columnName, targetDir.getAbsolutePath(), null, null); + databaseDocumentExport.execute(connector, schemaName+"."+tableName, columnName, folder.toAbsolutePath().toString(), null, null); - File resultFile = Paths.get(targetDir.getAbsolutePath(), "ilimodels.xml").toFile(); + File resultFile = Paths.get(folder.toAbsolutePath().toString(), "ilimodels.xml").toFile(); assertTrue(resultFile.exists()); assertTrue(resultFile.length() > 60L); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/Db2DbStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/Db2DbStepTest.java index 0348323b..a7ce79d1 100755 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/Db2DbStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/Db2DbStepTest.java @@ -2,16 +2,20 @@ import ch.so.agi.gretl.api.Connector; import ch.so.agi.gretl.api.TransferSet; -import ch.so.agi.gretl.testutil.DbTest; +import ch.so.agi.gretl.testutil.TestTags; import ch.so.agi.gretl.testutil.TestUtil; import ch.so.agi.gretl.util.EmptyFileException; import ch.so.agi.gretl.util.GretlException; -import org.junit.*; -import org.junit.experimental.categories.Category; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.io.File; import java.io.IOException; @@ -21,15 +25,15 @@ import java.sql.*; import java.util.*; -import static org.gradle.internal.impldep.org.testng.AssertJUnit.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; +@Testcontainers public class Db2DbStepTest { private static final String GEOM_WKT = "LINESTRING(2600000 1200000,2600001 1200001)"; - @ClassRule - public static PostgreSQLContainer postgres = + @Container + public PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgisContainerProvider().newInstance() .withDatabaseName(TestUtil.PG_DB_NAME) .withUsername(TestUtil.PG_DDLUSR_USR) @@ -38,16 +42,16 @@ public class Db2DbStepTest { private Connector connector; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; - @Before + @BeforeEach public void before() throws Exception { this.connector = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null); createTestDb(this.connector); } - @After + @AfterEach public void after() throws Exception { Connector sourceDb = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null); clearTestDb(sourceDb); @@ -90,7 +94,7 @@ public void newlineAtEndOfFileTest_Ok() throws Exception { db2db.processAllTransferSets(this.connector, this.connector, transferSets); } - @Test(expected = IOException.class) + @Test public void fileWithMultipleStmtTest_throwsIOException() throws Exception { String content = "SELECT * FROM colors;" + System.lineSeparator() + "SELECT * FROM colors;"; File sqlFile = TestUtil.createTempFile(folder, content, "query.sql"); @@ -98,33 +102,39 @@ public void fileWithMultipleStmtTest_throwsIOException() throws Exception { new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", true) )); - Db2DbStep db2db = new Db2DbStep(); - db2db.processAllTransferSets(this.connector, this.connector, transferSets); - Assert.fail(); + assertThrows(IOException.class, () -> { + Db2DbStep db2db = new Db2DbStep(); + db2db.processAllTransferSets(this.connector, this.connector, transferSets); + fail(); + }); } - @Test(expected = EmptyFileException.class) + @Test public void db2dbEmptyFile_throwsEmptyFileException() throws Exception { File sqlFile = TestUtil.createTempFile(folder, "", "query.sql"); ArrayList transferSets = new ArrayList<>(Collections.singletonList( new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", Boolean.FALSE) )); - Db2DbStep db2db = new Db2DbStep(); - db2db.processAllTransferSets(this.connector, this.connector, transferSets); - Assert.fail("EmptyFileException müsste geworfen werden"); + assertThrows(EmptyFileException.class, () -> { + Db2DbStep db2db = new Db2DbStep(); + db2db.processAllTransferSets(this.connector, this.connector, transferSets); + fail("EmptyFileException müsste geworfen werden"); + }); } - @Test(expected = SQLException.class) + @Test public void invalidSql_throwsSqlException() throws Exception { File sqlFile = TestUtil.createTempFile(folder, "SELECT somethingInvalid FROM colors", "query.sql"); ArrayList transferSets = new ArrayList<>(Collections.singletonList( new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", Boolean.FALSE) )); - Db2DbStep db2db = new Db2DbStep(); - db2db.processAllTransferSets(this.connector, this.connector, transferSets); - Assert.fail("EmptyFileException müsste geworfen werden"); + assertThrows(SQLException.class, () -> { + Db2DbStep db2db = new Db2DbStep(); + db2db.processAllTransferSets(this.connector, this.connector, transferSets); + fail("EmptyFileException müsste geworfen werden"); + }); } @Test @@ -143,8 +153,7 @@ public void columnNumberTest() throws Exception { Connector targetDb = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null); Db2DbStep db2db = new Db2DbStep(); db2db.processAllTransferSets(sourceDb, targetDb, transferSets); - - Assert.fail("Eine Exception müsste geworfen werden. "); + fail("Eine Exception müsste geworfen werden."); } catch (GretlException ge) { boolean isMismatchException = GretlException.TYPE_COLUMN_MISMATCH.equals(ge.getType()); if (!isMismatchException) { @@ -153,10 +162,11 @@ public void columnNumberTest() throws Exception { } } - @Test(expected = SQLException.class) + @Test public void incompatibleDataType_throwsSqlException() throws Exception { try (Connection connection = this.connector.connect(); Statement stmt = connection.createStatement()) { - stmt.execute("DROP TABLE colors_copy; CREATE TABLE colors_copy (rot integer, gruen integer, blau integer, farbname integer)"); + stmt.execute("DROP TABLE colors_copy"); + stmt.execute("CREATE TABLE colors_copy (rot integer, gruen integer, blau integer, farbname integer)"); File sqlFile = TestUtil.createTempFile(folder, "SELECT * FROM colors", "query.sql"); ArrayList transferSets = new ArrayList<>(Collections.singletonList( @@ -164,11 +174,11 @@ public void incompatibleDataType_throwsSqlException() throws Exception { )); Connector sourceDb = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null); Connector targetDb = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null); - Db2DbStep db2db = new Db2DbStep(); - - db2db.processAllTransferSets(sourceDb, targetDb, transferSets); - Assert.fail("Eine Exception müsste geworfen werden. "); + assertThrows(SQLException.class, () -> { + Db2DbStep db2db = new Db2DbStep(); + db2db.processAllTransferSets(sourceDb, targetDb, transferSets); + }); } } @@ -181,7 +191,6 @@ public void copyEmptyTableToOtherTable_Ok() throws Exception { Connector sourceDb = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null); Connector targetDb = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null); Db2DbStep db2db = new Db2DbStep(); - db2db.processAllTransferSets(sourceDb, targetDb, transferSets); } @@ -225,8 +234,8 @@ public void closeConnectionsTest_connectionsClosed() throws Exception { Db2DbStep db2db = new Db2DbStep(); db2db.processAllTransferSets(sourceDb, targetDb, transferSets); - Assert.assertTrue("SourceConnection is not closed", sourceDb.isClosed()); - Assert.assertTrue("TargetConnection is not closed", targetDb.isClosed()); + assertTrue(sourceDb.isClosed(), "SourceConnection is not closed"); + assertTrue(targetDb.isClosed(), "TargetConnection is not closed"); } @Test @@ -241,13 +250,13 @@ public void closeConnectionsAfterFailedTest_connectionsClosed() throws Exception Connector targetDb = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null); Db2DbStep db2db = new Db2DbStep(); - Assert.assertThrows(SQLException.class, () -> db2db.processAllTransferSets(sourceDb, targetDb, transferSets)); - Assert.assertTrue("SourceConnection is not closed", sourceDb.isClosed()); - Assert.assertTrue("TargetConnection is not closed", targetDb.isClosed()); + assertThrows(SQLException.class, () -> db2db.processAllTransferSets(sourceDb, targetDb, transferSets)); + assertTrue(sourceDb.isClosed(), "SourceConnection is not closed"); + assertTrue(targetDb.isClosed(), "TargetConnection is not closed"); } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void canWriteGeomFromWkbTest_Ok() throws Exception { String schemaName = "GeomFromWkbTest"; @@ -278,7 +287,7 @@ public void canWriteGeomFromWkbTest_Ok() throws Exception { } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void canWriteGeomFromWktTest_Ok() throws Exception { String schemaName = "GeomFromWktTest"; @@ -309,7 +318,7 @@ public void canWriteGeomFromWktTest_Ok() throws Exception { } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void canWriteGeomFromGeoJsonTest_Ok() throws Exception { String schemaName = "GeomFromGeoJsonTest"; @@ -343,7 +352,7 @@ public void canWriteGeomFromGeoJsonTest_Ok() throws Exception { * 300'000 rows should take about 15 seconds */ @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void positiveBulkLoadPostgisTest_Ok() throws Exception { int numRows = 300000; String schemaName = "BULKLOAD2POSTGIS"; @@ -380,7 +389,7 @@ public void positiveBulkLoadPostgisTest_Ok() throws Exception { ResultSet rs = checkStmt.executeQuery(checkSQL); rs.next(); - Assert.assertEquals("Check Statement must return exactly " + numRows, numRows, rs.getInt(1)); + assertEquals(numRows, rs.getInt(1), "Check Statement must return exactly " + numRows); dropSchema(schemaName, targetCon); } } @@ -390,7 +399,7 @@ public void positiveBulkLoadPostgisTest_Ok() throws Exception { * from sqlite to postgis */ @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void positiveSqlite2PostgisTest_Ok() throws Exception { String schemaName = "SQLITE2POSTGIS"; File sqliteDb = createTmpDb(schemaName); @@ -429,7 +438,7 @@ public void positiveSqlite2PostgisTest_Ok() throws Exception { ResultSet rs = checkStmt.executeQuery(checkSql); rs.next(); - Assert.assertEquals("Check Statement must return exactly one row", 1, rs.getInt(1)); + assertEquals(1, rs.getInt(1), "Check Statement must return exactly one row"); } } @@ -438,7 +447,7 @@ public void positiveSqlite2PostgisTest_Ok() throws Exception { * transferred faultfree from Postgis to sqlite */ @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void positivePostgis2SqliteTest_Ok() throws Exception { String schemaName = "POSTGIS2SQLITE"; File sqliteDb = createTmpDb(schemaName); @@ -471,7 +480,7 @@ public void positivePostgis2SqliteTest_Ok() throws Exception { ResultSet rs = checkStmt.executeQuery(checkSQL); rs.next(); - Assert.assertEquals("Check Statement must return exactly one row", 1, rs.getInt(1)); + assertEquals(1, rs.getInt(1), "Check Statement must return exactly one row"); dropSchema(schemaName, srcCon); } } @@ -574,7 +583,7 @@ private static void assertEqualGeomInSourceAndSink(Connection con, String schema rs.next(); String geomRes = rs.getString(1).trim().toUpperCase(); - Assert.assertEquals(expectedMessage, GEOM_WKT, geomRes); + assertEquals(GEOM_WKT, geomRes, expectedMessage); } } @@ -601,7 +610,7 @@ private void dropSchema(String schemaName, Connection con) throws SQLException { } } - private static Connection connectToPreparedPgDb(String schemaName) throws Exception { + private Connection connectToPreparedPgDb(String schemaName) throws Exception { String url = postgres.getJdbcUrl(); String user = postgres.getUsername(); String password = postgres.getPassword(); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/Gpkg2DxfStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/Gpkg2DxfStepTest.java index b16b2603..dce32c64 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/Gpkg2DxfStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/Gpkg2DxfStepTest.java @@ -1,35 +1,34 @@ package ch.so.agi.gretl.steps; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class Gpkg2DxfStepTest { - - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + + @TempDir + public Path folder; @Test public void export_Ok() throws Exception { - String TEST_OUT = folder.newFolder().getAbsolutePath(); File gpkgFile = TestUtil.getResourceFile(TestUtil.ADMINISTRATIVE_EINSTELLUNGEN_GPKG_PATH); Gpkg2DxfStep gpkg2dxfStep = new Gpkg2DxfStep(); - gpkg2dxfStep.execute(gpkgFile.getAbsolutePath(), TEST_OUT); + gpkg2dxfStep.execute(gpkgFile.getAbsolutePath(), folder.toAbsolutePath().toString()); // Check results - String contentNF = new String(Files.readAllBytes(Paths.get(TEST_OUT, "nachfuehrngskrise_gemeinde.dxf"))); + String contentNF = new String(Files.readAllBytes(Paths.get(folder.toAbsolutePath().toString(), "nachfuehrngskrise_gemeinde.dxf"))); assertTrue(contentNF.contains("LerchWeberAG")); assertTrue(contentNF.contains("2638171.578")); - String contentGB = new String(Files.readAllBytes(Paths.get(TEST_OUT, "grundbuchkreise_grundbuchkreis.dxf"))); + String contentGB = new String(Files.readAllBytes(Paths.get(folder.toAbsolutePath().toString(), "grundbuchkreise_grundbuchkreis.dxf"))); assertTrue(contentGB.contains("2619682.201")); } } diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/Gpkg2ShpStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/Gpkg2ShpStepTest.java index 8de878ed..6437b38b 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/Gpkg2ShpStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/Gpkg2ShpStepTest.java @@ -4,58 +4,54 @@ import org.geotools.data.FileDataStore; import org.geotools.data.FileDataStoreFinder; import org.geotools.data.simple.SimpleFeatureSource; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.opengis.feature.type.AttributeDescriptor; import java.io.File; +import java.nio.file.Path; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class Gpkg2ShpStepTest { + + @TempDir + public Path folder; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - - @Test + @Test public void export_no_Geometry_Ok() throws Exception { - String TEST_OUT = folder.newFolder().getAbsolutePath(); File gpkgFile = TestUtil.getResourceFile(TestUtil.AGGLOPROGRAMME_GPKG_PATH); Gpkg2ShpStep gpkg2shpStep = new Gpkg2ShpStep(); - gpkg2shpStep.execute(gpkgFile.getAbsolutePath(), TEST_OUT); + gpkg2shpStep.execute(gpkgFile.getAbsolutePath(), folder.toAbsolutePath().toString()); // Check results { - FileDataStore dataStore = FileDataStoreFinder.getDataStore(new File(TEST_OUT, "massnahmen.shp")); + FileDataStore dataStore = FileDataStoreFinder.getDataStore(new File(folder.toAbsolutePath().toString(), "massnahmen.shp")); SimpleFeatureSource featuresSource = dataStore.getFeatureSource(); - assertEquals(451, featuresSource.getFeatures().size()); - + assertEquals(451, featuresSource.getFeatures().size()); assertEquals(35, featuresSource.getSchema().getAttributeCount()); } } @Test public void export_Ok() throws Exception { - String TEST_OUT = folder.newFolder().getAbsolutePath(); File gpkgFile = TestUtil.getResourceFile("data/gpkg2shp/ch.so.agi_av_gb_administrative_einteilungen_2020-08-20.gpkg"); Gpkg2ShpStep gpkg2shpStep = new Gpkg2ShpStep(); - gpkg2shpStep.execute(gpkgFile.getAbsolutePath(), TEST_OUT); + gpkg2shpStep.execute(gpkgFile.getAbsolutePath(), folder.toAbsolutePath().toString()); //Check results { - FileDataStore dataStore = FileDataStoreFinder.getDataStore(new File(TEST_OUT, "nachfuehrngskrise_gemeinde.shp")); + FileDataStore dataStore = FileDataStoreFinder.getDataStore(new File(folder.toAbsolutePath().toString(), "nachfuehrngskrise_gemeinde.shp")); SimpleFeatureSource featuresSource = dataStore.getFeatureSource(); assertEquals(109, featuresSource.getFeatures().size()); assertEquals("CH1903+_LV95", featuresSource.getSchema().getCoordinateReferenceSystem().getName().toString()); } { - FileDataStore dataStore = FileDataStoreFinder.getDataStore(new File(TEST_OUT, "grundbuchkreise_grundbuchkreis.shp")); + FileDataStore dataStore = FileDataStoreFinder.getDataStore(new File(folder.toAbsolutePath().toString(), "grundbuchkreise_grundbuchkreis.shp")); SimpleFeatureSource featuresSource = dataStore.getFeatureSource(); assertEquals(127, featuresSource.getFeatures().size()); assertEquals("CH1903+_LV95", featuresSource.getSchema().getCoordinateReferenceSystem().getName().toString()); - assertEquals(19, featuresSource.getSchema().getAttributeCount()); AttributeDescriptor attrDesc = featuresSource.getSchema().getDescriptor("plz"); @@ -65,16 +61,13 @@ public void export_Ok() throws Exception { @Test public void export_more_attribute_types_Ok() throws Exception { - String TEST_OUT = folder.newFolder().getAbsolutePath(); - //String TEST_OUT = "/Users/stefan/tmp/shp/"; - File gpkgFile = TestUtil.getResourceFile("data/gpkg2shp/ch.so.afu.abbaustellen.gpkg"); Gpkg2ShpStep gpkg2shpStep = new Gpkg2ShpStep(); - gpkg2shpStep.execute(gpkgFile.getAbsolutePath(), TEST_OUT); + gpkg2shpStep.execute(gpkgFile.getAbsolutePath(), folder.toAbsolutePath().toString()); // Check results { - FileDataStore dataStore = FileDataStoreFinder.getDataStore(new File(TEST_OUT, "abbaustelle.shp")); + FileDataStore dataStore = FileDataStoreFinder.getDataStore(new File(folder.toAbsolutePath().toString(), "abbaustelle.shp")); SimpleFeatureSource featuresSource = dataStore.getFeatureSource(); assertEquals(98, featuresSource.getFeatures().size()); assertEquals("CH1903+_LV95", diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/GzipStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/GzipStepTest.java index 57bacab9..851e2e7f 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/GzipStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/GzipStepTest.java @@ -3,26 +3,27 @@ import ch.so.agi.gretl.logging.GretlLogger; import ch.so.agi.gretl.logging.LogEnvironment; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.zip.GZIPInputStream; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class GzipStepTest { private final GretlLogger log; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + + @TempDir + public Path folder; public GzipStepTest() { this.log = LogEnvironment.getLogger(this.getClass()); @@ -30,9 +31,9 @@ public GzipStepTest() { @Test public void compress_file_Ok() throws Exception { - File outDirectory = folder.newFolder("transformFile_Ok"); + Path outDirectory = TestUtil.createTempDir(folder, "transformFile_Ok"); File dataFile = TestUtil.getResourceFile(TestUtil.PLANREGISTER_XML_PATH); - File gzipFile = Paths.get(outDirectory.getAbsolutePath(), "planregister.xml.gz").toFile(); + File gzipFile = Paths.get(outDirectory.toAbsolutePath().toString(), "planregister.xml.gz").toFile(); // Transform File GzipStep gzipStep = new GzipStep(); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/JsonImportStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/JsonImportStepTest.java index 1322de63..b0148275 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/JsonImportStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/JsonImportStepTest.java @@ -2,24 +2,30 @@ import ch.so.agi.gretl.api.Connector; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.*; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.io.File; +import java.nio.file.Path; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +@Testcontainers public class JsonImportStepTest { - @ClassRule - public static PostgreSQLContainer postgres = + @Container + public PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgisContainerProvider().newInstance() .withDatabaseName(TestUtil.PG_DB_NAME) .withUsername(TestUtil.PG_DDLUSR_USR) @@ -32,8 +38,8 @@ public class JsonImportStepTest { private final String columnName; private Connector connector; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; public JsonImportStepTest() { this.schemaName = "jsonimport"; @@ -41,12 +47,12 @@ public JsonImportStepTest() { this.columnName = "json_text_col"; } - @Before + @BeforeEach public void before() throws Exception { this.connector = new Connector(postgres.getJdbcUrl(), TestUtil.PG_DDLUSR_USR, TestUtil.PG_DDLUSR_PWD); } - @After + @AfterEach public void after() throws Exception { if (!this.connector.isClosed()) { this.connector.close(); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/MetaPublisherStepTestFile2LocalTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/MetaPublisherStepTestFile2LocalTest.java index 344c01cd..e65b3fff 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/MetaPublisherStepTestFile2LocalTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/MetaPublisherStepTestFile2LocalTest.java @@ -1,9 +1,8 @@ package ch.so.agi.gretl.steps; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.nio.file.Files; import java.nio.file.Path; @@ -12,7 +11,8 @@ import java.util.Date; import java.util.List; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class MetaPublisherStepTestFile2LocalTest { @@ -21,14 +21,14 @@ public class MetaPublisherStepTestFile2LocalTest { public static final String PATH_ELE_CONFIG = "config"; public static final String GEOCAT_FTP_DIR_INT = "int"; public static final String GEOCAT_FTP_DIR_PROD = "prod"; - - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + + @TempDir + public Path folder; @Test public void publish_raster_geocat_Ok() throws Exception { - Path target = folder.newFolder("publish_raster_geocat_Ok").toPath(); - Path geocatTarget = folder.newFolder("publish_raster_geocat_Ok_geocat").toPath(); + Path target = TestUtil.createTempDir(folder, "publish_raster_geocat_Ok"); + Path geocatTarget = TestUtil.createTempDir(folder, "publish_raster_geocat_Ok_geocat"); String themePublication = "ch.so.agi.orthofoto_1993.grau"; // Run step @@ -51,7 +51,7 @@ public void publish_raster_geocat_Ok() throws Exception { @Test public void publish_simple_meta_Ok() throws Exception { // Prepare - Path target = folder.newFolder("publish_simple_meta_Ok").toPath(); + Path target = TestUtil.createTempDir(folder, "publish_simple_meta_Ok"); String themePublication = "ch.so.afu.abbaustellen"; // Run step @@ -79,8 +79,8 @@ public void publish_simple_meta_Ok() throws Exception { @Test public void publish_simple_meta_geocat_Ok() throws Exception { // Prepare - Path target = folder.newFolder("publish_simple_meta_geocat_Ok").toPath(); - Path geocatTarget = folder.newFolder("publish_simple_meta_geocat_Ok_geocat").toPath(); + Path target = TestUtil.createTempDir(folder, "publish_simple_meta_geocat_Ok"); + Path geocatTarget = TestUtil.createTempDir(folder, "publish_simple_meta_geocat_Ok_geocat"); String themePublication = "ch.so.afu.abbaustellen"; // Run step @@ -100,7 +100,7 @@ public void publish_simple_meta_geocat_Ok() throws Exception { @Test public void publish_regions_meta_Ok() throws Exception { // Prepare - Path target = folder.newFolder("publish_regions_meta_Ok").toPath(); + Path target = TestUtil.createTempDir(folder, "publish_regions_meta_Ok"); String themePublication = "ch.so.agi.av.dm01_so"; List regions = new ArrayList() {{ add("2463"); @@ -143,8 +143,8 @@ public void publish_regions_meta_Ok() throws Exception { @Test public void publish_regions_meta_geocat_Ok() throws Exception { // Prepare - Path target = folder.newFolder("publish_regions_meta_Ok").toPath(); - Path geocatTarget = folder.newFolder("publish_regions_meta_Ok_geocat").toPath(); + Path target = TestUtil.createTempDir(folder, "publish_regions_meta_Ok"); + Path geocatTarget = TestUtil.createTempDir(folder, "publish_regions_meta_Ok_geocat"); String themePublication = "ch.so.agi.av.dm01_so"; List regions = new ArrayList() {{ add("2463"); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/OgdMetaPublisherStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/OgdMetaPublisherStepTest.java index 281d7b7a..87d809a0 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/OgdMetaPublisherStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/OgdMetaPublisherStepTest.java @@ -3,21 +3,20 @@ import ch.ehi.basics.settings.Settings; import ch.so.agi.gretl.testutil.TestUtil; import org.interlis2.validator.Validator; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class OgdMetaPublisherStepTest { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; // TODO // Test mit Subdatasets @@ -26,22 +25,20 @@ public class OgdMetaPublisherStepTest { public void single_resource_no_identifier_Ok() throws Exception { // Prepare File configFile = TestUtil.getResourceFile(TestUtil.KANTONALE_GEBAEUDE_TOML_PATH); - Path outputPath = folder.newFolder().toPath(); // Run OgdMetaPublisherStep ogdMetaPublisherStep = new OgdMetaPublisherStep(); - ogdMetaPublisherStep.execute(configFile.toPath(), outputPath); + ogdMetaPublisherStep.execute(configFile.toPath(), folder); // Validate Settings settings = new Settings(); settings.setValue(Validator.SETTING_ILIDIRS, Validator.SETTING_DEFAULT_ILIDIRS + ";src/main/resources/ogdmetapublisher/ili/"); - Path xtfFile = Paths.get(outputPath.toFile().getAbsolutePath(), "meta-ch.so.hba.kantonale_gebaeude.xtf"); + Path xtfFile = Paths.get(folder.toAbsolutePath().toString(), "meta-ch.so.hba.kantonale_gebaeude.xtf"); boolean valid = Validator.runValidation(xtfFile.toString(), settings); assertTrue(valid); String content = new String(Files.readAllBytes(xtfFile)); assertTrue(content.contains("Anzahl kantonale (nicht-öffentliche) Ladestationen")); } - } diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/PostgisRasterExportStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/PostgisRasterExportStepTest.java index dc9abc14..e3647736 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/PostgisRasterExportStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/PostgisRasterExportStepTest.java @@ -2,21 +2,27 @@ import ch.so.agi.gretl.api.Connector; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.*; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.io.File; +import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +@Testcontainers public class PostgisRasterExportStepTest { - @ClassRule - public static PostgreSQLContainer postgres = + @Container + public PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgisContainerProvider().newInstance() .withDatabaseName(TestUtil.PG_DB_NAME) .withUsername(TestUtil.PG_DDLUSR_USR) @@ -25,15 +31,15 @@ public class PostgisRasterExportStepTest { private Connector connector; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; - @Before + @BeforeEach public void before() { this.connector = new Connector(postgres.getJdbcUrl(), TestUtil.PG_READERUSR_USR, TestUtil.PG_READERUSR_PWD); } - @After + @AfterEach public void after() throws Exception { if (!this.connector.isClosed()) { this.connector.close(); @@ -46,8 +52,8 @@ public void export_geotiff_Ok() throws Exception { File sqlFile = TestUtil.getResourceFile(TestUtil.RASTER_GEOTIFF_SQL_PATH); String outFileName = "outfile.tif"; File targetFile = TestUtil.getResourceFile(TestUtil.TARGET_TIF_PATH); - File outDirectory = folder.newFolder("build"); - File outFile = Paths.get(outDirectory.getAbsolutePath(), outFileName).toFile(); + Path outDirectory = TestUtil.createTempDir(folder, "build"); + File outFile = Paths.get(outDirectory.toAbsolutePath().toString(), outFileName).toFile(); // Run: Calculate and export raster file from PostGIS PostgisRasterExportStep postgisRasterExportStep = new PostgisRasterExportStep(); @@ -68,9 +74,8 @@ public void export_aaigrid_Ok() throws Exception { // TODO this file is missing in the resources, what should be actually tested here? File targetFile = new File("src/test/resources/data/postgisrasterprocessor/target.asc"); - File outDirectory = folder.newFolder("build"); - //File outDirectory = Paths.get("/Users/stefan/tmp/").toFile(); - File outFile = Paths.get(outDirectory.getAbsolutePath(), outFileName).toFile(); + Path outDirectory = TestUtil.createTempDir(folder, "build"); + File outFile = Paths.get(outDirectory.toAbsolutePath().toString(), outFileName).toFile(); // Run: Calculate and export raster file from PostGIS PostgisRasterExportStep postgisRasterExportStep = new PostgisRasterExportStep(); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/PublisherStepDb2LocalTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/PublisherStepDb2LocalTest.java index 0892fcaf..8056f610 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/PublisherStepDb2LocalTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/PublisherStepDb2LocalTest.java @@ -5,14 +5,15 @@ import ch.ehi.ili2db.base.Ili2dbException; import ch.ehi.ili2db.gui.Config; import ch.ehi.ili2pg.PgMain; -import ch.so.agi.gretl.testutil.DbTest; +import ch.so.agi.gretl.testutil.TestTags; import ch.so.agi.gretl.testutil.TestUtil; import org.interlis2.validator.Validator; -import org.junit.*; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.*; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.io.IOException; import java.nio.file.Files; @@ -26,13 +27,14 @@ import static ch.ehi.ili2db.gui.Config.BASKET_HANDLING_READWRITE; import static ch.so.agi.gretl.steps.AbstractPublisherStepTest.*; +import static org.junit.jupiter.api.Assertions.*; +@Testcontainers public class PublisherStepDb2LocalTest { - private static final String DM01AVCH24LV95D = "DM01AVCH24LV95D"; private static final Path localTestOut = Paths.get("build").resolve("out"); - @ClassRule + @Container public static PostgreSQLContainer postgres = System.getProperty("dbUrl") == null ? (PostgreSQLContainer) new PostgisContainerProvider().newInstance() .withDatabaseName(TestUtil.PG_DB_NAME) @@ -42,20 +44,21 @@ public class PublisherStepDb2LocalTest { .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)) : null; - private final String dbUrl; - private final String dbUser; - private final String dbPassword; - private final String dbSchema; + private static String dbUrl; + private static String dbUser; + private static String dbPassword; + private static String dbSchema; private Config config; - public PublisherStepDb2LocalTest() { - this.dbUrl = System.getProperty("dbUrl", postgres != null ? postgres.getJdbcUrl() : null); - this.dbUser = System.getProperty("dbusr", TestUtil.PG_DDLUSR_USR); - this.dbPassword = System.getProperty("dbPassword", TestUtil.PG_DDLUSR_PWD); - this.dbSchema = "publisher"; + @BeforeAll + public static void beforeAll() { + dbUrl = System.getProperty("dbUrl", postgres != null ? postgres.getJdbcUrl() : null); + dbUser = System.getProperty("dbusr", TestUtil.PG_DDLUSR_USR); + dbPassword = System.getProperty("dbPassword", TestUtil.PG_DDLUSR_PWD); + dbSchema = "publisher"; } - @Before + @BeforeEach public void before() { this.config = new Config(); config.setModeldir(Ili2db.ILI_FROM_DB+ch.interlis.ili2c.Main.ILIDIR_SEPARATOR + AbstractPublisherStepTest.ILI_DIRS); @@ -77,13 +80,13 @@ public void before() { config.setDefaultSrsCode("2056"); } - @After + @AfterEach public void after() { this.config = null; } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_allNew() throws Exception { Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); String datasetName = "av"; @@ -100,23 +103,23 @@ public void db_allNew() throws Exception { // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_allNew_modelsToPublish() throws Exception { Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); @@ -132,23 +135,23 @@ public void db_allNew_modelsToPublish() throws Exception { // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_allNew_modelsToPublish_NotSimple_Fail() throws Exception { Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); @@ -162,15 +165,15 @@ public void db_allNew_modelsToPublish_NotSimple_Fail() throws Exception { try { publishDataset(jdbcConnection, SRC_DATA_DATE_0, null, DM01AVCH24LV95D, false, null, null, null); - Assert.fail(); + fail("Expected IllegalArgumentException to be thrown"); } catch (IllegalArgumentException ex) { - Assert.assertEquals("modelsToPublish can only be used with simple models", ex.getMessage()); + assertEquals("modelsToPublish can only be used with simple models", ex.getMessage()); } } } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_UserFormats_allNew() throws Exception { final String datasetName = "simple"; Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); @@ -187,7 +190,7 @@ public void db_UserFormats_allNew() throws Exception { } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_UserFormats_firstHistory() throws Exception { { db_UserFormats_allNew(); @@ -203,45 +206,45 @@ public void db_UserFormats_firstHistory() throws Exception { // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertTrue(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".xtf.zip"))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".shp.zip"))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".dxf.zip"))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".gpkg.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertTrue(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".xtf.zip"))); + assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".shp.zip"))); + assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".dxf.zip"))); + assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".gpkg.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_SIMPLE_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_1), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_SIMPLE_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_1), PublisherStep.readPublishDate(targetFolderAktuell)); } // verify history { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderHistoryRoot = targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY); final Path targetFolderHistory = targetFolderHistoryRoot.resolve(PublisherStep.getDateTag(SRC_DATA_DATE_0)); - Assert.assertTrue(Files.exists(targetFolderHistory)); - Assert.assertTrue(Files.exists(targetFolderHistory.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".xtf.zip"))); - Assert.assertFalse(Files.exists(targetFolderHistory.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".shp.zip"))); - Assert.assertFalse(Files.exists(targetFolderHistory.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".dxf.zip"))); - Assert.assertFalse(Files.exists(targetFolderHistory.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".gpkg.zip"))); + assertTrue(Files.exists(targetFolderHistory)); + assertTrue(Files.exists(targetFolderHistory.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".xtf.zip"))); + assertFalse(Files.exists(targetFolderHistory.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".shp.zip"))); + assertFalse(Files.exists(targetFolderHistory.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".dxf.zip"))); + assertFalse(Files.exists(targetFolderHistory.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".gpkg.zip"))); final Path targetFolderAktuellMeta = targetFolderHistory.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_SIMPLE_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderHistory)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_SIMPLE_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderHistory)); } } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_UserFormats_ModelDir_AV() throws Exception { Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); String datasetName="av"; @@ -258,23 +261,23 @@ public void db_UserFormats_ModelDir_AV() throws Exception { // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_UserFormats_NoModelDir_AV() throws Exception { Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); String datasetName = "av"; @@ -291,23 +294,23 @@ public void db_UserFormats_NoModelDir_AV() throws Exception { // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertTrue(Files.exists(targetFolderAktuell.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_regionsRegEx() throws Exception { Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); List publishedRegions = new ArrayList<>(); @@ -327,26 +330,26 @@ public void db_regionsRegEx() throws Exception { } // verify - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertEquals(2,publishedRegions.size()); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertEquals(2,publishedRegions.size()); for (String controlRegion:new String[] {"2501","2502"}) { - Assert.assertTrue(publishedRegions.contains(controlRegion)); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); + assertTrue(publishedRegions.contains(controlRegion)); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); } final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_regionsList() throws Exception { Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); List publishedRegions = new ArrayList<>(); @@ -366,27 +369,27 @@ public void db_regionsList() throws Exception { publishDataset(jdbcConnection, SRC_DATA_DATE_0, null, null, false, null, regions, publishedRegions); } - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertEquals(1,publishedRegions.size()); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertEquals(1,publishedRegions.size()); for (String controlRegion : new String[] {"2501"}) { - Assert.assertTrue(publishedRegions.contains(controlRegion)); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); + assertTrue(publishedRegions.contains(controlRegion)); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); } final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_regionsRegEx_UserFormats() throws Exception { Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); List publishedRegions=new ArrayList<>(); @@ -407,30 +410,30 @@ public void db_regionsRegEx_UserFormats() throws Exception { // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertEquals(2,publishedRegions.size()); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertEquals(2,publishedRegions.size()); for (String controlRegion : new String[] {"SimpleCoord23a","SimpleCoord23b"}) { - Assert.assertTrue(publishedRegions.contains(controlRegion)); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".xtf.zip"))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".gpkg.zip"))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".shp.zip"))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".dxf.zip"))); + assertTrue(publishedRegions.contains(controlRegion)); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".xtf.zip"))); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".gpkg.zip"))); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".shp.zip"))); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".dxf.zip"))); } final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_SIMPLE_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_SIMPLE_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } } @Test - @Category(DbTest.class) + @Tag(TestTags.DB_TEST) public void db_regionsRegEx_UserFormats_AV() throws Exception { Path targetFolder = localTestOut.resolve(AbstractPublisherStepTest.SRC_DATA_IDENT); List publishedRegions = new ArrayList<>(); @@ -454,23 +457,23 @@ public void db_regionsRegEx_UserFormats_AV() throws Exception { // verify { - Assert.assertTrue(Files.exists(targetFolder)); + assertTrue(Files.exists(targetFolder)); final Path targetFolderAktuell = targetFolder.resolve(PublisherStep.PATH_ELE_AKTUELL); - Assert.assertTrue(Files.exists(targetFolderAktuell)); - Assert.assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); - Assert.assertEquals(2,publishedRegions.size()); + assertTrue(Files.exists(targetFolderAktuell)); + assertFalse(Files.exists(targetFolder.resolve(PublisherStep.PATH_ELE_HISTORY))); + assertEquals(2,publishedRegions.size()); for(String controlRegion:new String[] {"2501","2502"}) { - Assert.assertTrue(publishedRegions.contains(controlRegion)); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); - Assert.assertFalse(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".gpkg.zip"))); - Assert.assertFalse(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".shp.zip"))); - Assert.assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".dxf.zip"))); + assertTrue(publishedRegions.contains(controlRegion)); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".itf.zip"))); + assertFalse(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".gpkg.zip"))); + assertFalse(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".shp.zip"))); + assertTrue(Files.exists(targetFolderAktuell.resolve(controlRegion+"."+AbstractPublisherStepTest.SRC_DATA_IDENT+".dxf.zip"))); } final Path targetFolderAktuellMeta = targetFolderAktuell.resolve(PublisherStep.PATH_ELE_META); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta)); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); - Assert.assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); - Assert.assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); + assertTrue(Files.exists(targetFolderAktuellMeta)); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(AbstractPublisherStepTest.SRC_ILI_AV_FILENAME))); + assertTrue(Files.exists(targetFolderAktuellMeta.resolve(PublisherStep.PATH_ELE_PUBLISHDATE_JSON))); + assertEquals(PublisherStep.getDateTag(SRC_DATA_DATE_0), PublisherStep.readPublishDate(targetFolderAktuell)); } } diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/PublisherStepFile2RemoteTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/PublisherStepFile2RemoteTest.java index 4fff405f..7223eca1 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/PublisherStepFile2RemoteTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/PublisherStepFile2RemoteTest.java @@ -1,9 +1,9 @@ package ch.so.agi.gretl.steps; -import ch.so.agi.gretl.testutil.SftpTest; +import ch.so.agi.gretl.testutil.TestTags; import com.github.robtimus.filesystems.sftp.SFTPEnvironment; -import org.junit.BeforeClass; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import java.io.File; import java.io.IOException; @@ -13,7 +13,7 @@ import java.nio.file.FileSystems; import java.nio.file.Path; -@Category(SftpTest.class) +@Tag(TestTags.SFTP_TEST) public class PublisherStepFile2RemoteTest extends AbstractPublisherStepTest { private static final String FTP_URL = System.getProperty("ftpurl"); private static final String FTP_USER = System.getProperty("ftpusr"); @@ -23,7 +23,7 @@ public class PublisherStepFile2RemoteTest extends AbstractPublisherStepTest { private static FileSystem fileSystem = null; private static String path; - @BeforeClass + @BeforeAll public static void initFileSystem() { if (fileSystem != null) { return; @@ -45,6 +45,11 @@ public static void initFileSystem() { } } + @Override + protected Path getTargetPath() { + return fileSystem.getPath(path); + } + private static URI createHostURI(URI rawUri) throws URISyntaxException { String scheme = rawUri.getScheme(); String host = rawUri.getHost(); @@ -56,9 +61,4 @@ private static URI createHostURI(URI rawUri) throws URISyntaxException { return new URI(String.format("%s://%s:%d", scheme, host, port)); } } - - @Override - protected Path getTargetPath() { - return fileSystem.getPath(path); - } -} +} \ No newline at end of file diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/S3Bucket2BucketStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/S3Bucket2BucketStepTest.java index f00a1a7c..81b498c6 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/S3Bucket2BucketStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/S3Bucket2BucketStepTest.java @@ -1,12 +1,11 @@ package ch.so.agi.gretl.steps; -import ch.so.agi.gretl.testutil.S3Test; import ch.so.agi.gretl.testutil.S3TestHelper; +import ch.so.agi.gretl.testutil.TestTags; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; import software.amazon.awssdk.services.s3.model.ListObjectsRequest; @@ -16,10 +15,11 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; +import java.nio.file.Path; import java.util.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class S3Bucket2BucketStepTest { private final String s3AccessKey; @@ -31,8 +31,8 @@ public class S3Bucket2BucketStepTest { private final String acl; private final S3TestHelper s3TestHelper; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; public S3Bucket2BucketStepTest() { this.s3AccessKey = System.getProperty("s3AccessKey"); @@ -46,7 +46,7 @@ public S3Bucket2BucketStepTest() { } @Test - @Category(S3Test.class) + @Tag(TestTags.S3_TEST) public void copyFiles_Ok() throws Exception { File sourceObject = TestUtil.getResourceFile(TestUtil.S3_BUCKET_DIR_PATH); Map metadata = new HashMap<>(); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/S3DownloadStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/S3DownloadStepTest.java index c5a9fd8c..3925d1d1 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/S3DownloadStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/S3DownloadStepTest.java @@ -2,27 +2,26 @@ import ch.so.agi.gretl.logging.GretlLogger; import ch.so.agi.gretl.logging.LogEnvironment; -import ch.so.agi.gretl.testutil.S3Test; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TemporaryFolder; +import ch.so.agi.gretl.testutil.TestTags; +import ch.so.agi.gretl.testutil.TestUtil; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; -import java.io.File; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class S3DownloadStepTest { - private final String s3AccessKey; private final String s3SecretKey; private final String s3BucketName; private final GretlLogger log; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; public S3DownloadStepTest() { this.log = LogEnvironment.getLogger(this.getClass()); @@ -32,19 +31,19 @@ public S3DownloadStepTest() { } @Test - @Category(S3Test.class) + @Tag(TestTags.S3_TEST) public void downloadFile_Ok() throws Exception { String s3EndPoint = "https://s3.eu-central-1.amazonaws.com"; String s3Region = "eu-central-1"; String key = "download.txt"; - File downloadDir = folder.newFolder("downloadFile_Ok"); + Path downloadDir = TestUtil.createTempDir(folder, "downloadFile_Ok"); // Download a single file. S3DownloadStep s3DownloadStep = new S3DownloadStep(); - s3DownloadStep.execute(s3AccessKey, s3SecretKey, s3BucketName, key, s3EndPoint, s3Region, downloadDir); + s3DownloadStep.execute(s3AccessKey, s3SecretKey, s3BucketName, key, s3EndPoint, s3Region, downloadDir.toFile()); // Check result. - String content = new String(Files.readAllBytes(Paths.get(downloadDir.getAbsolutePath(), key))); + String content = new String(Files.readAllBytes(Paths.get(downloadDir.toAbsolutePath().toString(), key))); log.debug(content); assertEquals("fubar", content.substring(0, 5)); } diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/S3UploadStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/S3UploadStepTest.java index 521a0bbe..892eda28 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/S3UploadStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/S3UploadStepTest.java @@ -1,12 +1,11 @@ package ch.so.agi.gretl.steps; -import ch.so.agi.gretl.testutil.S3Test; import ch.so.agi.gretl.testutil.S3TestHelper; +import ch.so.agi.gretl.testutil.TestTags; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import software.amazon.awssdk.core.ResponseInputStream; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.model.*; @@ -14,15 +13,15 @@ import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class S3UploadStepTest { - private final String s3AccessKey; private final String s3SecretKey; private final String s3BucketName; @@ -31,8 +30,8 @@ public class S3UploadStepTest { private final String acl; private final S3TestHelper s3TestHelper; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; public S3UploadStepTest() { this.s3AccessKey = System.getProperty("s3AccessKey"); @@ -45,7 +44,7 @@ public S3UploadStepTest() { } @Test - @Category(S3Test.class) + @Tag(TestTags.S3_TEST) public void uploadDirectory_Ok() throws Exception { File sourceObject = TestUtil.getResourceFile("data/s3upload/"); Map metaData = new HashMap() {{ @@ -83,7 +82,7 @@ public void uploadDirectory_Ok() throws Exception { } @Test - @Category(S3Test.class) + @Tag(TestTags.S3_TEST) public void uploadFile_Ok() throws Exception { File sourceObject = TestUtil.getResourceFile("data/s3upload/foo.txt"); Map metaData = new HashMap<>(); @@ -109,7 +108,7 @@ public void uploadFile_Ok() throws Exception { } @Test - @Category(S3Test.class) + @Tag(TestTags.S3_TEST) public void uploadFile_Fail() throws Exception { File sourceObject = TestUtil.getResourceFile("data/s3upload/foo.txt"); Map metaData = new HashMap<>(); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/SqlExecutorStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/SqlExecutorStepTest.java index 53af265f..a08fb7c9 100755 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/SqlExecutorStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/SqlExecutorStepTest.java @@ -2,42 +2,49 @@ import ch.so.agi.gretl.api.Connector; import ch.so.agi.gretl.logging.LogEnvironment; -import ch.so.agi.gretl.testutil.DbTest; +import ch.so.agi.gretl.testutil.TestTags; import ch.so.agi.gretl.testutil.TestUtil; import ch.so.agi.gretl.util.EmptyFileException; import ch.so.agi.gretl.util.FileStylingDefinition; import ch.so.agi.gretl.util.GretlException; -import org.junit.*; -import org.junit.experimental.categories.Category; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.testcontainers.containers.PostgisContainerProvider; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.io.File; +import java.nio.file.Path; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; + /** * Tests for the SqlExecutorStep */ +@Testcontainers public class SqlExecutorStepTest { - @ClassRule - public static PostgreSQLContainer postgres = + @Container + public PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgisContainerProvider().newInstance() .withDatabaseName(TestUtil.PG_DB_NAME) .withUsername(TestUtil.PG_DDLUSR_USR) .withInitScript(TestUtil.PG_INIT_SCRIPT_PATH) .waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)); - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; private final Connector connector; private final Connector duckDbConnector; @@ -47,12 +54,12 @@ public SqlExecutorStepTest() { duckDbConnector = new Connector("jdbc:duckdb::memory:", null, null); } - @Before + @BeforeEach public void before() throws Exception { TestUtil.createTestDb(this.connector, TestUtil.CREATE_TEST_DB_SQL_PATH); } - @After + @AfterEach public void after() throws Exception { TestUtil.clearTestDb(connector); if (!connector.isClosed()) { @@ -123,9 +130,9 @@ public void executeWithInexistentFilePath_ThrowsGretlException() throws Exceptio step.execute(connector, sqlList); } catch (GretlException e) { assertEquals( - String.format("GretlException must be of type: %s", GretlException.TYPE_FILE_NOT_READABLE), + GretlException.TYPE_FILE_NOT_READABLE, e.getType(), - GretlException.TYPE_FILE_NOT_READABLE + String.format("GretlException must be of type: %s", GretlException.TYPE_FILE_NOT_READABLE) ); } } @@ -185,8 +192,8 @@ public void executeDuckDB_Fail() throws Exception { } } - @Category(DbTest.class) @Test + @Tag(TestTags.DB_TEST) public void executePostgisVersionTest() throws Exception { File inputFile = TestUtil.getResourceFile(TestUtil.POSTGIS_VERSION_SQL_PATH); FileStylingDefinition.checkForUtf8(inputFile); diff --git a/gretl/src/test/java/ch/so/agi/gretl/steps/XslTransformerStepTest.java b/gretl/src/test/java/ch/so/agi/gretl/steps/XslTransformerStepTest.java index 7678d175..9cb34625 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/steps/XslTransformerStepTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/steps/XslTransformerStepTest.java @@ -1,32 +1,33 @@ package ch.so.agi.gretl.steps; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class XslTransformerStepTest { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; @Test public void transformFile_Resource_Ok() throws Exception { - File outDirectory = folder.newFolder("transformFile_Ok"); + Path outDirectory = TestUtil.createTempDir(folder, "transformFile_Ok"); File sourceFile = TestUtil.getResourceFile("data/xsltransformer/MeldungAnGeometer_G-0098981_20230214_104054_Koordinaten.xml"); // Transform File XslTransformerStep xslTransformerStep = new XslTransformerStep(); - xslTransformerStep.execute("eCH0132_to_SO_AGI_SGV_Meldungen_20221109.xsl", sourceFile, outDirectory); + xslTransformerStep.execute("eCH0132_to_SO_AGI_SGV_Meldungen_20221109.xsl", sourceFile, outDirectory.toFile()); // Check result - byte[] bytes = Files.readAllBytes(Paths.get(outDirectory.getAbsolutePath(), "MeldungAnGeometer_G-0098981_20230214_104054_Koordinaten.xtf")); + byte[] bytes = Files.readAllBytes(Paths.get(outDirectory.toAbsolutePath().toString(), "MeldungAnGeometer_G-0098981_20230214_104054_Koordinaten.xtf")); String fileContent = new String (bytes); assertTrue(fileContent.contains("")); @@ -36,15 +37,15 @@ public void transformFile_Resource_Ok() throws Exception { @Test public void transformFile_File_Ok() throws Exception { File xslFile = new File("src/main/resources/xslt/eCH0132_to_SO_AGI_SGV_Meldungen_20221109.xsl"); - File outDirectory = folder.newFolder("transformFile_Ok"); + Path outDirectory = TestUtil.createTempDir(folder, "transformFile_Ok"); File sourceFile = TestUtil.getResourceFile("data/xsltransformer/MeldungAnGeometer_G-0098981_20230214_104054_Koordinaten.xml"); // Transform File XslTransformerStep xslTransformerStep = new XslTransformerStep(); - xslTransformerStep.execute(xslFile, sourceFile, outDirectory); + xslTransformerStep.execute(xslFile, sourceFile, outDirectory.toFile()); // Check result - byte[] bytes = Files.readAllBytes(Paths.get(outDirectory.getAbsolutePath(), "MeldungAnGeometer_G-0098981_20230214_104054_Koordinaten.xtf")); + byte[] bytes = Files.readAllBytes(Paths.get(outDirectory.toAbsolutePath().toString(), "MeldungAnGeometer_G-0098981_20230214_104054_Koordinaten.xtf")); String fileContent = new String (bytes); assertTrue(fileContent.contains("")); diff --git a/gretl/src/test/java/ch/so/agi/gretl/testutil/DbTest.java b/gretl/src/test/java/ch/so/agi/gretl/testutil/DbTest.java deleted file mode 100755 index 8f23a19e..00000000 --- a/gretl/src/test/java/ch/so/agi/gretl/testutil/DbTest.java +++ /dev/null @@ -1,6 +0,0 @@ -package ch.so.agi.gretl.testutil; - -/** - * Marker for all Componenttests that depend on a PostGIS server. - */ -public interface DbTest {} diff --git a/gretl/src/test/java/ch/so/agi/gretl/testutil/FileListTest.java b/gretl/src/test/java/ch/so/agi/gretl/testutil/FileListTest.java index f7edf5c9..898adbd2 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/testutil/FileListTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/testutil/FileListTest.java @@ -3,19 +3,21 @@ import java.nio.file.Paths; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ch.so.agi.gretl.steps.AbstractPublisherStepTest; import ch.so.agi.gretl.steps.PublisherStep; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class FileListTest { @Test public void filesTest() throws Exception { List regions=PublisherStep.listRegions(Paths.get(AbstractPublisherStepTest.SRC_TEST_DATA_FILES), "[0-9][0-9][0-9][0-9]", "itf"); - Assert.assertEquals(2, regions.size()); - Assert.assertTrue(regions.contains("2501")); - Assert.assertTrue(regions.contains("2502")); + assertEquals(2, regions.size()); + assertTrue(regions.contains("2501")); + assertTrue(regions.contains("2502")); } } diff --git a/gretl/src/test/java/ch/so/agi/gretl/testutil/S3Test.java b/gretl/src/test/java/ch/so/agi/gretl/testutil/S3Test.java deleted file mode 100644 index 90ee6a4b..00000000 --- a/gretl/src/test/java/ch/so/agi/gretl/testutil/S3Test.java +++ /dev/null @@ -1,5 +0,0 @@ -package ch.so.agi.gretl.testutil; - -public interface S3Test { - -} diff --git a/gretl/src/test/java/ch/so/agi/gretl/testutil/S3TestHelper.java b/gretl/src/test/java/ch/so/agi/gretl/testutil/S3TestHelper.java index 2bca8155..34a364b1 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/testutil/S3TestHelper.java +++ b/gretl/src/test/java/ch/so/agi/gretl/testutil/S3TestHelper.java @@ -15,7 +15,6 @@ import java.util.Objects; public class S3TestHelper { - private final String s3AccessKey; private final String s3SecretKey; private final String s3Region; diff --git a/gretl/src/test/java/ch/so/agi/gretl/testutil/SftpTest.java b/gretl/src/test/java/ch/so/agi/gretl/testutil/SftpTest.java deleted file mode 100644 index 11caca95..00000000 --- a/gretl/src/test/java/ch/so/agi/gretl/testutil/SftpTest.java +++ /dev/null @@ -1,6 +0,0 @@ -package ch.so.agi.gretl.testutil; - -/** - * Marker for all Componenttests that depend on a SFTP server. - */ -public interface SftpTest {} diff --git a/gretl/src/test/java/ch/so/agi/gretl/testutil/SftpUriTest.java b/gretl/src/test/java/ch/so/agi/gretl/testutil/SftpUriTest.java index c77e0eaa..0e0f2aac 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/testutil/SftpUriTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/testutil/SftpUriTest.java @@ -2,29 +2,30 @@ import java.net.URI; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class SftpUriTest { @Test public void parserTest() throws Exception { URI uri = new URI( "sftp://ftp.umleditor.org/publisher" ); String path=uri.getRawPath(); - Assert.assertEquals("/publisher",path); + assertEquals("/publisher",path); URI base= new URI(uri.getScheme()+"://"+uri.getHost()); - Assert.assertEquals("sftp://ftp.umleditor.org", base.toString()); + assertEquals("sftp://ftp.umleditor.org", base.toString()); } @Test public void relativeFileTest() throws Exception{ URI uri = new URI( "publisher" ); - Assert.assertEquals(null, uri.getScheme()); - Assert.assertEquals("publisher", uri.getRawPath()); + assertEquals(null, uri.getScheme()); + assertEquals("publisher", uri.getRawPath()); } @Test public void absoluteFileTest() throws Exception{ URI uri = new URI( "/publisher" ); - Assert.assertEquals(null, uri.getScheme()); - Assert.assertEquals("/publisher", uri.getRawPath()); + assertEquals(null, uri.getScheme()); + assertEquals("/publisher", uri.getRawPath()); } } diff --git a/gretl/src/test/java/ch/so/agi/gretl/testutil/TestTags.java b/gretl/src/test/java/ch/so/agi/gretl/testutil/TestTags.java new file mode 100644 index 00000000..e9daf11b --- /dev/null +++ b/gretl/src/test/java/ch/so/agi/gretl/testutil/TestTags.java @@ -0,0 +1,9 @@ +package ch.so.agi.gretl.testutil; + +public interface TestTags { + String DB_TEST = "dbTest"; + String S3_TEST = "s3Test"; + String SFTP_TEST = "sftpTest"; + String DB_DRIVERS_REACHABLE_TEST = "dbDriversReachableTest"; + String QGIS_REACHABLE_TEST = "qgisReachableTest"; +} diff --git a/gretl/src/test/java/ch/so/agi/gretl/testutil/TestUtil.java b/gretl/src/test/java/ch/so/agi/gretl/testutil/TestUtil.java index b02437ce..6007da1b 100755 --- a/gretl/src/test/java/ch/so/agi/gretl/testutil/TestUtil.java +++ b/gretl/src/test/java/ch/so/agi/gretl/testutil/TestUtil.java @@ -3,13 +3,13 @@ import ch.so.agi.gretl.api.Connector; import ch.so.agi.gretl.steps.SqlExecutorStep; import ch.so.agi.gretl.util.FileStylingDefinition; -import org.junit.rules.TemporaryFolder; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.net.URL; +import java.nio.file.Path; import java.sql.Connection; import java.util.Collections; import java.util.Objects; @@ -48,8 +48,8 @@ public class TestUtil { public static final String TARGET_ASC_PATH = "data/postgisrasterprocessor/target.asc"; public static final String S3_BUCKET_DIR_PATH = "data/s3bucket2bucket"; - public static File createTempFile(TemporaryFolder folder, String content, String fileName) throws IOException { - File sqlFile = folder.newFile(fileName); + public static File createTempFile(Path directoryPath, String content, String fileName) throws IOException { + File sqlFile = new File(directoryPath.toString(), fileName); try (BufferedWriter bw = new BufferedWriter(new FileWriter(sqlFile))) { bw.write(content); @@ -57,6 +57,20 @@ public static File createTempFile(TemporaryFolder folder, String content, String } } + public static Path createTempDir(Path parentDirPath, String dirname) throws IOException { + File directory = new File(parentDirPath.toString(), dirname); + + if (directory.exists()) { + return directory.toPath(); + } + + if (!directory.mkdirs()) { + throw new IOException("Could not create directory: " + parentDirPath + File.separator + dirname); + } + + return directory.toPath(); + } + /** * Retrieves a file from the resources directory. * diff --git a/gretl/src/test/java/ch/so/agi/gretl/util/DbConnectorTest.java b/gretl/src/test/java/ch/so/agi/gretl/util/DbConnectorTest.java index ed763db9..f2a95a86 100755 --- a/gretl/src/test/java/ch/so/agi/gretl/util/DbConnectorTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/util/DbConnectorTest.java @@ -3,7 +3,7 @@ import ch.so.agi.gretl.logging.GretlLogger; import ch.so.agi.gretl.logging.LogEnvironment; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.sql.Connection; diff --git a/gretl/src/test/java/ch/so/agi/gretl/util/FileStylingDefinitionTest.java b/gretl/src/test/java/ch/so/agi/gretl/util/FileStylingDefinitionTest.java index f73d8eaf..afe57bd5 100755 --- a/gretl/src/test/java/ch/so/agi/gretl/util/FileStylingDefinitionTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/util/FileStylingDefinitionTest.java @@ -1,17 +1,20 @@ package ch.so.agi.gretl.util; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import ch.so.agi.gretl.testutil.TestUtil; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; +import java.nio.file.Path; -public class FileStylingDefinitionTest { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; - @Test +public class FileStylingDefinitionTest { + @TempDir + public Path folder; + + @Test public void checkEncoding_Ok() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); File inputfile = new File(classLoader.getResource("awjf_biotopbaeume_pub_biotopbaeume_biotopbaum_ok.sql").getFile()); @@ -20,9 +23,9 @@ public void checkEncoding_Ok() throws Exception { // Empty files are handled elsewhere. But empty files will // let the encoding validation stall. - @Test + @Test public void checkEncoding_Ok_empty_File() throws Exception { - File inputfile = folder.newFile("query.sql"); + File inputfile = TestUtil.createTempFile(folder, "", "query.sql"); FileStylingDefinition.checkForUtf8(inputfile); } @@ -42,8 +45,8 @@ public void checkEncoding_Fail() throws Exception { File inputfile = new File(classLoader.getResource("test.txt").getFile()); try { FileStylingDefinition.checkForUtf8(inputfile); - Assert.fail(); - } catch (Exception e) {} + fail(); + } catch (Exception ignored) {} } @Test @@ -53,7 +56,7 @@ public void fileWithBOMThrowsException() throws Exception { try { FileStylingDefinition.checkForBOMInFile(inputfile); } catch (GretlException e) { - Assert.assertEquals("file with unallowed BOM", e.getType()); + assertEquals("file with unallowed BOM", e.getType()); } } diff --git a/gretl/src/test/java/ch/so/agi/gretl/util/GroomingTest.java b/gretl/src/test/java/ch/so/agi/gretl/util/GroomingTest.java index a5353aa6..749a3382 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/util/GroomingTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/util/GroomingTest.java @@ -7,28 +7,29 @@ import java.util.Calendar; import java.util.Date; import java.util.List; -import java.util.Locale; -import java.util.TimeZone; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ch.so.agi.gretl.logging.GretlLogger; import ch.so.agi.gretl.logging.LogEnvironment; import ch.so.agi.gretl.steps.AbstractPublisherStepTest; import ch.so.agi.gretl.steps.PublisherStep; -import ch.so.agi.gretl.util.Grooming; -public class GroomingTest { +import static org.gradle.internal.impldep.org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; +public class GroomingTest { final public static String SRC_TEST_DATA = AbstractPublisherStepTest.SRC_TEST_DATA; protected GretlLogger log; - private java.text.DateFormat dateParser=Grooming.getDateFormat(); + private java.text.DateFormat dateParser = Grooming.getDateFormat(); + public GroomingTest() { LogEnvironment.initStandalone(); this.log = LogEnvironment.getLogger(this.getClass()); } + @Test public void weeks() throws Exception { Date date0=dateParser.parse("2022-10-31"); @@ -37,11 +38,12 @@ public void weeks() throws Exception { printDate(date1); Calendar cal0=Grooming.getCalendar();cal0.setTime(date0); Calendar cal1=Grooming.getCalendar();cal1.setTime(date1); - Assert.assertEquals(9, cal0.get(java.util.Calendar.MONTH)); - Assert.assertEquals(10, cal1.get(java.util.Calendar.MONTH)); - Assert.assertEquals(5, cal0.get(java.util.Calendar.WEEK_OF_MONTH)); - Assert.assertEquals(1, cal1.get(java.util.Calendar.WEEK_OF_MONTH)); + assertEquals(9, cal0.get(java.util.Calendar.MONTH)); + assertEquals(10, cal1.get(java.util.Calendar.MONTH)); + assertEquals(5, cal0.get(java.util.Calendar.WEEK_OF_MONTH)); + assertEquals(1, cal1.get(java.util.Calendar.WEEK_OF_MONTH)); } + protected void printDate(Date date) { java.util.Calendar itemc=Grooming.getCalendar(); itemc.setTimeInMillis(date.getTime()); @@ -51,38 +53,42 @@ protected void printDate(Date date) { long weekOfYear=itemc.get(java.util.Calendar.WEEK_OF_YEAR); System.out.println("date "+date+", year "+year+", month "+month+", weekOfMonth "+weekOfMonth+", weekOfYear "+weekOfYear); } + @Test public void readsimpleFile() throws Exception { Grooming grooming=PublisherStep.readGrooming(Paths.get(SRC_TEST_DATA).resolve("simpleGrooming.json")); - Assert.assertEquals((Integer)0, grooming.getDaily().getFrom()); - Assert.assertEquals((Integer)1, grooming.getDaily().getTo()); - Assert.assertEquals((Integer)1, grooming.getWeekly().getFrom()); - Assert.assertEquals((Integer)4, grooming.getWeekly().getTo()); - Assert.assertEquals((Integer)4, grooming.getMonthly().getFrom()); - Assert.assertEquals((Integer)52, grooming.getMonthly().getTo()); - Assert.assertEquals((Integer)52, grooming.getYearly().getFrom()); - Assert.assertEquals(null, grooming.getYearly().getTo()); + assertEquals((Integer)0, grooming.getDaily().getFrom()); + assertEquals((Integer)1, grooming.getDaily().getTo()); + assertEquals((Integer)1, grooming.getWeekly().getFrom()); + assertEquals((Integer)4, grooming.getWeekly().getTo()); + assertEquals((Integer)4, grooming.getMonthly().getFrom()); + assertEquals((Integer)52, grooming.getMonthly().getTo()); + assertEquals((Integer)52, grooming.getYearly().getFrom()); + assertNull(grooming.getYearly().getTo()); } + @Test public void readMissingFile() throws Exception { try { - Grooming grooming=PublisherStep.readGrooming(Paths.get(SRC_TEST_DATA).resolve("missingGrooming.json")); - Assert.fail("exception expected"); + Grooming grooming = PublisherStep.readGrooming(Paths.get(SRC_TEST_DATA).resolve("missingGrooming.json")); + fail("exception expected"); }catch(IOException ex) { ; // ok log.error("readMissingFile", ex); } } + @Test public void readWrongFile() throws Exception { try { - Grooming grooming=PublisherStep.readGrooming(Paths.get(SRC_TEST_DATA).resolve("wrongGrooming.json")); - Assert.fail("exception expected"); + Grooming grooming = PublisherStep.readGrooming(Paths.get(SRC_TEST_DATA).resolve("wrongGrooming.json")); + fail("exception expected"); }catch(IOException ex) { ; // ok log.error("readWrongFile", ex); } } + @Test public void dailyOpenEnd() throws Exception { Grooming grooming=new Grooming(); @@ -95,8 +101,9 @@ public void dailyOpenEnd() throws Exception { add(allHistory,"2021-04-01",null,today); List deleteDates=new ArrayList(); grooming.getFilesToDelete(today, allHistory, deleteDates); - Assert.assertEquals(0, deleteDates.size()); + assertEquals(0, deleteDates.size()); } + @Test public void dailyOnly() throws Exception { Grooming grooming=new Grooming(); @@ -112,8 +119,9 @@ public void dailyOnly() throws Exception { List deleteDates=new ArrayList(); grooming.getFilesToDelete(today, allHistory, deleteDates); expectedDeleteDates.sort(null); - Assert.assertEquals(expectedDeleteDates, deleteDates); + assertEquals(expectedDeleteDates, deleteDates); } + @Test public void weeklyOpenEnd() throws Exception { Grooming grooming=new Grooming(); @@ -131,8 +139,9 @@ public void weeklyOpenEnd() throws Exception { List deleteDates=new ArrayList(); grooming.getFilesToDelete(today, allHistory, deleteDates); expectedDeleteDates.sort(null); - Assert.assertEquals(expectedDeleteDates, deleteDates); + assertEquals(expectedDeleteDates, deleteDates); } + @Test public void weeklyOnly() throws Exception { Grooming grooming=new Grooming(); @@ -151,8 +160,9 @@ public void weeklyOnly() throws Exception { List deleteDates=new ArrayList(); grooming.getFilesToDelete(today, allHistory, deleteDates); expectedDeleteDates.sort(null); - Assert.assertEquals(expectedDeleteDates, deleteDates); + assertEquals(expectedDeleteDates, deleteDates); } + private Date add(List allHistory, String dateTxt,List expectedDeleteDates,Date today) throws ParseException{ Date date=dateParser.parse(dateTxt); @@ -166,6 +176,7 @@ private Date add(List allHistory, } return date; } + @Test public void weeklyMonthlyOpenEnd() throws Exception { Grooming grooming=new Grooming(); @@ -184,8 +195,9 @@ public void weeklyMonthlyOpenEnd() throws Exception { List deleteDates=new ArrayList(); grooming.getFilesToDelete(today, allHistory, deleteDates); expectedDeleteDates.sort(null); - Assert.assertEquals(expectedDeleteDates, deleteDates); + assertEquals(expectedDeleteDates, deleteDates); } + @Test public void doWeeklyMonthlyOpenEnd() throws Exception { Grooming grooming=new Grooming(); @@ -204,8 +216,9 @@ public void doWeeklyMonthlyOpenEnd() throws Exception { today = addOneDay(today); } Date[] expected=new Date[] {dateParser.parse("2022-05-01"),dateParser.parse("2022-06-01"),dateParser.parse("2022-06-06"),dateParser.parse("2022-06-13"),dateParser.parse("2022-06-20"),dateParser.parse("2022-06-27"),dateParser.parse("2022-06-29")}; - Assert.assertArrayEquals(expected, allHistory.toArray(new Date[allHistory.size()])); + assertArrayEquals(expected, allHistory.toArray(new Date[0])); } + @Test public void doWeeklyYearlyOpenEnd() throws Exception { Grooming grooming=new Grooming(); @@ -224,9 +237,10 @@ public void doWeeklyYearlyOpenEnd() throws Exception { today = addOneDay(today); //System.out.println(today); } - Date[] expected=new Date[] {dateParser.parse("2022-05-01"),dateParser.parse("2023-01-01"),dateParser.parse("2023-04-10"),dateParser.parse("2023-04-17"),dateParser.parse("2023-04-24"),dateParser.parse("2023-05-01"),dateParser.parse("2023-05-05")}; - Assert.assertArrayEquals(expected, allHistory.toArray(new Date[allHistory.size()])); + Date[] expected = new Date[] {dateParser.parse("2022-05-01"),dateParser.parse("2023-01-01"),dateParser.parse("2023-04-10"),dateParser.parse("2023-04-17"),dateParser.parse("2023-04-24"),dateParser.parse("2023-05-01"),dateParser.parse("2023-05-05")}; + assertArrayEquals(expected, allHistory.toArray(new Date[0])); } + protected Date addOneDay(Date today) { java.util.Calendar c=Grooming.getCalendar(); c.setTime(today); @@ -234,6 +248,7 @@ protected Date addOneDay(Date today) { today=new Date(c.getTimeInMillis()); return today; } + private void print(String prefix,List allHistory,Date today) { StringBuffer all=new StringBuffer(); String sep=""; @@ -249,6 +264,7 @@ private void print(String prefix,List allHistory,Date today) { } System.out.println(prefix+all); } + @Test public void weeklyMonthly() throws Exception { Grooming grooming=new Grooming(); @@ -256,6 +272,7 @@ public void weeklyMonthly() throws Exception { grooming.setMonthly(new GroomingRange(2,5)); grooming.isValid(); } + @Test public void weeklyMonthlyMismatch() throws Exception { Grooming grooming=new Grooming(); @@ -263,11 +280,10 @@ public void weeklyMonthlyMismatch() throws Exception { grooming.setMonthly(new GroomingRange(1,5)); try { grooming.isValid(); - Assert.fail(); - }catch(IOException e) { - - } + fail(); + } catch(IOException ignored) {} } + @Test public void weeklyYearlyOpenEnd() throws Exception { Grooming grooming=new Grooming(); @@ -275,6 +291,7 @@ public void weeklyYearlyOpenEnd() throws Exception { grooming.setYearly(new GroomingRange(2,null)); grooming.isValid(); } + @Test public void weeklyYearly() throws Exception { Grooming grooming=new Grooming(); @@ -282,6 +299,7 @@ public void weeklyYearly() throws Exception { grooming.setYearly(new GroomingRange(2,5)); grooming.isValid(); } + @Test public void weeklyYearlyMismatch() throws Exception { Grooming grooming=new Grooming(); @@ -289,11 +307,10 @@ public void weeklyYearlyMismatch() throws Exception { grooming.setYearly(new GroomingRange(3,5)); try { grooming.isValid(); - Assert.fail(); - }catch(IOException e) { - - } + fail(); + } catch(IOException ignored) {} } + @Test public void weeklyYearlyOpenEndMismatch() throws Exception { Grooming grooming=new Grooming(); @@ -301,11 +318,10 @@ public void weeklyYearlyOpenEndMismatch() throws Exception { grooming.setYearly(new GroomingRange(29,null)); try { grooming.isValid(); - Assert.fail(); - }catch(IOException e) { - - } + fail(); + } catch(IOException ignored) {} } + @Test public void yearlyOpenEnd() throws Exception { Grooming grooming=new Grooming(); @@ -323,8 +339,9 @@ public void yearlyOpenEnd() throws Exception { List deleteDates=new ArrayList(); grooming.getFilesToDelete(today, allHistory, deleteDates); expectedDeleteDates.sort(null); - Assert.assertEquals(expectedDeleteDates, deleteDates); + assertEquals(expectedDeleteDates, deleteDates); } + @Test public void yearlyOnly() throws Exception { Grooming grooming=new Grooming(); @@ -339,6 +356,6 @@ public void yearlyOnly() throws Exception { List deleteDates=new ArrayList(); grooming.getFilesToDelete(today, allHistory, deleteDates); expectedDeleteDates.sort(null); - Assert.assertEquals(expectedDeleteDates, deleteDates); + assertEquals(expectedDeleteDates, deleteDates); } } diff --git a/gretl/src/test/java/ch/so/agi/gretl/util/SimiSvcClientMock.java b/gretl/src/test/java/ch/so/agi/gretl/util/SimiSvcClientMock.java index 1ecc329b..e1301e55 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/util/SimiSvcClientMock.java +++ b/gretl/src/test/java/ch/so/agi/gretl/util/SimiSvcClientMock.java @@ -18,6 +18,7 @@ public class SimiSvcClientMock implements SimiSvcApi { @Override public void setup(String endpoint, String usr, String pwd) { } + @Override public void setupTokenService(String endpoint, String usr, String pwd) { } diff --git a/gretl/src/test/java/ch/so/agi/gretl/util/SimiSvcClientTest.java b/gretl/src/test/java/ch/so/agi/gretl/util/SimiSvcClientTest.java index 5d3ecec8..b75a25b1 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/util/SimiSvcClientTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/util/SimiSvcClientTest.java @@ -1,9 +1,7 @@ package ch.so.agi.gretl.util; -import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Date; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -11,18 +9,20 @@ import javax.servlet.http.HttpServletResponse; import org.apache.catalina.Context; -import org.apache.catalina.LifecycleException; import org.apache.catalina.Wrapper; import org.apache.catalina.startup.Tomcat; -import org.junit.AfterClass; +import org.junit.jupiter.api.AfterAll; import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import ch.so.agi.gretl.steps.PublisherStep; import ch.so.agi.gretl.util.publisher.PublicationLog; import ch.so.agi.gretl.util.publisher.PublishedRegion; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class SimiSvcClientTest { public final static String OAUTH_TOKEN_GRANT_USR="admin"; public final static String OAUTH_TOKEN_GRANT_PWD="admin"; @@ -79,7 +79,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws Se } private static CustomServlet servlet=null; private static Tomcat tomcat = null; - @BeforeClass + @BeforeAll public static synchronized void setupServer() throws Exception { if(tomcat==null) { tomcat = new Tomcat(); @@ -95,7 +95,7 @@ public static synchronized void setupServer() throws Exception { tomcat.start(); } } - @AfterClass + @AfterAll public static synchronized void stopServer() throws Exception { if(tomcat!=null) { tomcat.stop(); @@ -112,11 +112,11 @@ public void getLeaflet() throws Exception { final String expected_dataIdent = "ch.so.agi.mopublic"; final String expected_published = "2022-03-08T00:00:00.000"; String leaflet=svc.getLeaflet(expected_dataIdent, new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(expected_published)); - Assert.assertEquals(DOC_LEAFLET, leaflet); - Assert.assertEquals(expected_dataIdent, servlet.doc_dataident); - Assert.assertEquals(expected_published, servlet.doc_published); - Assert.assertEquals("text/html", servlet.doc_contentType); - Assert.assertEquals("Bearer " + OAUTH_TOKEN, servlet.doc_authHeaderValue); + assertEquals(DOC_LEAFLET, leaflet); + assertEquals(expected_dataIdent, servlet.doc_dataident); + assertEquals(expected_published, servlet.doc_published); + assertEquals("text/html", servlet.doc_contentType); + assertEquals("Bearer " + OAUTH_TOKEN, servlet.doc_authHeaderValue); } @Test public void getAccessToken() throws Exception { @@ -125,15 +125,15 @@ public void getAccessToken() throws Exception { svc.setup("http://localhost:8080/simi-svc/rest",OAUTH_TOKEN_GRANT_USR,OAUTH_TOKEN_GRANT_PWD); svc.setupTokenService("http://localhost:8080/simi-svc/rest",OAUTH_TOKEN_USR,OAUTH_TOKEN_PWD); String token=svc.getAccessToken(); - Assert.assertEquals(OAUTH_TOKEN,token); + assertEquals(OAUTH_TOKEN,token); { String auth = OAUTH_TOKEN_USR + ":" + OAUTH_TOKEN_PWD; byte[] encodedAuth = java.util.Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8)); String authHeaderValue = "Basic " + new String(encodedAuth); - Assert.assertEquals(authHeaderValue, servlet.oauthToken_authHeaderValue); + assertEquals(authHeaderValue, servlet.oauthToken_authHeaderValue); } - Assert.assertEquals("application/x-www-form-urlencoded",servlet.oauthToken_contentType); - Assert.assertEquals("grant_type=password&username="+OAUTH_TOKEN_GRANT_USR+"&password="+OAUTH_TOKEN_GRANT_PWD,servlet.oauthToken_content); + assertEquals("application/x-www-form-urlencoded",servlet.oauthToken_contentType); + assertEquals("grant_type=password&username="+OAUTH_TOKEN_GRANT_USR+"&password="+OAUTH_TOKEN_GRANT_PWD,servlet.oauthToken_content); } @Test public void notifyPublication() throws Exception { @@ -142,9 +142,9 @@ public void notifyPublication() throws Exception { svc.setup("http://localhost:8080/simi-svc/rest",null,null); final PublicationLog data = new PublicationLog("ch.so.agi.mopublic", new java.text.SimpleDateFormat("yyyy-MM-dd").parse("2022-03-08")); svc.notifyPublication(data); - Assert.assertEquals("application/json", servlet.pubsignal_contentType); - Assert.assertNull(servlet.pubsignal_authHeaderValue); - Assert.assertEquals(PublisherStep.publicationToString(data),servlet.pubsignal_content); + assertEquals("application/json", servlet.pubsignal_contentType); + assertNull(servlet.pubsignal_authHeaderValue); + assertEquals(PublisherStep.publicationToString(data),servlet.pubsignal_content); } @Test public void notifyPublicationOAuth() throws Exception { @@ -157,9 +157,9 @@ public void notifyPublicationOAuth() throws Exception { final PublicationLog data = new PublicationLog(expected_dataIdent, new java.text.SimpleDateFormat("yyyy-MM-dd").parse(expected_published)); //String leaflet=svc.getLeaflet(expected_dataIdent, new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(expected_published)); svc.notifyPublication(data); - Assert.assertEquals("application/json", servlet.pubsignal_contentType); - Assert.assertEquals("Bearer " + OAUTH_TOKEN, servlet.pubsignal_authHeaderValue); - Assert.assertEquals(PublisherStep.publicationToString(data),servlet.pubsignal_content); + assertEquals("application/json", servlet.pubsignal_contentType); + assertEquals("Bearer " + OAUTH_TOKEN, servlet.pubsignal_authHeaderValue); + assertEquals(PublisherStep.publicationToString(data),servlet.pubsignal_content); } @Test public void notifyPublicationRegions() throws Exception { @@ -174,8 +174,8 @@ public void notifyPublicationRegions() throws Exception { pub.addPublishedRegion(new PublishedRegion("22")); pub.addPublishedRegion(new PublishedRegion("33")); svc.notifyPublication(pub); - Assert.assertEquals("application/json", servlet.pubsignal_contentType); - Assert.assertEquals("Bearer " + OAUTH_TOKEN, servlet.pubsignal_authHeaderValue); - Assert.assertEquals(PublisherStep.publicationToString(pub),servlet.pubsignal_content); + assertEquals("application/json", servlet.pubsignal_contentType); + assertEquals("Bearer " + OAUTH_TOKEN, servlet.pubsignal_authHeaderValue); + assertEquals(PublisherStep.publicationToString(pub),servlet.pubsignal_content); } } diff --git a/gretl/src/test/java/ch/so/agi/gretl/util/SqlReaderTest.java b/gretl/src/test/java/ch/so/agi/gretl/util/SqlReaderTest.java index 0d3d37ee..d4561756 100755 --- a/gretl/src/test/java/ch/so/agi/gretl/util/SqlReaderTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/util/SqlReaderTest.java @@ -1,42 +1,28 @@ package ch.so.agi.gretl.util; -import ch.so.agi.gretl.logging.GretlLogger; -import ch.so.agi.gretl.logging.LogEnvironment; import ch.so.agi.gretl.testutil.TestUtil; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; +import java.nio.file.Path; -public class SqlReaderTest { - private static GretlLogger log; +import static org.junit.jupiter.api.Assertions.assertEquals; - static { - LogEnvironment.initStandalone(); - log = LogEnvironment.getLogger(SqlReaderTest.class); - } +public class SqlReaderTest { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public Path folder; @Test public void lineCommentsCleanRemoved() throws Exception { - String lineComment = "--This is a singleline comment."; String statement = "select \"user\", \"admin\", \"alias\" from sqlkeywords"; - String wholeStatement = lineComment + "\n" + statement; File sqlFile = TestUtil.createTempFile(folder, wholeStatement, "statementIsUnchanged.sql"); - String parsedStatement = new SqlReader().readSqlStmt(sqlFile); - Assert.assertEquals("Line comment must be removed without changing the statement itself", statement, - parsedStatement); + assertEquals(parsedStatement, statement,"Line comment must be removed without changing the statement itself"); } } diff --git a/gretl/src/test/java/ch/so/agi/gretl/util/metapublisher/RegionsTest.java b/gretl/src/test/java/ch/so/agi/gretl/util/metapublisher/RegionsTest.java index ddcaee47..7694cfe0 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/util/metapublisher/RegionsTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/util/metapublisher/RegionsTest.java @@ -1,28 +1,24 @@ package ch.so.agi.gretl.util.metapublisher; +import ch.so.agi.gretl.logging.GretlLogger; +import ch.so.agi.gretl.logging.LogEnvironment; +import ch.so.agi.gretl.steps.metapublisher.meta.RegionsUtil; +import ch.so.agi.gretl.testutil.TestUtil; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; -import java.util.Map; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import ch.so.agi.gretl.logging.GretlLogger; -import ch.so.agi.gretl.logging.LogEnvironment; -import ch.so.agi.gretl.steps.metapublisher.meta.RegionsUtil; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class RegionsTest { protected GretlLogger log; @@ -30,9 +26,9 @@ public class RegionsTest { public RegionsTest() { this.log = LogEnvironment.getLogger(this.getClass()); } - - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + + @TempDir + public Path folder; @Test public void update_Ok() throws Exception { @@ -41,8 +37,8 @@ public void update_Ok() throws Exception { String origDate = "1999-01-01"; String fileName = "ch.so.agi.av.dm01_so.json"; File jsonFile = Paths.get("src/test/resources/data/metapublisher/util/", fileName).toFile(); - File outDirectory = folder.newFolder("update_ok"); - File targetJsonFile = Paths.get(outDirectory.getAbsolutePath(), fileName).toFile(); + Path outDirectory = TestUtil.createTempDir(folder, "update_ok"); + File targetJsonFile = Paths.get(outDirectory.toAbsolutePath().toString(), fileName).toFile(); Files.copy(jsonFile.toPath(), targetJsonFile.toPath(), StandardCopyOption.REPLACE_EXISTING); diff --git a/gretl/src/test/java/ch/so/agi/gretl/util/publisher/PublicationLogTest.java b/gretl/src/test/java/ch/so/agi/gretl/util/publisher/PublicationLogTest.java index 4e4484e2..099a2796 100644 --- a/gretl/src/test/java/ch/so/agi/gretl/util/publisher/PublicationLogTest.java +++ b/gretl/src/test/java/ch/so/agi/gretl/util/publisher/PublicationLogTest.java @@ -6,13 +6,16 @@ import java.nio.file.Paths; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ch.so.agi.gretl.logging.GretlLogger; import ch.so.agi.gretl.logging.LogEnvironment; import ch.so.agi.gretl.steps.AbstractPublisherStepTest; import ch.so.agi.gretl.steps.PublisherStep; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class PublicationLogTest { final public static String SRC_TEST_DATA = AbstractPublisherStepTest.SRC_TEST_DATA; final protected Path localTestOut = Paths.get("build").resolve("out"); @@ -33,10 +36,10 @@ public void readMinimalFile() throws Exception { final Path file = localTestOut.resolve("minimalPublication.json"); PublisherStep.writePublication(file,expected); PublicationLog actual=PublisherStep.readPublication(file); - Assert.assertEquals(expected.getDataIdent(), actual.getDataIdent()); - Assert.assertEquals(expected.getPublished(), actual.getPublished()); - Assert.assertNull(actual.getPublishedBaskets()); - Assert.assertNull(actual.getPublishedRegions()); + assertEquals(expected.getDataIdent(), actual.getDataIdent()); + assertEquals(expected.getPublished(), actual.getPublished()); + assertNull(actual.getPublishedBaskets()); + assertNull(actual.getPublishedRegions()); } @Test public void readBasketsFile() throws Exception { @@ -48,16 +51,16 @@ public void readBasketsFile() throws Exception { final Path file = localTestOut.resolve("basketsPublication.json"); PublisherStep.writePublication(file,expected); PublicationLog actual=PublisherStep.readPublication(file); - Assert.assertEquals(expected.getDataIdent(), actual.getDataIdent()); - Assert.assertEquals(expected.getPublished(), actual.getPublished()); - Assert.assertEquals(2,actual.getPublishedBaskets().size()); - Assert.assertEquals("SO_AGI_MOpublic_20201009",actual.getPublishedBaskets().get(0).getModel()); - Assert.assertEquals("Bodenbedeckung",actual.getPublishedBaskets().get(0).getTopic()); - Assert.assertEquals("oltenBID",actual.getPublishedBaskets().get(0).getBasket()); - Assert.assertEquals("DM01",actual.getPublishedBaskets().get(1).getModel()); - Assert.assertEquals("Liegenschaften",actual.getPublishedBaskets().get(1).getTopic()); - Assert.assertEquals("wangenBID",actual.getPublishedBaskets().get(1).getBasket()); - Assert.assertNull(actual.getPublishedRegions()); + assertEquals(expected.getDataIdent(), actual.getDataIdent()); + assertEquals(expected.getPublished(), actual.getPublished()); + assertEquals(2,actual.getPublishedBaskets().size()); + assertEquals("SO_AGI_MOpublic_20201009",actual.getPublishedBaskets().get(0).getModel()); + assertEquals("Bodenbedeckung",actual.getPublishedBaskets().get(0).getTopic()); + assertEquals("oltenBID",actual.getPublishedBaskets().get(0).getBasket()); + assertEquals("DM01",actual.getPublishedBaskets().get(1).getModel()); + assertEquals("Liegenschaften",actual.getPublishedBaskets().get(1).getTopic()); + assertEquals("wangenBID",actual.getPublishedBaskets().get(1).getBasket()); + assertNull(actual.getPublishedRegions()); } @Test public void readRegionsFile() throws Exception { @@ -71,19 +74,19 @@ public void readRegionsFile() throws Exception { final Path file = localTestOut.resolve("regionsPublication.json"); PublisherStep.writePublication(file,expected); PublicationLog actual=PublisherStep.readPublication(file); - Assert.assertEquals(expected.getDataIdent(), actual.getDataIdent()); - Assert.assertEquals(expected.getPublished(), actual.getPublished()); - Assert.assertNull(actual.getPublishedBaskets()); - Assert.assertEquals(2,actual.getPublishedRegions().size()); - Assert.assertEquals("olten",actual.getPublishedRegions().get(0).getRegion()); - Assert.assertEquals(1,actual.getPublishedRegions().get(0).getPublishedBaskets().size()); - Assert.assertEquals("SO_AGI_MOpublic_20201009",actual.getPublishedRegions().get(0).getPublishedBaskets().get(0).getModel()); - Assert.assertEquals("Bodenbedeckung",actual.getPublishedRegions().get(0).getPublishedBaskets().get(0).getTopic()); - Assert.assertEquals("oltenBID",actual.getPublishedRegions().get(0).getPublishedBaskets().get(0).getBasket()); - Assert.assertEquals("wangen",actual.getPublishedRegions().get(1).getRegion()); - Assert.assertEquals(1,actual.getPublishedRegions().get(1).getPublishedBaskets().size()); - Assert.assertEquals("SO_AGI_MOpublic_20201009",actual.getPublishedRegions().get(1).getPublishedBaskets().get(0).getModel()); - Assert.assertEquals("Bodenbedeckung",actual.getPublishedRegions().get(1).getPublishedBaskets().get(0).getTopic()); - Assert.assertEquals("wangenBID",actual.getPublishedRegions().get(1).getPublishedBaskets().get(0).getBasket()); + assertEquals(expected.getDataIdent(), actual.getDataIdent()); + assertEquals(expected.getPublished(), actual.getPublished()); + assertNull(actual.getPublishedBaskets()); + assertEquals(2,actual.getPublishedRegions().size()); + assertEquals("olten",actual.getPublishedRegions().get(0).getRegion()); + assertEquals(1,actual.getPublishedRegions().get(0).getPublishedBaskets().size()); + assertEquals("SO_AGI_MOpublic_20201009",actual.getPublishedRegions().get(0).getPublishedBaskets().get(0).getModel()); + assertEquals("Bodenbedeckung",actual.getPublishedRegions().get(0).getPublishedBaskets().get(0).getTopic()); + assertEquals("oltenBID",actual.getPublishedRegions().get(0).getPublishedBaskets().get(0).getBasket()); + assertEquals("wangen",actual.getPublishedRegions().get(1).getRegion()); + assertEquals(1,actual.getPublishedRegions().get(1).getPublishedBaskets().size()); + assertEquals("SO_AGI_MOpublic_20201009",actual.getPublishedRegions().get(1).getPublishedBaskets().get(0).getModel()); + assertEquals("Bodenbedeckung",actual.getPublishedRegions().get(1).getPublishedBaskets().get(0).getTopic()); + assertEquals("wangenBID",actual.getPublishedRegions().get(1).getPublishedBaskets().get(0).getBasket()); } }