https://github.com/kosmisk-dk/postgresql-test-datasource
DataSource Provider for Integation Testing with PostgreSQL databases
https://github.com/kosmisk-dk/postgresql-test-datasource
integration-testing java postgresql
Last synced: 3 months ago
JSON representation
DataSource Provider for Integation Testing with PostgreSQL databases
- Host: GitHub
- URL: https://github.com/kosmisk-dk/postgresql-test-datasource
- Owner: kosmisk-dk
- License: apache-2.0
- Created: 2018-02-15T11:16:25.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-09-08T00:07:25.000Z (over 3 years ago)
- Last Synced: 2025-07-26T01:24:45.434Z (9 months ago)
- Topics: integration-testing, java, postgresql
- Language: Java
- Size: 25.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# PostgreSQL DataSource Integration Test Helper
A helper class for PostgreSQL integration testing.
It allows for postgresql connections made from
* System properties (give name of property that defines the port and the name of the database)
* Environment Variables (give name of environment variable, that contain a connect URI)
* fallback
* from PG* Environment variables
* from ${user.name} (as user, password and database)
It also implements a number of helper methods, to manipulate the database.
Functions to:
* wipe a schema
* dump/truncate and restore tables either by name from a list or all tables in foreign key respecting order
## Usage
A typical use case is outlined below:
### Typical Test Environment
org.apache.maven.plugins
maven-failsafe-plugin
${some.version}
false
${postgresql.testbase.port}
${postgresql.dump.folder}
-Dfile.encoding=${project.build.sourceEncoding}
integration-test
verify
dk.kosmisk
postgresql-maven-plugin
${some.version}
postgresql-test-database
setup
startup
shutdown
testbase
${basedir}/src/test/resources/schema.sql
${basedir}/src/test/resources/testdata.sql
...
dk.kosmisk
postgresql-test-datasource
${some.version}
jar
### Typical Test
public class EntityTest {
private PostgresITDataSource dataSource;
@Before
public void setup() throws Exception {
dataSource = PostgresITDataSource.builder()
.fromProperty("testbase", "postgresql.testbase.port")
.fromEnvironment("MY_PGTEST_URL")
.withFallback()
.build();
dataSource.copyAllTablesToDisk();
}
@After
public void cleanup() throws Exception {
dataSource.truncateAllTables();
dataSource.copyAllTablesFromDisk();
}
@Test
public void testSomething() throws Exception {
System.out.println("Something");
try(Connection connection = dataSource.getConnection()) {
...
}
}