Search in sources :

Example 1 with JdbcRepositoryHelper

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper in project microservice_framework by CJSCommonPlatform.

the class StreamStatusJdbcRepositoryIT method initDatabase.

@Before
public void initDatabase() throws Exception {
    final TestDataSourceFactory testDataSourceFactory = new TestDataSourceFactory(LIQUIBASE_STREAM_STATUS_CHANGELOG_XML);
    final JdbcDataSource dataSource = testDataSourceFactory.createDataSource();
    jdbcRepository = new StreamStatusJdbcRepository(dataSource, new JdbcRepositoryHelper());
    try {
        final Poller poller = new Poller();
        poller.pollUntilFound(() -> {
            try {
                dataSource.getConnection().prepareStatement("SELECT COUNT (*) FROM stream_buffer;").execute();
                return Optional.of("Success");
            } catch (SQLException e) {
                e.printStackTrace();
                fail("EventJdbcRepository construction failed");
                return Optional.empty();
            }
        });
    } catch (final Exception e) {
        e.printStackTrace();
        fail("EventJdbcRepository construction failed");
    }
}
Also used : JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) SQLException(java.sql.SQLException) TestDataSourceFactory(uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Poller(uk.gov.justice.services.test.utils.core.messaging.Poller) SQLException(java.sql.SQLException) Before(org.junit.Before)

Example 2 with JdbcRepositoryHelper

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper in project microservice_framework by CJSCommonPlatform.

the class EventStreamJdbcRepositoryIT method initialize.

@Before
public void initialize() {
    try {
        jdbcRepository.dataSource = new TestDataSourceFactory(LIQUIBASE_EVENT_STORE_DB_CHANGELOG_XML).createDataSource();
        jdbcRepository.logger = mock(Logger.class);
        jdbcRepository.eventStreamJdbcRepositoryHelper = new JdbcRepositoryHelper();
        jdbcRepository.clock = new UtcClock();
        final Poller poller = new Poller();
        poller.pollUntilFound(() -> {
            try {
                jdbcRepository.dataSource.getConnection().prepareStatement("SELECT COUNT (*) FROM event_stream;").execute();
                return Optional.of("Success");
            } catch (SQLException e) {
                e.printStackTrace();
                return Optional.empty();
            }
        });
    } catch (final Exception e) {
        e.printStackTrace();
        Assert.fail("EventStreamJdbcRepository construction failed");
    }
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) SQLException(java.sql.SQLException) TestDataSourceFactory(uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory) Logger(org.slf4j.Logger) Poller(uk.gov.justice.services.test.utils.core.messaging.Poller) InvalidPositionException(uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException) SQLException(java.sql.SQLException) Before(org.junit.Before)

Example 3 with JdbcRepositoryHelper

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper in project microservice_framework by CJSCommonPlatform.

the class StreamStatusJdbcRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    when(dataSource.getConnection()).thenReturn(connection);
    when(connection.getMetaData()).thenReturn(dbMetadata);
    repository.jdbcRepositoryHelper = new JdbcRepositoryHelper();
}
Also used : JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) Before(org.junit.Before)

Example 4 with JdbcRepositoryHelper

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper in project microservice_framework by CJSCommonPlatform.

the class StreamBufferJdbcRepositoryIT method initDatabase.

@Before
public void initDatabase() throws Exception {
    final TestDataSourceFactory testDataSourceFactory = new TestDataSourceFactory(LIQUIBASE_STREAM_STATUS_CHANGELOG_XML);
    final JdbcDataSource dataSource = testDataSourceFactory.createDataSource();
    jdbcRepository = new StreamBufferJdbcRepository(dataSource, new JdbcRepositoryHelper());
    try {
        final Poller poller = new Poller();
        poller.pollUntilFound(() -> {
            try {
                dataSource.getConnection().prepareStatement("SELECT COUNT (*) FROM stream_buffer;").execute();
                return Optional.of("Success");
            } catch (SQLException e) {
                e.printStackTrace();
                fail("EventJdbcRepository construction failed");
                return Optional.empty();
            }
        });
    } catch (final Exception e) {
        e.printStackTrace();
        fail("EventJdbcRepository construction failed");
    }
}
Also used : JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) SQLException(java.sql.SQLException) TestDataSourceFactory(uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Poller(uk.gov.justice.services.test.utils.core.messaging.Poller) SQLException(java.sql.SQLException) Before(org.junit.Before)

Example 5 with JdbcRepositoryHelper

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper in project microservice_framework by CJSCommonPlatform.

the class StandaloneStreamStatusJdbcRepositoryFactory method getSnapshotStreamStatusJdbcRepository.

public static StreamStatusJdbcRepository getSnapshotStreamStatusJdbcRepository(final DataSource dataSource) {
    final StreamStatusJdbcRepository snapshotJdbcRepository = new StreamStatusJdbcRepository();
    snapshotJdbcRepository.dataSource = dataSource;
    snapshotJdbcRepository.jdbcRepositoryHelper = new JdbcRepositoryHelper();
    return snapshotJdbcRepository;
}
Also used : JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper)

Aggregations

JdbcRepositoryHelper (uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper)7 Before (org.junit.Before)5 SQLException (java.sql.SQLException)4 Poller (uk.gov.justice.services.test.utils.core.messaging.Poller)4 TestDataSourceFactory (uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory)4 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)2 Logger (org.slf4j.Logger)2 AnsiSQLEventLogInsertionStrategy (uk.gov.justice.services.eventsourcing.repository.jdbc.AnsiSQLEventLogInsertionStrategy)2 InvalidPositionException (uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException)2 UtcClock (uk.gov.justice.services.common.util.UtcClock)1 JdbcDataSourceProvider (uk.gov.justice.services.jdbc.persistence.JdbcDataSourceProvider)1 JdbcRepositoryException (uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)1