Search in sources :

Example 1 with RefundAvailabilityUpdated

use of uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated 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) 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 RefundAvailabilityUpdated

use of uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated 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) 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 3 with RefundAvailabilityUpdated

use of uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated 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)

Example 4 with RefundAvailabilityUpdated

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

the class EventFactoryTest method shouldCreateCorrectEventsFromRefundErrorStateTransition.

@Test
public void shouldCreateCorrectEventsFromRefundErrorStateTransition() throws Exception {
    when(chargeService.findCharge(charge.getExternalId())).thenReturn(Optional.of(Charge.from(charge)));
    RefundHistory refundErrorHistory = RefundHistoryEntityFixture.aValidRefundHistoryEntity().withStatus(RefundStatus.REFUND_ERROR.getValue()).withUserExternalId("user_external_id").withChargeExternalId(charge.getExternalId()).withGatewayTransactionId(randomAlphanumeric(30)).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));
    RefundError refundError = (RefundError) refundEvents.stream().filter(e -> ResourceType.REFUND.equals(e.getResourceType())).findFirst().get();
    assertThat(refundError.getParentResourceExternalId(), is(charge.getExternalId()));
    assertThat(((RefundEventWithGatewayTransactionIdDetails) refundError.getEventDetails()).getGatewayTransactionId(), is(refundErrorHistory.getGatewayTransactionId()));
    assertThat(refundError.getResourceType(), is(ResourceType.REFUND));
    assertThat(refundError.getEventDetails(), is(instanceOf(RefundEventWithGatewayTransactionIdDetails.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) 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) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 5 with RefundAvailabilityUpdated

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

the class EventFactoryTest method shouldCreatePaymentCreatedEventWithCorrectPayloadForPaymentCreatedStateTransition.

@Test
public void shouldCreatePaymentCreatedEventWithCorrectPayloadForPaymentCreatedStateTransition() 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, PaymentCreated.class);
    List<Event> events = eventFactory.createEvents(paymentStateTransition);
    assertThat(events.size(), is(2));
    PaymentCreated event = (PaymentCreated) events.get(0);
    assertThat(event, instanceOf(PaymentCreated.class));
    assertThat(event.getEventDetails(), instanceOf(PaymentCreatedEventDetails.class));
    assertThat(event.getResourceExternalId(), Is.is(chargeEventEntity.getChargeEntity().getExternalId()));
    RefundAvailabilityUpdated event2 = (RefundAvailabilityUpdated) events.get(1);
    assertThat(event2, instanceOf(RefundAvailabilityUpdated.class));
    assertThat(event2.getEventDetails(), instanceOf(RefundAvailabilityUpdatedEventDetails.class));
}
Also used : PaymentCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentCreatedEventDetails) 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) PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)5 RefundAvailabilityUpdatedEventDetails (uk.gov.pay.connector.events.eventdetails.charge.RefundAvailabilityUpdatedEventDetails)5 Event (uk.gov.pay.connector.events.model.Event)5 RefundAvailabilityUpdated (uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated)5 PaymentStateTransition (uk.gov.pay.connector.queue.statetransition.PaymentStateTransition)5 Parameters (junitparams.Parameters)4 PaymentCreatedEventDetails (uk.gov.pay.connector.events.eventdetails.charge.PaymentCreatedEventDetails)4 Instant (java.time.Instant)3 List (java.util.List)3 Optional (java.util.Optional)3 JUnitParamsRunner (junitparams.JUnitParamsRunner)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 RunWith (org.junit.runner.RunWith)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3