Skip to content

Commit

Permalink
Merge branch 'refs/heads/feature/134-update-junit' into feature/136-t…
Browse files Browse the repository at this point in the history
…estcontainers
  • Loading branch information
Daniel Kubanyi committed Jul 25, 2024
2 parents 2f56bdb + 5a68d0a commit fb81c38
Show file tree
Hide file tree
Showing 38 changed files with 510 additions and 552 deletions.
18 changes: 8 additions & 10 deletions gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/Av2chTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package ch.so.agi.gretl.jobs;

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

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

import org.junit.Test;

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

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

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

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

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

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

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

import java.io.File;

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

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

import static org.junit.Assert.assertEquals;

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

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

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

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

public class Csv2ExcelTest {

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

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

import java.nio.file.Paths;

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

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

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

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

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

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

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

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

@Testcontainers
public class CsvExportTest {

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

@Test
public void exportOk() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()));
}

}
51 changes: 22 additions & 29 deletions gretl/src/integrationTest/java/ch/so/agi/gretl/jobs/CurlTest.java
Original file line number Diff line number Diff line change
@@ -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();
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"));


}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Loading

0 comments on commit fb81c38

Please sign in to comment.