Search in sources :

Example 1 with StateTransition

use of uk.gov.pay.connector.queue.statetransition.StateTransition in project pay-connector by alphagov.

the class EventFactoryTest method shouldCreateCorrectEventsFromRefundCreatedStateTransition.

@Test
public void shouldCreateCorrectEventsFromRefundCreatedStateTransition() throws Exception {
    when(chargeService.findCharge(charge.getExternalId())).thenReturn(Optional.of(Charge.from(charge)));
    RefundHistory refundCreatedHistory = RefundHistoryEntityFixture.aValidRefundHistoryEntity().withStatus(RefundStatus.CREATED.getValue()).withUserExternalId("user_external_id").withUserEmail("test@example.com").withChargeExternalId(charge.getExternalId()).withAmount(charge.getAmount()).build();
    when(refundDao.getRefundHistoryByRefundExternalIdAndRefundStatus(refundCreatedHistory.getExternalId(), refundCreatedHistory.getStatus())).thenReturn(Optional.of(refundCreatedHistory));
    StateTransition refundStateTransition = new RefundStateTransition(refundCreatedHistory.getExternalId(), refundCreatedHistory.getStatus(), RefundCreatedByUser.class);
    List<Event> refundEvents = eventFactory.createEvents(refundStateTransition);
    assertThat(refundEvents.size(), is(2));
    RefundCreatedByUser refundCreatedByUser = (RefundCreatedByUser) refundEvents.stream().filter(e -> ResourceType.REFUND.equals(e.getResourceType())).findFirst().get();
    RefundCreatedByUserEventDetails eventDetails = (RefundCreatedByUserEventDetails) refundCreatedByUser.getEventDetails();
    assertThat(refundCreatedByUser.getParentResourceExternalId(), is(charge.getExternalId()));
    assertThat(eventDetails.getRefundedBy(), is("user_external_id"));
    assertThat(eventDetails.getUserEmail(), is("test@example.com"));
    assertThat(refundCreatedByUser.getResourceType(), is(ResourceType.REFUND));
    assertThat(refundCreatedByUser.getEventDetails(), is(instanceOf(RefundCreatedByUserEventDetails.class)));
    RefundAvailabilityUpdated refundAvailabilityUpdated = (RefundAvailabilityUpdated) refundEvents.stream().filter(e -> ResourceType.PAYMENT.equals(e.getResourceType())).findFirst().get();
    assertThat(refundAvailabilityUpdated.getResourceExternalId(), is(charge.getExternalId()));
    assertThat(refundAvailabilityUpdated.getResourceType(), is(ResourceType.PAYMENT));
    assertThat(refundAvailabilityUpdated.getEventDetails(), is(instanceOf(RefundAvailabilityUpdatedEventDetails.class)));
}
Also used : RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) CoreMatchers.is(org.hamcrest.CoreMatchers.is) CaptureConfirmedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CaptureConfirmedEventDetails) PaymentNotificationCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentNotificationCreatedEventDetails) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) BackfillerRecreatedUserEmailCollected(uk.gov.pay.connector.events.model.charge.BackfillerRecreatedUserEmailCollected) GatewayRequires3dsAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayRequires3dsAuthorisation) Is(org.hamcrest.core.Is) PaymentExpired(uk.gov.pay.connector.events.model.charge.PaymentExpired) CancelledByUserEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CancelledByUserEventDetails) PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) SandboxPaymentProvider(uk.gov.pay.connector.gateway.sandbox.SandboxPaymentProvider) CaptureSubmitted(uk.gov.pay.connector.events.model.charge.CaptureSubmitted) PaymentProviders(uk.gov.pay.connector.gateway.PaymentProviders) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) JUnitParamsRunner(junitparams.JUnitParamsRunner) RefundEventWithGatewayTransactionIdDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundEventWithGatewayTransactionIdDetails) ChargeEntityFixture(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture) CancelledByExternalService(uk.gov.pay.connector.events.model.charge.CancelledByExternalService) CancelledByUser(uk.gov.pay.connector.events.model.charge.CancelledByUser) EventFactory(uk.gov.pay.connector.events.model.EventFactory) GatewayTimeoutDuringAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayTimeoutDuringAuthorisation) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) CaptureSubmittedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CaptureSubmittedEventDetails) CancelledByExpiration(uk.gov.pay.connector.events.model.charge.CancelledByExpiration) LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) AuthorisationErrorCheckedWithGatewayChargeWasMissing(uk.gov.pay.connector.events.model.charge.AuthorisationErrorCheckedWithGatewayChargeWasMissing) RefundStatus(uk.gov.pay.connector.refund.model.domain.RefundStatus) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) Instant(java.time.Instant) RefundHistoryEntityFixture(uk.gov.pay.connector.pact.RefundHistoryEntityFixture) List(java.util.List) CaptureConfirmed(uk.gov.pay.connector.events.model.charge.CaptureConfirmed) Auth3dsRequiredEntity(uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity) CancelByExternalServiceSubmitted(uk.gov.pay.connector.events.model.charge.CancelByExternalServiceSubmitted) StatusCorrectedToCapturedToMatchGatewayStatus(uk.gov.pay.connector.events.model.charge.StatusCorrectedToCapturedToMatchGatewayStatus) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric) CancelByExpirationFailed(uk.gov.pay.connector.events.model.charge.CancelByExpirationFailed) RefundService(uk.gov.pay.connector.refund.service.RefundService) Optional(java.util.Optional) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) Event(uk.gov.pay.connector.events.model.Event) ResourceType(uk.gov.pay.connector.events.model.ResourceType) CancelByExternalServiceFailed(uk.gov.pay.connector.events.model.charge.CancelByExternalServiceFailed) CancelByUserFailed(uk.gov.pay.connector.events.model.charge.CancelByUserFailed) UserEmailCollectedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.UserEmailCollectedEventDetails) Parameters(junitparams.Parameters) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PaymentInstrumentService(uk.gov.pay.connector.paymentinstrument.service.PaymentInstrumentService) RefundDao(uk.gov.pay.connector.refund.dao.RefundDao) GatewayRequires3dsAuthorisationEventDetails(uk.gov.pay.connector.events.eventdetails.charge.GatewayRequires3dsAuthorisationEventDetails) ChargeEventEntityFixture(uk.gov.pay.connector.pact.ChargeEventEntityFixture) CaptureErrored(uk.gov.pay.connector.events.model.charge.CaptureErrored) RunWith(org.junit.runner.RunWith) PaymentCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentCreatedEventDetails) AuthorisationCancelled(uk.gov.pay.connector.events.model.charge.AuthorisationCancelled) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) EmptyEventDetails(uk.gov.pay.connector.events.eventdetails.EmptyEventDetails) Charge(uk.gov.pay.connector.charge.model.domain.Charge) AuthorisationRejected(uk.gov.pay.connector.events.model.charge.AuthorisationRejected) CancelledWithGatewayAfterAuthorisationError(uk.gov.pay.connector.events.model.charge.CancelledWithGatewayAfterAuthorisationError) ChargeService(uk.gov.pay.connector.charge.service.ChargeService) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) CaptureAbandonedAfterTooManyRetries(uk.gov.pay.connector.events.model.charge.CaptureAbandonedAfterTooManyRetries) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ENTERING_CARD_DETAILS(uk.gov.pay.connector.charge.model.domain.ChargeStatus.ENTERING_CARD_DETAILS) Before(org.junit.Before) AuthorisationErrorCheckedWithGatewayChargeWasRejected(uk.gov.pay.connector.events.model.charge.AuthorisationErrorCheckedWithGatewayChargeWasRejected) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) GatewayErrorDuringAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayErrorDuringAuthorisation) RefundAvailabilityUpdatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.RefundAvailabilityUpdatedEventDetails) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) AUTHORISATION_3DS_REQUIRED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.AUTHORISATION_3DS_REQUIRED) Test(org.junit.Test) ChargeEventDao(uk.gov.pay.connector.chargeevent.dao.ChargeEventDao) Mockito.when(org.mockito.Mockito.when) PaymentNotificationCreated(uk.gov.pay.connector.events.model.charge.PaymentNotificationCreated) UnexpectedGatewayErrorDuringAuthorisation(uk.gov.pay.connector.events.model.charge.UnexpectedGatewayErrorDuringAuthorisation) RefundCreatedByUserEventDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundCreatedByUserEventDetails) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Event(uk.gov.pay.connector.events.model.Event) RefundCreatedByUserEventDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundCreatedByUserEventDetails) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 2 with StateTransition

use of uk.gov.pay.connector.queue.statetransition.StateTransition in project pay-connector by alphagov.

the class EventFactoryTest method shouldCreateCorrectEventsFromRefundSucceededStateTransition.

@Test
public void shouldCreateCorrectEventsFromRefundSucceededStateTransition() throws Exception {
    when(chargeService.findCharge(charge.getExternalId())).thenReturn(Optional.of(Charge.from(charge)));
    RefundHistory refundSucceededHistory = RefundHistoryEntityFixture.aValidRefundHistoryEntity().withStatus(RefundStatus.REFUNDED.getValue()).withUserExternalId("user_external_id").withChargeExternalId(charge.getExternalId()).withAmount(charge.getAmount()).build();
    when(refundDao.getRefundHistoryByRefundExternalIdAndRefundStatus(refundSucceededHistory.getExternalId(), refundSucceededHistory.getStatus())).thenReturn(Optional.of(refundSucceededHistory));
    StateTransition refundStateTransition = new RefundStateTransition(refundSucceededHistory.getExternalId(), refundSucceededHistory.getStatus(), RefundSucceeded.class);
    List<Event> refundEvents = eventFactory.createEvents(refundStateTransition);
    assertThat(refundEvents.size(), is(1));
    RefundSucceeded refundSucceeded = (RefundSucceeded) refundEvents.get(0);
    assertThat(refundSucceeded.getParentResourceExternalId(), is(charge.getExternalId()));
    assertThat(refundSucceeded.getResourceExternalId(), is(refundSucceededHistory.getExternalId()));
    assertThat(refundSucceeded.getResourceType(), is(ResourceType.REFUND));
    assertThat(refundSucceeded.getEventDetails(), is(instanceOf(RefundEventWithGatewayTransactionIdDetails.class)));
}
Also used : RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Event(uk.gov.pay.connector.events.model.Event) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 3 with StateTransition

use of uk.gov.pay.connector.queue.statetransition.StateTransition in project pay-connector by alphagov.

the class EventFactoryTest method shouldCreateCorrectEventsFromRefundSubmittedStateTransition.

@Test
public void shouldCreateCorrectEventsFromRefundSubmittedStateTransition() throws Exception {
    when(chargeService.findCharge(charge.getExternalId())).thenReturn(Optional.of(Charge.from(charge)));
    RefundHistory refundSubmittedHistory = RefundHistoryEntityFixture.aValidRefundHistoryEntity().withStatus(RefundStatus.REFUND_SUBMITTED.getValue()).withUserExternalId("user_external_id").withChargeExternalId(charge.getExternalId()).withAmount(charge.getAmount()).build();
    when(refundDao.getRefundHistoryByRefundExternalIdAndRefundStatus(refundSubmittedHistory.getExternalId(), refundSubmittedHistory.getStatus())).thenReturn(Optional.of(refundSubmittedHistory));
    StateTransition refundStateTransition = new RefundStateTransition(refundSubmittedHistory.getExternalId(), refundSubmittedHistory.getStatus(), RefundSubmitted.class);
    List<Event> refundEvents = eventFactory.createEvents(refundStateTransition);
    assertThat(refundEvents.size(), is(1));
    RefundSubmitted refundSubmitted = (RefundSubmitted) refundEvents.get(0);
    assertThat(refundSubmitted.getParentResourceExternalId(), is(charge.getExternalId()));
    assertThat(refundSubmitted.getResourceExternalId(), is(refundSubmittedHistory.getExternalId()));
    assertThat(refundSubmitted.getResourceType(), is(ResourceType.REFUND));
    assertThat(refundSubmitted.getEventDetails(), is(instanceOf(RefundEventWithGatewayTransactionIdDetails.class)));
}
Also used : RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Event(uk.gov.pay.connector.events.model.Event) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 4 with StateTransition

use of uk.gov.pay.connector.queue.statetransition.StateTransition in project pay-connector by alphagov.

the class EventFactoryTest method shouldCreatedARefundAvailabilityUpdatedEvent_ifPaymentIsHistoric.

@Test
public void shouldCreatedARefundAvailabilityUpdatedEvent_ifPaymentIsHistoric() throws Exception {
    ChargeResponse.RefundSummary refundSummary = new ChargeResponse.RefundSummary();
    refundSummary.setStatus("available");
    LedgerTransaction transaction = new LedgerTransaction();
    transaction.setTransactionId(charge.getExternalId());
    transaction.setPaymentProvider("sandbox");
    transaction.setRefundSummary(refundSummary);
    transaction.setAmount(charge.getAmount());
    transaction.setTotalAmount(charge.getAmount());
    transaction.setCreatedDate(Instant.now().toString());
    transaction.setGatewayAccountId(charge.getGatewayAccount().getId().toString());
    transaction.setServiceId(charge.getServiceId());
    transaction.setLive(charge.getGatewayAccount().isLive());
    when(chargeService.findCharge(transaction.getTransactionId())).thenReturn(Optional.of(Charge.from(transaction)));
    RefundHistory refundErrorHistory = RefundHistoryEntityFixture.aValidRefundHistoryEntity().withStatus(RefundStatus.REFUND_ERROR.getValue()).withUserExternalId("user_external_id").withChargeExternalId(charge.getExternalId()).withAmount(charge.getAmount()).build();
    when(refundDao.getRefundHistoryByRefundExternalIdAndRefundStatus(refundErrorHistory.getExternalId(), refundErrorHistory.getStatus())).thenReturn(Optional.of(refundErrorHistory));
    StateTransition refundStateTransition = new RefundStateTransition(refundErrorHistory.getExternalId(), refundErrorHistory.getStatus(), RefundError.class);
    List<Event> refundEvents = eventFactory.createEvents(refundStateTransition);
    assertThat(refundEvents.size(), is(2));
    RefundAvailabilityUpdated refundAvailabilityUpdated = (RefundAvailabilityUpdated) refundEvents.stream().filter(e -> ResourceType.PAYMENT.equals(e.getResourceType())).findFirst().get();
    assertThat(refundAvailabilityUpdated.getResourceExternalId(), is(transaction.getTransactionId()));
    assertThat(refundAvailabilityUpdated.getResourceType(), is(ResourceType.PAYMENT));
    assertThat(refundAvailabilityUpdated.getEventDetails(), is(instanceOf(RefundAvailabilityUpdatedEventDetails.class)));
}
Also used : RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) CoreMatchers.is(org.hamcrest.CoreMatchers.is) CaptureConfirmedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CaptureConfirmedEventDetails) PaymentNotificationCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentNotificationCreatedEventDetails) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) BackfillerRecreatedUserEmailCollected(uk.gov.pay.connector.events.model.charge.BackfillerRecreatedUserEmailCollected) GatewayRequires3dsAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayRequires3dsAuthorisation) Is(org.hamcrest.core.Is) PaymentExpired(uk.gov.pay.connector.events.model.charge.PaymentExpired) CancelledByUserEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CancelledByUserEventDetails) PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) SandboxPaymentProvider(uk.gov.pay.connector.gateway.sandbox.SandboxPaymentProvider) CaptureSubmitted(uk.gov.pay.connector.events.model.charge.CaptureSubmitted) PaymentProviders(uk.gov.pay.connector.gateway.PaymentProviders) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) JUnitParamsRunner(junitparams.JUnitParamsRunner) RefundEventWithGatewayTransactionIdDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundEventWithGatewayTransactionIdDetails) ChargeEntityFixture(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture) CancelledByExternalService(uk.gov.pay.connector.events.model.charge.CancelledByExternalService) CancelledByUser(uk.gov.pay.connector.events.model.charge.CancelledByUser) EventFactory(uk.gov.pay.connector.events.model.EventFactory) GatewayTimeoutDuringAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayTimeoutDuringAuthorisation) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) CaptureSubmittedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CaptureSubmittedEventDetails) CancelledByExpiration(uk.gov.pay.connector.events.model.charge.CancelledByExpiration) LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) AuthorisationErrorCheckedWithGatewayChargeWasMissing(uk.gov.pay.connector.events.model.charge.AuthorisationErrorCheckedWithGatewayChargeWasMissing) RefundStatus(uk.gov.pay.connector.refund.model.domain.RefundStatus) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) Instant(java.time.Instant) RefundHistoryEntityFixture(uk.gov.pay.connector.pact.RefundHistoryEntityFixture) List(java.util.List) CaptureConfirmed(uk.gov.pay.connector.events.model.charge.CaptureConfirmed) Auth3dsRequiredEntity(uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity) CancelByExternalServiceSubmitted(uk.gov.pay.connector.events.model.charge.CancelByExternalServiceSubmitted) StatusCorrectedToCapturedToMatchGatewayStatus(uk.gov.pay.connector.events.model.charge.StatusCorrectedToCapturedToMatchGatewayStatus) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric) CancelByExpirationFailed(uk.gov.pay.connector.events.model.charge.CancelByExpirationFailed) RefundService(uk.gov.pay.connector.refund.service.RefundService) Optional(java.util.Optional) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) Event(uk.gov.pay.connector.events.model.Event) ResourceType(uk.gov.pay.connector.events.model.ResourceType) CancelByExternalServiceFailed(uk.gov.pay.connector.events.model.charge.CancelByExternalServiceFailed) CancelByUserFailed(uk.gov.pay.connector.events.model.charge.CancelByUserFailed) UserEmailCollectedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.UserEmailCollectedEventDetails) Parameters(junitparams.Parameters) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PaymentInstrumentService(uk.gov.pay.connector.paymentinstrument.service.PaymentInstrumentService) RefundDao(uk.gov.pay.connector.refund.dao.RefundDao) GatewayRequires3dsAuthorisationEventDetails(uk.gov.pay.connector.events.eventdetails.charge.GatewayRequires3dsAuthorisationEventDetails) ChargeEventEntityFixture(uk.gov.pay.connector.pact.ChargeEventEntityFixture) CaptureErrored(uk.gov.pay.connector.events.model.charge.CaptureErrored) RunWith(org.junit.runner.RunWith) PaymentCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentCreatedEventDetails) AuthorisationCancelled(uk.gov.pay.connector.events.model.charge.AuthorisationCancelled) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) EmptyEventDetails(uk.gov.pay.connector.events.eventdetails.EmptyEventDetails) Charge(uk.gov.pay.connector.charge.model.domain.Charge) AuthorisationRejected(uk.gov.pay.connector.events.model.charge.AuthorisationRejected) CancelledWithGatewayAfterAuthorisationError(uk.gov.pay.connector.events.model.charge.CancelledWithGatewayAfterAuthorisationError) ChargeService(uk.gov.pay.connector.charge.service.ChargeService) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) CaptureAbandonedAfterTooManyRetries(uk.gov.pay.connector.events.model.charge.CaptureAbandonedAfterTooManyRetries) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ENTERING_CARD_DETAILS(uk.gov.pay.connector.charge.model.domain.ChargeStatus.ENTERING_CARD_DETAILS) Before(org.junit.Before) AuthorisationErrorCheckedWithGatewayChargeWasRejected(uk.gov.pay.connector.events.model.charge.AuthorisationErrorCheckedWithGatewayChargeWasRejected) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) GatewayErrorDuringAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayErrorDuringAuthorisation) RefundAvailabilityUpdatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.RefundAvailabilityUpdatedEventDetails) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) AUTHORISATION_3DS_REQUIRED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.AUTHORISATION_3DS_REQUIRED) Test(org.junit.Test) ChargeEventDao(uk.gov.pay.connector.chargeevent.dao.ChargeEventDao) Mockito.when(org.mockito.Mockito.when) PaymentNotificationCreated(uk.gov.pay.connector.events.model.charge.PaymentNotificationCreated) UnexpectedGatewayErrorDuringAuthorisation(uk.gov.pay.connector.events.model.charge.UnexpectedGatewayErrorDuringAuthorisation) RefundCreatedByUserEventDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundCreatedByUserEventDetails) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Event(uk.gov.pay.connector.events.model.Event) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 5 with StateTransition

use of uk.gov.pay.connector.queue.statetransition.StateTransition in project pay-connector by alphagov.

the class HistoricalEventEmitterServiceTest method executeShouldOfferRefundEventsWithRefundHistory.

@Test
public void executeShouldOfferRefundEventsWithRefundHistory() {
    RefundHistory refundHistory = RefundHistoryEntityFixture.aValidRefundHistoryEntity().withChargeExternalId(chargeEntity.getExternalId()).withStatus(RefundStatus.CREATED.toString()).build();
    chargeEntity.getEvents().clear();
    when(refundDao.searchAllHistoryByChargeExternalId(chargeEntity.getExternalId())).thenReturn(List.of(refundHistory));
    when(chargeDao.findMaxId()).thenReturn(1L);
    when(chargeDao.findById(1L)).thenReturn(Optional.of(chargeEntity));
    when(chargeService.findCharge(chargeEntity.getExternalId())).thenReturn(Optional.of(Charge.from(chargeEntity)));
    historicalEventEmitterService.emitHistoricEventsById(1L, OptionalLong.empty(), 1L);
    ArgumentCaptor<StateTransition> argument = ArgumentCaptor.forClass(StateTransition.class);
    verify(stateTransitionService).offerStateTransition(argument.capture(), any(RefundCreatedByService.class), isNotNull());
    assertThat(argument.getAllValues().get(0).getStateTransitionEventClass(), is(RefundCreatedByService.class));
    verify(emittedEventDao, atMostOnce()).recordEmission(any(), isNotNull());
}
Also used : StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) RefundCreatedByService(uk.gov.pay.connector.events.model.refund.RefundCreatedByService) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 StateTransition (uk.gov.pay.connector.queue.statetransition.StateTransition)13 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)8 Event (uk.gov.pay.connector.events.model.Event)8 RefundHistory (uk.gov.pay.connector.refund.model.domain.RefundHistory)7 PaymentCreated (uk.gov.pay.connector.events.model.charge.PaymentCreated)5 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)4 PaymentStateTransition (uk.gov.pay.connector.queue.statetransition.PaymentStateTransition)4 RefundStateTransition (uk.gov.pay.connector.queue.statetransition.RefundStateTransition)4 Instant (java.time.Instant)3 List (java.util.List)3 Optional (java.util.Optional)3 JUnitParamsRunner (junitparams.JUnitParamsRunner)3 Parameters (junitparams.Parameters)3 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Is (org.hamcrest.core.Is)3 IsInstanceOf.instanceOf (org.hamcrest.core.IsInstanceOf.instanceOf)3 Before (org.junit.Before)3