use of com.tunyk.currencyconverter.api.CurrencyConverterException in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticStandingOrderTaskTest method shouldRejectPaymentWhenAnyException.
@Test
public void shouldRejectPaymentWhenAnyException() throws CurrencyConverterException {
// Given
FRStandingOrder payment = defaultPayment(StandingOrderStatus.PENDING);
given(paymentsService.getActiveStandingOrders()).willReturn(Collections.singletonList(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
doThrow(new RuntimeException("Simulated failure")).when(moneyService).moveMoney(any(), any(), any(), any(), any());
// When
acceptDueStandingOrderTask.payDueStandingOrders();
// Then
verify(moneyService).moveMoney(eq(account), any(), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updateStandingOrder(argThat(p -> p.getStatus().equals(StandingOrderStatus.REJECTED)));
assertThat(payment.getRejectionReason()).isEqualTo("Failed to execute payment: Simulated failure");
}
use of com.tunyk.currencyconverter.api.CurrencyConverterException in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticStandingOrderTaskTest method pendingStandingOrder_firstPaymentDue_shouldCreditAccount.
@Test
public void pendingStandingOrder_firstPaymentDue_shouldCreditAccount() throws CurrencyConverterException {
// Given
FRStandingOrder payment = defaultPayment(StandingOrderStatus.PENDING);
given(paymentsService.getActiveStandingOrders()).willReturn(Collections.singletonList(payment));
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(defaultAccount(DEBIT_ACCOUNT));
FRAccount account = defaultAccount(CREDIT_ACCOUNT);
given(account2StoreService.findAccountByIdentification(CREDIT_ACCOUNT)).willReturn(Optional.of(account));
// When
acceptDueStandingOrderTask.payDueStandingOrders();
// Then
verify(moneyService).moveMoney(eq(account), any(), eq(FRCreditDebitIndicator.CREDIT), eq(payment), any());
verify(paymentsService).updateStandingOrder(argThat(p -> p.getStatus().equals(StandingOrderStatus.ACTIVE)));
}
use of com.tunyk.currencyconverter.api.CurrencyConverterException in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticStandingOrderTaskTest method shouldRejectPaymentWhenCurrencyConversionException.
@Test
public void shouldRejectPaymentWhenCurrencyConversionException() throws CurrencyConverterException {
// Given
FRStandingOrder payment = defaultPayment(StandingOrderStatus.PENDING);
given(paymentsService.getActiveStandingOrders()).willReturn(Collections.singletonList(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
doThrow(new CurrencyConverterException("Simulated failure")).when(moneyService).moveMoney(any(), any(), any(), any(), any());
// When
acceptDueStandingOrderTask.payDueStandingOrders();
// Then
verify(moneyService).moveMoney(eq(account), any(), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updateStandingOrder(argThat(p -> p.getStatus().equals(StandingOrderStatus.REJECTED)));
assertThat(payment.getRejectionReason()).isEqualTo("Can't convert amount in the right currency: Simulated failure");
}
use of com.tunyk.currencyconverter.api.CurrencyConverterException in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticStandingOrderTaskTest method pendingStandingOrder_firstPaymentDue_shouldDebitAccount.
@Test
public void pendingStandingOrder_firstPaymentDue_shouldDebitAccount() throws CurrencyConverterException {
// Given
FRStandingOrder payment = defaultPayment(StandingOrderStatus.PENDING);
given(paymentsService.getActiveStandingOrders()).willReturn(Collections.singletonList(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
// When
acceptDueStandingOrderTask.payDueStandingOrders();
// Then
verify(moneyService).moveMoney(eq(account), any(), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updateStandingOrder(argThat(p -> p.getStatus().equals(StandingOrderStatus.ACTIVE)));
}
use of com.tunyk.currencyconverter.api.CurrencyConverterException in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticStandingOrderTaskTest method pendingStandingOrder_recurringPaymentDue_shouldDebitAccount.
@Test
public void pendingStandingOrder_recurringPaymentDue_shouldDebitAccount() throws CurrencyConverterException {
// Given
FRStandingOrder payment = defaultPayment(StandingOrderStatus.ACTIVE);
given(paymentsService.getActiveStandingOrders()).willReturn(Collections.singletonList(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
given(frequencyService.getNextDateTime(any(), any())).willReturn(DateTime.now().minusDays(1));
// When
acceptDueStandingOrderTask.payDueStandingOrders();
// Then
verify(moneyService).moveMoney(eq(account), any(), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updateStandingOrder(argThat(p -> p.getStatus().equals(StandingOrderStatus.ACTIVE)));
}
Aggregations