Search in sources :

Example 1 with UtcClock

use of uk.gov.justice.services.common.util.UtcClock in project microservice_framework by CJSCommonPlatform.

the class EnveloperFactory method create.

public DefaultEnveloper create() {
    final ObjectMapper objectMapper = new ObjectMapperProducer().objectMapper();
    final ObjectToJsonValueConverter converter = new ObjectToJsonValueConverter(objectMapper);
    return new DefaultEnveloper(new UtcClock(), converter);
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) ObjectMapperProducer(uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer) ObjectToJsonValueConverter(uk.gov.justice.services.common.converter.ObjectToJsonValueConverter) DefaultEnveloper(uk.gov.justice.services.core.enveloper.DefaultEnveloper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with UtcClock

use of uk.gov.justice.services.common.util.UtcClock in project microservice_framework by CJSCommonPlatform.

the class EventConverterTest method shouldCreateEnvelope.

@Test
public void shouldCreateEnvelope() throws Exception {
    JsonEnvelope actualEnvelope = eventConverter.envelopeOf(new Event(ID, STREAM_ID, SEQUENCE_ID, NAME, METADATA_JSON, PAYLOAD_JSON, new UtcClock().now()));
    assertThat(actualEnvelope.metadata().id(), equalTo(ID));
    assertThat(actualEnvelope.metadata().name(), equalTo(NAME));
    String actualPayload = actualEnvelope.payloadAsJsonObject().toString();
    JSONAssert.assertEquals(PAYLOAD_JSON, actualPayload, false);
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 3 with UtcClock

use of uk.gov.justice.services.common.util.UtcClock in project microservice_framework by CJSCommonPlatform.

the class EventsPageIT method storeEvents.

private void storeEvents(final int eventNumber) throws InvalidPositionException {
    for (int i = 1; i <= eventNumber; i++) {
        final UUID id = randomUUID();
        final Metadata metadata = JsonEnvelope.metadataBuilder().withId(id).withStreamId(STREAM_ID).withName("name").createdAt(now()).withVersion(i).build();
        final Event event = new Event(randomUUID(), STREAM_ID, valueOf(i), "Test Name" + i, metadata.asJsonObject().toString(), createObjectBuilder().add("field" + i, "value" + i).build().toString(), new UtcClock().now());
        eventsRepository.insert(event);
    }
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) Metadata(uk.gov.justice.services.messaging.Metadata) Event(uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID)

Example 4 with UtcClock

use of uk.gov.justice.services.common.util.UtcClock in project microservice_framework by CJSCommonPlatform.

the class AnsiSQLEventInsertionStrategyTest method shouldExecutePreparedStatement.

@Test
public void shouldExecutePreparedStatement() throws Exception {
    final UUID id = UUID.randomUUID();
    final UUID streamId = UUID.randomUUID();
    final long sequenceId = 1L;
    final String name = "Name";
    final String metadata = "metadata";
    final String payload = "payload";
    final ZonedDateTime createdAt = new UtcClock().now();
    when(event.getId()).thenReturn(id);
    when(event.getStreamId()).thenReturn(streamId);
    when(event.getSequenceId()).thenReturn(sequenceId);
    when(event.getName()).thenReturn(name);
    when(event.getMetadata()).thenReturn(metadata);
    when(event.getPayload()).thenReturn(payload);
    when(event.getCreatedAt()).thenReturn(createdAt);
    strategy.insert(preparedStatement, event);
    verify(preparedStatement).setObject(1, id);
    verify(preparedStatement).setObject(2, streamId);
    verify(preparedStatement).setLong(3, sequenceId);
    verify(preparedStatement).setString(4, name);
    verify(preparedStatement).setString(5, metadata);
    verify(preparedStatement).setString(6, payload);
    verify(preparedStatement).setTimestamp(7, toSqlTimestamp(createdAt));
    verify(preparedStatement).executeUpdate();
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with UtcClock

use of uk.gov.justice.services.common.util.UtcClock 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)

Aggregations

UtcClock (uk.gov.justice.services.common.util.UtcClock)13 Test (org.junit.Test)10 UUID (java.util.UUID)9 UUID.randomUUID (java.util.UUID.randomUUID)8 URL (java.net.URL)6 ArrayList (java.util.ArrayList)6 ResteasyUriInfo (org.jboss.resteasy.spi.ResteasyUriInfo)6 EventEntry (uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry)6 Position (uk.gov.justice.services.eventsourcing.source.api.service.core.Position)4 JsonObject (javax.json.JsonObject)2 ObjectToJsonValueConverter (uk.gov.justice.services.common.converter.ObjectToJsonValueConverter)2 ObjectMapperProducer (uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer)2 DefaultEnveloper (uk.gov.justice.services.core.enveloper.DefaultEnveloper)2 Event (uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event)2 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)2 Metadata (uk.gov.justice.services.messaging.Metadata)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SQLException (java.sql.SQLException)1 ZonedDateTime (java.time.ZonedDateTime)1 Response (javax.ws.rs.core.Response)1