Search in sources :

Example 1 with PaymentCreated

use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.

the class StateTransitionEmitterProcessTest method shouldPutPaymentTransitionBackOnQueueIfEventEmitFails.

@Test
public void shouldPutPaymentTransitionBackOnQueueIfEventEmitFails() throws Exception {
    PaymentStateTransition paymentStateTransition = new PaymentStateTransition(100L, PaymentEvent.class);
    ChargeEventEntity chargeEvent = mock(ChargeEventEntity.class);
    when(stateTransitionQueue.poll(anyLong(), any(TimeUnit.class))).thenReturn(paymentStateTransition);
    when(eventFactory.createEvents(any(PaymentStateTransition.class))).thenReturn(List.of(new PaymentCreated("service-id", true, "id", mock(PaymentCreatedEventDetails.class), ZonedDateTime.now())));
    doThrow(QueueException.class).when(mockEventService).emitAndMarkEventAsEmitted(any());
    stateTransitionEmitterProcess.handleStateTransitionMessages();
    verify(stateTransitionQueue).offer(any(PaymentStateTransition.class));
}
Also used : PaymentCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentCreatedEventDetails) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) TimeUnit(java.util.concurrent.TimeUnit) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) Test(org.junit.Test)

Example 2 with PaymentCreated

use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.

the class EmittedEventDaoIT method findNotEmittedEventsOlderThan_shouldReturnEventsWithEmptyEmittedDate.

@Test
public void findNotEmittedEventsOlderThan_shouldReturnEventsWithEmptyEmittedDate() {
    final PaymentCreated paymentCreatedEvent = aPaymentCreatedEvent();
    emittedEventDao.recordEmission(paymentCreatedEvent.getResourceType(), paymentCreatedEvent.getResourceExternalId(), paymentCreatedEvent.getEventType(), paymentCreatedEvent.getTimestamp(), null);
    Optional<Long> maxId = emittedEventDao.findNotEmittedEventMaxIdOlderThan(ZonedDateTime.parse("2019-01-01T14:00:01Z"), ZonedDateTime.now(UTC));
    assertThat(maxId.isPresent(), is(true));
    List<EmittedEventEntity> notEmittedEvents = emittedEventDao.findNotEmittedEventsOlderThan(ZonedDateTime.parse("2019-01-01T14:00:01Z"), 1, 0L, Long.MAX_VALUE, ZonedDateTime.now(UTC));
    assertThat(notEmittedEvents.size(), is(1));
    assertThat(notEmittedEvents.get(0).getEmittedDate(), nullValue());
    assertThat(notEmittedEvents.get(0).getEventType(), is(paymentCreatedEvent.getEventType()));
    assertThat(notEmittedEvents.get(0).getResourceExternalId(), is(paymentCreatedEvent.getResourceExternalId()));
    assertThat(notEmittedEvents.get(0).getResourceType(), is(paymentCreatedEvent.getResourceType().getLowercase()));
}
Also used : EmittedEventEntity(uk.gov.pay.connector.events.EmittedEventEntity) PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) Test(org.junit.Test)

Example 3 with PaymentCreated

use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.

the class EmittedEventDaoIT method hasBeenEmittedBefore_shouldReturnTrueIfRecordedBefore.

@Test
public void hasBeenEmittedBefore_shouldReturnTrueIfRecordedBefore() {
    final PaymentCreated paymentCreatedEvent = aPaymentCreatedEvent();
    emittedEventDao.recordEmission(paymentCreatedEvent, null);
    assertThat(emittedEventDao.hasBeenEmittedBefore(paymentCreatedEvent), is(true));
}
Also used : PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) Test(org.junit.Test)

Example 4 with PaymentCreated

use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.

the class EmittedEventDaoIT method recordEmissionWithParameters_shouldRecordEmission.

@Test
public void recordEmissionWithParameters_shouldRecordEmission() {
    final PaymentCreated eventToRecord = aPaymentCreatedEvent();
    ZonedDateTime doNotRetryEmitUntilDate = ZonedDateTime.parse("2019-01-02T13:00:00Z");
    emittedEventDao.recordEmission(eventToRecord.getResourceType(), eventToRecord.getResourceExternalId(), eventToRecord.getEventType(), eventToRecord.getTimestamp(), doNotRetryEmitUntilDate);
    final List<Map<String, Object>> events = databaseTestHelper.readEmittedEvents();
    assertThat(events.size(), is(1));
    final Map<String, Object> event = events.get(0);
    assertThat(event.get("resource_external_id"), is(eventToRecord.getResourceExternalId()));
    assertThat(event.get("resource_type"), is(eventToRecord.getResourceType().getLowercase()));
    assertThat(event.get("event_type"), is(eventToRecord.getEventType()));
    assertThat(event.get("emitted_date"), is(nullValue()));
    assertThat(event.get("do_not_retry_emit_until"), is(Timestamp.from(doNotRetryEmitUntilDate.toInstant())));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Map(java.util.Map) PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) Test(org.junit.Test)

Example 5 with PaymentCreated

use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.

the class EmittedEventDaoIT method findNotEmittedEventsOlderThan_shouldNotReturnRecordsWithDoNotRetryEmitUntilValueInFuture.

@Test
public void findNotEmittedEventsOlderThan_shouldNotReturnRecordsWithDoNotRetryEmitUntilValueInFuture() {
    final PaymentCreated paymentCreatedEvent = aPaymentCreatedEvent();
    final RefundSubmitted refundSubmittedEvent = aRefundSubmittedEvent(ZonedDateTime.parse("2019-01-01T14:00:00Z"));
    emittedEventDao.recordEmission(paymentCreatedEvent.getResourceType(), paymentCreatedEvent.getResourceExternalId(), paymentCreatedEvent.getEventType(), paymentCreatedEvent.getTimestamp(), null);
    ZonedDateTime doNotRetryEmitUntil = ZonedDateTime.now(UTC).minusSeconds(120);
    emittedEventDao.recordEmission(refundSubmittedEvent.getResourceType(), refundSubmittedEvent.getResourceExternalId(), refundSubmittedEvent.getEventType(), refundSubmittedEvent.getTimestamp(), doNotRetryEmitUntil);
    emittedEventDao.recordEmission(paymentCreatedEvent.getResourceType(), paymentCreatedEvent.getResourceExternalId(), paymentCreatedEvent.getEventType(), paymentCreatedEvent.getTimestamp(), ZonedDateTime.now(UTC).plusSeconds(120));
    Optional<Long> maxId = emittedEventDao.findNotEmittedEventMaxIdOlderThan(ZonedDateTime.parse("2019-01-01T14:00:01Z"), ZonedDateTime.now(UTC));
    assertThat(maxId.isPresent(), is(true));
    List<EmittedEventEntity> notEmittedEvents = emittedEventDao.findNotEmittedEventsOlderThan(ZonedDateTime.parse("2019-01-01T14:00:01Z"), 2, 0L, Long.MAX_VALUE, ZonedDateTime.now(UTC));
    assertThat(notEmittedEvents.size(), is(2));
    assertThat(notEmittedEvents.get(0).getEmittedDate(), nullValue());
    assertThat(notEmittedEvents.get(0).getEventType(), is(paymentCreatedEvent.getEventType()));
    assertThat(notEmittedEvents.get(0).getResourceExternalId(), is(paymentCreatedEvent.getResourceExternalId()));
    assertThat(notEmittedEvents.get(0).getResourceType(), is(paymentCreatedEvent.getResourceType().getLowercase()));
    assertThat(notEmittedEvents.get(0).getDoNotRetryEmitUntil(), is(nullValue()));
    assertThat(notEmittedEvents.get(1).getEmittedDate(), nullValue());
    assertThat(notEmittedEvents.get(1).getEventType(), is(refundSubmittedEvent.getEventType()));
    assertThat(notEmittedEvents.get(1).getResourceExternalId(), is(refundSubmittedEvent.getResourceExternalId()));
    assertThat(notEmittedEvents.get(1).getResourceType(), is(refundSubmittedEvent.getResourceType().getLowercase()));
    assertThat(Timestamp.from(notEmittedEvents.get(1).getDoNotRetryEmitUntil().toInstant()), is(Timestamp.from(doNotRetryEmitUntil.toInstant())));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) EmittedEventEntity(uk.gov.pay.connector.events.EmittedEventEntity) PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) RefundSubmitted(uk.gov.pay.connector.events.model.refund.RefundSubmitted) Test(org.junit.Test)

Aggregations

PaymentCreated (uk.gov.pay.connector.events.model.charge.PaymentCreated)11 Test (org.junit.Test)10 ZonedDateTime (java.time.ZonedDateTime)3 Map (java.util.Map)3 PaymentCreatedEventDetails (uk.gov.pay.connector.events.eventdetails.charge.PaymentCreatedEventDetails)3 PaymentStateTransition (uk.gov.pay.connector.queue.statetransition.PaymentStateTransition)3 TimeUnit (java.util.concurrent.TimeUnit)2 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)2 EmittedEventEntity (uk.gov.pay.connector.events.EmittedEventEntity)2 Event (uk.gov.pay.connector.events.model.Event)2 PactVerifyProvider (au.com.dius.pact.provider.PactVerifyProvider)1 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)1 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)1 RefundAvailabilityUpdatedEventDetails (uk.gov.pay.connector.events.eventdetails.charge.RefundAvailabilityUpdatedEventDetails)1 PaymentEvent (uk.gov.pay.connector.events.model.charge.PaymentEvent)1 RefundAvailabilityUpdated (uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated)1 RefundSubmitted (uk.gov.pay.connector.events.model.refund.RefundSubmitted)1 ExternalMetadata (uk.gov.service.payments.commons.model.charge.ExternalMetadata)1