Skip to content

Commit 3ca2575

Browse files
committed
ISSUE-680 # Run Postgres tests in CI
1 parent ad4fba4 commit 3ca2575

File tree

9 files changed

+133
-17
lines changed

9 files changed

+133
-17
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ jobs:
2828
- name: Running Kafka
2929
run: docker-compose -f docker/compose/kafka-schema-registry.yml up -d && sleep 10
3030

31+
- name: Running PostgreSQL (to test DB SQL Executor)
32+
run: docker-compose -f docker/compose/pg_compose.yml up -d
33+
3134
- name: Building and testing the changes
3235
run: mvn clean test

core/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,11 @@
184184
<artifactId>h2</artifactId>
185185
<scope>test</scope>
186186
</dependency>
187-
<!--uncomment this to test database with postgres
188187
<dependency>
189188
<groupId>org.postgresql</groupId>
190189
<artifactId>postgresql</artifactId>
191-
<version>42.7.4</version>
192190
<scope>test</scope>
193191
</dependency>
194-
-->
195192
<dependency>
196193
<groupId>com.aventstack</groupId>
197194
<artifactId>extentreports</artifactId>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.jsmart.zerocode.core.db;
2+
import org.jsmart.zerocode.core.domain.Scenario;
3+
import org.jsmart.zerocode.core.domain.TargetEnv;
4+
import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
8+
@TargetEnv("db_test_postgres.properties")
9+
@RunWith(ZeroCodeUnitRunner.class)
10+
public class DbSqlExecutorScenarioPostgresTest {
11+
12+
// Note: Spin up the DB container before running this test: docker/compose/pg_compose.yml
13+
14+
@Test
15+
@Scenario("integration_test_files/db/db_csv_load_with_headers_postgres.json")
16+
public void testDbCsvLoadWithHeaders() throws Exception {
17+
}
18+
19+
@Test
20+
@Scenario("integration_test_files/db/db_sql_execute_postgres.json")
21+
public void testDbSqlExecute() throws Exception {
22+
}
23+
24+
}

core/src/test/java/org/jsmart/zerocode/core/db/DbSqlExecutorScenarioTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
@RunWith(ZeroCodeUnitRunner.class)
1010
public class DbSqlExecutorScenarioTest {
1111

12-
// NOTE: Below tests will fail when run in postgres because this database stores identifiers in lowercase.
13-
// to make tests pass, change the keys in the response.rows to lowercase
14-
1512
@Test
1613
@Scenario("integration_test_files/db/db_csv_load_with_headers.json")
1714
public void testDbCsvLoadWithHeaders() throws Exception {

core/src/test/resources/db_test.properties

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,3 @@ db.driver.url=jdbc:h2:./target/test_db_sql_executor
55
# If connection requires authentication, specify user and password:
66
# db.driver.user=
77
# db.driver.password=
8-
9-
# To run the tests with postgres:
10-
# - Spin up the DB container (this was tested with the below versions #680, latest version is the recommended)
11-
# docker run --name zerocode-postgres -p:5432:5432 -e POSTGRES_PASSWORD=mypassword -d postgres:17.0
12-
# docker run --name zerocode-postgres -p:5432:5432 -e POSTGRES_PASSWORD=mypassword -d postgres:12.0
13-
# docker run --name zerocode-postgres -p:5432:5432 -e POSTGRES_PASSWORD=mypassword -d postgres:9.0
14-
# - add the driver dependency to the pom.xml: https://central.sonatype.com/artifact/org.postgresql/postgresql
15-
# - and uncomment the properties below:
16-
# db.driver.url=jdbc:postgresql://localhost:5432/postgres
17-
# db.driver.user=postgres
18-
# db.driver.password=mypassword
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Connection info used by the DbSqlExecutor
2+
3+
# JDBC connection string to a PostgreSQL test database
4+
# Spin up the DB container before running the postgres tests: docker/compose/pg_compose.yml
5+
db.driver.url=jdbc:postgresql://localhost:35432/postgres
6+
db.driver.user=postgres
7+
db.driver.password=example
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"scenarioName": "DbSqlExecutor: Load a CSV file with headers - PostgreSQL",
3+
"steps": [
4+
{
5+
"name": "Test database setup",
6+
"url": "org.jsmart.zerocode.core.db.DbSqlExecutor",
7+
"operation": "EXECUTE",
8+
"request": {
9+
"sql": "DROP TABLE IF EXISTS PLAYERS; CREATE TABLE PLAYERS (ID INTEGER, NAME VARCHAR(20), AGE INTEGER);"
10+
},
11+
"verify": { }
12+
},
13+
{
14+
"name": "Insert rows from a CSV file with headers",
15+
"url": "org.jsmart.zerocode.core.db.DbSqlExecutor",
16+
"operation": "LOADCSV",
17+
"request": {
18+
"tableName": "players",
19+
"csvSource": "integration_test_files/db/players_with_headers.csv",
20+
"withHeaders" : true
21+
},
22+
"verify": {
23+
"size" : 3
24+
}
25+
},
26+
{
27+
"name": "Check the content of inserted rows",
28+
"url": "org.jsmart.zerocode.core.db.DbSqlExecutor",
29+
"operation": "EXECUTE",
30+
"request": {
31+
"sql": "SELECT ID, NAME, AGE FROM PLAYERS ORDER BY ID"
32+
},
33+
"verify": {
34+
"rows.SIZE": 3,
35+
"rows": [ //<-- same than db_csv_load_with_headers.json, but keys in lowercase (postgres converts to lower)
36+
{ "id": 1001, "name": "Ronaldo", "age": 23 },
37+
{ "id": 1002, "name": "Devaldo", "age": null },
38+
{ "id": 1003, "name": "Trevaldo", "age": 35 }
39+
]
40+
}
41+
}
42+
]
43+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"scenarioName": "DbSqlExecutor: Read and write data using SQL - PostgreSQL",
3+
"steps": [
4+
{
5+
"name": "Test database setup",
6+
"url": "org.jsmart.zerocode.core.db.DbSqlExecutor",
7+
"operation": "EXECUTE",
8+
"request": {
9+
"sql": "DROP TABLE IF EXISTS PEOPLE; CREATE TABLE PEOPLE (ID INTEGER, NAME VARCHAR(20), START DATE, ACTIVE BOOLEAN);"
10+
},
11+
"verify": { }
12+
},
13+
{
14+
"name": "Insert rows using SQL",
15+
"url": "org.jsmart.zerocode.core.db.DbSqlExecutor",
16+
"operation": "EXECUTE",
17+
"request": {
18+
"sql": "INSERT INTO PEOPLE VALUES (1, 'Jeff Bejo', '2024-09-01', true); INSERT INTO PEOPLE VALUES (2, 'John Bajo', '2024-09-02', false);"
19+
},
20+
"verify": { }
21+
},
22+
{
23+
"name": "Insert with parameters and nulls",
24+
"url": "org.jsmart.zerocode.core.db.DbSqlExecutor",
25+
"operation": "execute", //<-- Uppercase for consistency, but also allows lowercase
26+
"request": {
27+
"sql": "INSERT INTO PEOPLE (ID, NAME, START, ACTIVE) VALUES (?, ?, ?, ?);",
28+
"sqlParams": [3, null, null, true]
29+
},
30+
"verify": { }
31+
},
32+
{
33+
"name": "Retrieve rows using SQL",
34+
"url": "org.jsmart.zerocode.core.db.DbSqlExecutor",
35+
"operation": "EXECUTE",
36+
"request": {
37+
"sql": "SELECT ID, NAME, to_char(START,'yyyy-MM-dd') AS START, ACTIVE FROM PEOPLE WHERE ACTIVE=?",
38+
"sqlParams": [true]
39+
},
40+
"verify": {
41+
"rows.SIZE": 2,
42+
"rows": [ //<-- same than db_sql_execute.json, but keys in lowercase (postgres converts to lower)
43+
{ "id": 1, "name": "Jeff Bejo", "start": "2024-09-01", "active": true },
44+
{ "id": 3, "name": null, "start": null, "active": true }
45+
]
46+
}
47+
}
48+
]
49+
}

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<httpclient.version>4.5.13</httpclient.version>
9090
<httpmime.version>4.5.12</httpmime.version>
9191
<h2.db.version>2.2.220</h2.db.version>
92+
<postgres.db.version>42.7.4</postgres.db.version>
9293
<extentreports.version>5.0.9</extentreports.version>
9394
<version.kafka-clients>3.7.0</version.kafka-clients>
9495
<version.gson>2.10.1</version.gson>
@@ -299,6 +300,12 @@
299300
<version>${h2.db.version}</version>
300301
<scope>test</scope>
301302
</dependency>
303+
<dependency>
304+
<groupId>org.postgresql</groupId>
305+
<artifactId>postgresql</artifactId>
306+
<version>${postgres.db.version}</version>
307+
<scope>test</scope>
308+
</dependency>
302309
<dependency>
303310
<groupId>com.aventstack</groupId>
304311
<artifactId>extentreports</artifactId>

0 commit comments

Comments
 (0)