Search in sources :

Example 6 with CurrencyConverterException

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");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) FrequencyService(com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService) StandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.status.StandingOrderStatus) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) BDDMockito.given(org.mockito.BDDMockito.given) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) MoneyService(com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) InjectMocks(org.mockito.InjectMocks) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) FRStandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData.FRStandingOrderStatus) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) StandingOrderService(com.forgerock.openbanking.common.services.store.account.standingorder.StandingOrderService) Optional(java.util.Optional) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData) PaymentNotificationFacade(com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) Test(org.junit.Test)

Example 7 with CurrencyConverterException

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)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) FrequencyService(com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService) StandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.status.StandingOrderStatus) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) BDDMockito.given(org.mockito.BDDMockito.given) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) MoneyService(com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) InjectMocks(org.mockito.InjectMocks) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) FRStandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData.FRStandingOrderStatus) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) StandingOrderService(com.forgerock.openbanking.common.services.store.account.standingorder.StandingOrderService) Optional(java.util.Optional) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData) PaymentNotificationFacade(com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) Test(org.junit.Test)

Example 8 with CurrencyConverterException

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");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) FrequencyService(com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService) StandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.status.StandingOrderStatus) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) BDDMockito.given(org.mockito.BDDMockito.given) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) MoneyService(com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) InjectMocks(org.mockito.InjectMocks) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) FRStandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData.FRStandingOrderStatus) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) StandingOrderService(com.forgerock.openbanking.common.services.store.account.standingorder.StandingOrderService) Optional(java.util.Optional) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData) PaymentNotificationFacade(com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) Test(org.junit.Test)

Example 9 with CurrencyConverterException

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)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) FrequencyService(com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService) StandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.status.StandingOrderStatus) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) BDDMockito.given(org.mockito.BDDMockito.given) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) MoneyService(com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) InjectMocks(org.mockito.InjectMocks) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) FRStandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData.FRStandingOrderStatus) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) StandingOrderService(com.forgerock.openbanking.common.services.store.account.standingorder.StandingOrderService) Optional(java.util.Optional) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData) PaymentNotificationFacade(com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) Test(org.junit.Test)

Example 10 with CurrencyConverterException

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)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) FrequencyService(com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService) StandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.status.StandingOrderStatus) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) BDDMockito.given(org.mockito.BDDMockito.given) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) MoneyService(com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) InjectMocks(org.mockito.InjectMocks) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) FRStandingOrderStatus(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData.FRStandingOrderStatus) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) StandingOrderService(com.forgerock.openbanking.common.services.store.account.standingorder.StandingOrderService) Optional(java.util.Optional) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData) PaymentNotificationFacade(com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRStandingOrder(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRStandingOrder) Test(org.junit.Test)

Aggregations

CurrencyConverterException (com.tunyk.currencyconverter.api.CurrencyConverterException)28 MoneyService (com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService)22 PaymentNotificationFacade (com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade)22 FRCreditDebitIndicator (com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator)22 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)22 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)22 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)22 AccountStoreService (com.forgerock.openbanking.common.services.store.account.AccountStoreService)22 Collections (java.util.Collections)22 Optional (java.util.Optional)22 Test (org.junit.Test)22 RunWith (org.junit.runner.RunWith)22 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)22 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)22 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)22 BDDMockito.given (org.mockito.BDDMockito.given)22 InjectMocks (org.mockito.InjectMocks)22 Mock (org.mockito.Mock)22 Mockito.doThrow (org.mockito.Mockito.doThrow)22 Mockito.verify (org.mockito.Mockito.verify)22