-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/com/hsbc/engineering/PostgresConnectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |