Search in sources :

Example 1 with PaymentStateTransition

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);
}
Also used : PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) StateTransitionQueue(uk.gov.pay.connector.queue.statetransition.StateTransitionQueue) Test(org.junit.Test)

Example 2 with PaymentStateTransition

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());
}
Also used : PaymentStarted(uk.gov.pay.connector.events.model.charge.PaymentStarted) ChargeEventEntityFixture.aValidChargeEventEntity(uk.gov.pay.connector.pact.ChargeEventEntityFixture.aValidChargeEventEntity) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Test(org.junit.Test)

Example 3 with PaymentStateTransition

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()));
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) Event(uk.gov.pay.connector.events.model.Event) PaymentNotificationCreated(uk.gov.pay.connector.events.model.charge.PaymentNotificationCreated) PaymentNotificationCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentNotificationCreatedEventDetails) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Test(org.junit.Test)

Example 4 with PaymentStateTransition

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()));
}
Also used : ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) BackfillerRecreatedUserEmailCollected(uk.gov.pay.connector.events.model.charge.BackfillerRecreatedUserEmailCollected) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) UserEmailCollectedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.UserEmailCollectedEventDetails) Event(uk.gov.pay.connector.events.model.Event) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Test(org.junit.Test)

Example 5 with PaymentStateTransition

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));
}
Also used : ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) Event(uk.gov.pay.connector.events.model.Event) RefundAvailabilityUpdatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.RefundAvailabilityUpdatedEventDetails) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

PaymentStateTransition (uk.gov.pay.connector.queue.statetransition.PaymentStateTransition)14 Test (org.junit.Test)13 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)8 Event (uk.gov.pay.connector.events.model.Event)6 TimeUnit (java.util.concurrent.TimeUnit)3 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)3 PaymentCreatedEventDetails (uk.gov.pay.connector.events.eventdetails.charge.PaymentCreatedEventDetails)3 PaymentCreated (uk.gov.pay.connector.events.model.charge.PaymentCreated)3 StateTransitionQueue (uk.gov.pay.connector.queue.statetransition.StateTransitionQueue)3 RefundAvailabilityUpdatedEventDetails (uk.gov.pay.connector.events.eventdetails.charge.RefundAvailabilityUpdatedEventDetails)2 RefundAvailabilityUpdated (uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated)2 Parameters (junitparams.Parameters)1 Auth3dsRequiredEntity (uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity)1 EmptyEventDetails (uk.gov.pay.connector.events.eventdetails.EmptyEventDetails)1 GatewayRequires3dsAuthorisationEventDetails (uk.gov.pay.connector.events.eventdetails.charge.GatewayRequires3dsAuthorisationEventDetails)1 PaymentNotificationCreatedEventDetails (uk.gov.pay.connector.events.eventdetails.charge.PaymentNotificationCreatedEventDetails)1 UserEmailCollectedEventDetails (uk.gov.pay.connector.events.eventdetails.charge.UserEmailCollectedEventDetails)1 BackfillerRecreatedUserEmailCollected (uk.gov.pay.connector.events.model.charge.BackfillerRecreatedUserEmailCollected)1 CancelByExternalServiceSubmitted (uk.gov.pay.connector.events.model.charge.CancelByExternalServiceSubmitted)1 GatewayRequires3dsAuthorisation (uk.gov.pay.connector.events.model.charge.GatewayRequires3dsAuthorisation)1