Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added postgres as a test container #77

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 11, 17 ]
java: [ 11, 17, 21 ]
name: Java ${{ matrix.java }} build
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: 'maven'

- name: Build with Maven on JDK ${{ matrix.java }}
run: mvn --batch-mode --update-snapshots verify
run: mvn --batch-mode --update-snapshots verify
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/release-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install gpg secret key
run: cat <(echo -e "${{ secrets.GPG_SECRET_KEY }}") | gpg --batch --import

- name: Set up Maven Central Repository
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
Expand All @@ -28,18 +28,17 @@ jobs:
servers: |
[{
"id": "ossrh",
"username": "${{ secrets.OSSRH_USERNAME }}",
"password": "${{ secrets.OSSRH_TOKEN }}"
"username": "${{ secrets.OSSRH_USER_V2 }}",
"password": "${{ secrets.OSSRH_TOKEN_V2 }}"
},
{
"id": "gpg.passphrase",
"passphrase": "${{ secrets.GPG_SECRET_KEY_PASSWORD }}",
"configuration": {}
}]


- name: Verify package
run: mvn --batch-mode verify

- name: Release package
run: mvn --batch-mode -DskipTests=true releaser:release
63 changes: 63 additions & 0 deletions .github/workflows/snapshot-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "Build - Snapshot"
on:
push:
branches-ignore:
- main
tags-ignore:
- '*'
pull_request:
branches:
- main

jobs:
snapshot_build:
name: Snapshot build and publish
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install gpg secret key
run: cat <(echo -e "${{ secrets.GPG_SECRET_KEY }}") | gpg --batch --import

- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
cache: 'maven'

- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Set up maven settings
uses: s4u/maven-settings-action@v2.8.0
with:
servers: |
[{
"id": "ossrh",
"username": "${{ secrets.OSSRH_USER_V2 }}",
"password": "${{ secrets.OSSRH_TOKEN_V2 }}"
},
{
"id": "gpg.passphrase",
"passphrase": "${{ secrets.GPG_SECRET_KEY_PASSWORD }}",
"configuration": {}
}]

- name: Upload snapshot
run: |
mvn \
--no-transfer-progress \
--batch-mode \
clean deploy
28 changes: 25 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<testcontainers.version>1.20.1</testcontainers.version>
<junit.version>5.10.2</junit.version>
<h2.version>2.2.224</h2.version>
<postgres.version>42.7.3</postgres.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.2</version>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -78,7 +82,25 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -306,4 +328,4 @@
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</project>
</project>
7 changes: 6 additions & 1 deletion src/main/java/com/hsbc/engineering/JDBCInquirer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.platform.launcher.listeners.TestExecutionSummary;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.logging.Logger;
Expand Down Expand Up @@ -50,6 +49,12 @@
*
*/
public class JDBCInquirer {

/**
* EmptyContructor to fix issue with Java 21 asking for java doc - warning: use of default constructor, which does not provide a comment
*/
public JDBCInquirer() { }

/**
* Default logger
*/
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/hsbc/engineering/JDBCSpecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
/**
* <p>JDBCSpecTest class.</p>
*
* For running JDBC Spec tests
*/
public class JDBCSpecTest {

/**
* EmptyContructor to fix issue with Java 21 asking for java doc - warning: use of default constructor, which does not provide a comment
*/
public JDBCSpecTest() { }

//Check for tables
@DisplayName("Checks if tables can be extracted via jdbc")
@ParameterizedTest
@ArgumentsSource(ConnectionProvider.class)
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/com/hsbc/engineering/PostgresConnectionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.hsbc.engineering;

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

import java.util.Map;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

@Testcontainers
public class PostgresConnectionTest {
final String user = "hello";
final String password = "moo";
final String database = "foo";

private Map<String, String> getConnectionMap() {
Map<String, String> args = Map.of(
Arguments.CLASS_NAME, "org.postgresql.Driver",
Arguments.USER, user,
Arguments.PWD, password,
Arguments.URL, pSqlContainer.getJdbcUrl(),
Arguments.SQL, "SELECT 2");

return args;
}

@Container
private PostgreSQLContainer pSqlContainer = new PostgreSQLContainer<>("postgres:16")
.withDatabaseName(database)
.withUsername(user)
.withPassword(password);

@Test
void checkOK() {
assertTrue(pSqlContainer.isRunning());
}

@Test
void mainFunctionTest() {
Assertions.assertDoesNotThrow(() -> JDBCInquirer.runSimpleConnectionTest(getConnectionMap()));
}

@Test
void perfFunctionTest() {
Assertions.assertDoesNotThrow(() -> JDBCInquirer.timeExtractionTest(getConnectionMap()));
}
}
Loading