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);
}
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);
}
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);
}
}
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();
}
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");
}
}
Aggregations