Skip to content

Commit

Permalink
Add a test DataSource to the file-service
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie committed Apr 14, 2020
1 parent 4ff6aa2 commit f3a1513
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 56 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ cache:
services:
- postgresql
before_script:
- psql -c 'create database frameworkeventstore;' -U postgres
- psql -c 'create database frameworkviewstore;' -U postgres
- psql -c 'create database frameworkfilestore;' -U postgres
- psql -c 'create database frameworksystem;' -U postgres
- psql -c "CREATE USER framework WITH PASSWORD 'framework';" -U postgres
- psql -c 'create database frameworkeventstore;' -U postgres
- psql -c 'create database frameworkviewstore;' -U postgres
- psql -c 'create database frameworkfilestore;' -U postgres
- psql -c 'create database frameworksystem;' -U postgres
- psql -c 'create database fileservice;' -U postgres
- psql -c "CREATE USER framework WITH PASSWORD 'framework';" -U postgres
- psql -c "CREATE USER fileservice WITH PASSWORD 'fileservice';" -U postgres
addons:
postgresql: '9.5'
sonarcloud:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
[Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- Added a test DataSource for the file-service database
- Added indexes to processed_event table

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

import org.postgresql.ds.PGSimpleDataSource;

/**
* @deprecated Moved to test-utils-framework-persistence in the framework
*/
@Deprecated
public class TestJdbcDataSourceProvider {

private static final int PORT = 5432;
Expand All @@ -31,6 +35,10 @@ public DataSource getSystemDataSource(final String contextName) {
return getDataSource(contextName, databaseName);
}

public DataSource getFileServiceDataSource() {
return getDataSource("fileservice", "fileservice");
}

public DataSource getFileStoreDataSource(final String contextName) {

final String databaseName = contextName + "filestore";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,81 +14,55 @@

public class TestJdbcDataSourceProviderTest {

private final TestJdbcDataSourceProvider testJdbcDataSourceProvider = new TestJdbcDataSourceProvider();
private TestJdbcDataSourceProvider testJdbcDataSourceProvider = new TestJdbcDataSourceProvider();

@Test
public void shouldGetDataSourceToTheEventStoreDatabase() throws Exception {
public void shouldGetADataSourceToTheViewStore() throws Exception {

final String query = "SELECT current_database();";
final DataSource dataSource = testJdbcDataSourceProvider.getViewStoreDataSource("framework");

final DataSource eventStoreDataSource = testJdbcDataSourceProvider.getEventStoreDataSource("framework");

try (final Connection connection = eventStoreDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(query);
final ResultSet resultSet = preparedStatement.executeQuery()) {

if (resultSet.next()) {
assertThat(resultSet.getString(1), is("frameworkeventstore"));
} else {
fail();
}
try(final Connection connection = dataSource.getConnection()) {
assertThat(connection.isClosed(), is(false));
}
}

@Test
public void shouldGetDataSourceToTheViewStoreDatabase() throws Exception {

final String query = "SELECT current_database();";
public void shouldGetADataSourceToTheEventStore() throws Exception {

final DataSource eventStoreDataSource = testJdbcDataSourceProvider.getViewStoreDataSource("framework");
final DataSource dataSource = testJdbcDataSourceProvider.getEventStoreDataSource("framework");

try (final Connection connection = eventStoreDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(query);
final ResultSet resultSet = preparedStatement.executeQuery()) {

if (resultSet.next()) {
assertThat(resultSet.getString(1), is("frameworkviewstore"));
} else {
fail();
}
try(final Connection connection = dataSource.getConnection()) {
assertThat(connection.isClosed(), is(false));
}
}

@Test
public void shouldGetDataSourceToTheSystemDatabase() throws Exception {

final String query = "SELECT current_database();";
public void shouldGetADataSourceToSystem() throws Exception {

final DataSource eventStoreDataSource = testJdbcDataSourceProvider.getSystemDataSource("framework");
final DataSource dataSource = testJdbcDataSourceProvider.getSystemDataSource("framework");

try (final Connection connection = eventStoreDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(query);
final ResultSet resultSet = preparedStatement.executeQuery()) {

if (resultSet.next()) {
assertThat(resultSet.getString(1), is("frameworksystem"));
} else {
fail();
}
try(final Connection connection = dataSource.getConnection()) {
assertThat(connection.isClosed(), is(false));
}
}

@Test
public void shouldGetDataSourceToTheFileStoreDatabase() throws Exception {
public void shouldGetADataSourceToFileStore() throws Exception {

final String query = "SELECT current_database();";
final DataSource dataSource = testJdbcDataSourceProvider.getFileStoreDataSource("framework");

final DataSource eventStoreDataSource = testJdbcDataSourceProvider.getFileStoreDataSource("framework");
try(final Connection connection = dataSource.getConnection()) {
assertThat(connection.isClosed(), is(false));
}
}

@Test
public void shouldGetDataSourceToFileService() throws Exception {

try (final Connection connection = eventStoreDataSource.getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(query);
final ResultSet resultSet = preparedStatement.executeQuery()) {
final DataSource dataSource = testJdbcDataSourceProvider.getFileServiceDataSource();

if (resultSet.next()) {
assertThat(resultSet.getString(1), is("frameworkfilestore"));
} else {
fail();
}
try(final Connection connection = dataSource.getConnection()) {
assertThat(connection.isClosed(), is(false));
}
}
}

0 comments on commit f3a1513

Please sign in to comment.