use of uk.gov.pay.connector.queue.statetransition.PaymentStateTransition in project pay-connector by alphagov.
the class StateTransitionQueueTest method shouldNotReturnElementBeforeDelay.
@Test
public void shouldNotReturnElementBeforeDelay() throws InterruptedException {
StateTransitionQueue queue = new StateTransitionQueue();
PaymentStateTransition transition = new PaymentStateTransition(1L, PaymentEvent.class);
queue.offer(transition);
PaymentStateTransition readTransition = (PaymentStateTransition) queue.poll();
assertNull(readTransition);
}
use of uk.gov.pay.connector.queue.statetransition.PaymentStateTransition in project pay-connector by alphagov.
the class StateTransitionServiceTest method shouldOfferPaymentStateTransitionMessageForAValidStateTransitionIntoNonLockingState.
@Test
public void shouldOfferPaymentStateTransitionMessageForAValidStateTransitionIntoNonLockingState() {
ChargeEventEntity chargeEvent = aValidChargeEventEntity().withId(100L).build();
stateTransitionService.offerPaymentStateTransition("external-id", ChargeStatus.CREATED, ENTERING_CARD_DETAILS, chargeEvent);
ArgumentCaptor<PaymentStateTransition> paymentStateTransitionArgumentCaptor = ArgumentCaptor.forClass(PaymentStateTransition.class);
verify(mockStateTransitionQueue).offer(paymentStateTransitionArgumentCaptor.capture());
assertThat(paymentStateTransitionArgumentCaptor.getValue().getChargeEventId(), is(100L));
assertThat(paymentStateTransitionArgumentCaptor.getValue().getStateTransitionEventClass(), is(PaymentStarted.class));
verify(mockEventService).recordOfferedEvent(PAYMENT, "external-id", "PAYMENT_STARTED", chargeEvent.getUpdated());
}
use of uk.gov.pay.connector.queue.statetransition.PaymentStateTransition in project pay-connector by alphagov.
the class EventFactoryTest method shouldCreatedCorrectEventForPaymentNotificationCreated.
@Test
public void shouldCreatedCorrectEventForPaymentNotificationCreated() throws Exception {
ChargeEntity charge = ChargeEntityFixture.aValidChargeEntity().withStatus(ChargeStatus.PAYMENT_NOTIFICATION_CREATED).build();
Long chargeEventEntityId = 100L;
ChargeEventEntity chargeEventEntity = ChargeEventEntityFixture.aValidChargeEventEntity().withCharge(charge).withId(chargeEventEntityId).build();
when(chargeEventDao.findById(ChargeEventEntity.class, chargeEventEntityId)).thenReturn(Optional.of(chargeEventEntity));
PaymentStateTransition paymentStateTransition = new PaymentStateTransition(chargeEventEntityId, PaymentNotificationCreated.class);
List<Event> events = eventFactory.createEvents(paymentStateTransition);
assertThat(events.size(), is(1));
PaymentNotificationCreated event = (PaymentNotificationCreated) events.get(0);
assertThat(event, is(instanceOf(PaymentNotificationCreated.class)));
assertThat(event.getEventDetails(), instanceOf(PaymentNotificationCreatedEventDetails.class));
assertThat(event.getResourceExternalId(), is(chargeEventEntity.getChargeEntity().getExternalId()));
PaymentNotificationCreatedEventDetails eventDetails = (PaymentNotificationCreatedEventDetails) event.getEventDetails();
assertThat(eventDetails.getGatewayTransactionId(), is(charge.getGatewayTransactionId()));
}
use of uk.gov.pay.connector.queue.statetransition.PaymentStateTransition in project pay-connector by alphagov.
the class EventFactoryTest method shouldCreatedCorrectEventForBackfillRecreatedUserEmailCollectedEvent.
@Test
public void shouldCreatedCorrectEventForBackfillRecreatedUserEmailCollectedEvent() throws Exception {
ChargeEntity charge = ChargeEntityFixture.aValidChargeEntity().withStatus(ChargeStatus.USER_CANCELLED).withEmail("test@example.org").build();
Long chargeEventEntityId = 100L;
ChargeEventEntity chargeEventEntity = ChargeEventEntityFixture.aValidChargeEventEntity().withCharge(charge).withChargeStatus(ENTERING_CARD_DETAILS).withId(chargeEventEntityId).build();
charge.getEvents().add(chargeEventEntity);
when(chargeEventDao.findById(ChargeEventEntity.class, chargeEventEntityId)).thenReturn(Optional.of(chargeEventEntity));
PaymentStateTransition paymentStateTransition = new PaymentStateTransition(chargeEventEntityId, BackfillerRecreatedUserEmailCollected.class);
List<Event> events = eventFactory.createEvents(paymentStateTransition);
assertThat(events.size(), is(1));
BackfillerRecreatedUserEmailCollected event = (BackfillerRecreatedUserEmailCollected) events.get(0);
assertThat(event, is(instanceOf(BackfillerRecreatedUserEmailCollected.class)));
assertThat(event.getEventDetails(), instanceOf(UserEmailCollectedEventDetails.class));
assertThat(event.getResourceExternalId(), is(chargeEventEntity.getChargeEntity().getExternalId()));
UserEmailCollectedEventDetails eventDetails = (UserEmailCollectedEventDetails) event.getEventDetails();
assertThat(eventDetails.getEmail(), is(charge.getEmail()));
}
use of uk.gov.pay.connector.queue.statetransition.PaymentStateTransition in project pay-connector by alphagov.
the class EventFactoryTest method shouldCreatedRefundAvailabilityUpdatedEventForTerminalAndOtherStatesAffectingRefundability.
@Test
@Parameters(method = "statesAffectingRefundability")
public void shouldCreatedRefundAvailabilityUpdatedEventForTerminalAndOtherStatesAffectingRefundability(Class eventClass, Class eventDetailsClass) throws Exception {
Long chargeEventEntityId = 100L;
ChargeEventEntity chargeEventEntity = ChargeEventEntityFixture.aValidChargeEventEntity().withCharge(charge).withId(chargeEventEntityId).build();
when(chargeEventDao.findById(ChargeEventEntity.class, chargeEventEntityId)).thenReturn(Optional.of(chargeEventEntity));
PaymentStateTransition paymentStateTransition = new PaymentStateTransition(chargeEventEntityId, eventClass);
List<Event> events = eventFactory.createEvents(paymentStateTransition);
assertThat(events.size(), is(2));
Event event1 = events.get(0);
assertThat(event1, instanceOf(eventClass));
assertThat(event1.getEventDetails(), instanceOf(eventDetailsClass));
RefundAvailabilityUpdated event2 = (RefundAvailabilityUpdated) events.get(1);
assertThat(event2, instanceOf(RefundAvailabilityUpdated.class));
assertThat(event2.getEventDetails(), instanceOf(RefundAvailabilityUpdatedEventDetails.class));
}
Aggregations