Search in sources :

Example 31 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class Accounts2ApiControllerIT method testGetAnAccount.

@Test
public void testGetAnAccount() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_AISP);
    FRAccount account = JMockData.mock(FRAccount.class);
    frAccountRepository.save(account);
    // When
    HttpResponse<OBReadAccount2> response = Unirest.get("https://rs-store:" + port + "/open-banking/v2.0/accounts/" + account.getId()).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-url", "http://localhost").header("x-ob-permissions", OBExternalPermissions1Code.READACCOUNTSDETAIL.name() + "," + OBExternalPermissions1Code.READPAN.name()).asObject(OBReadAccount2.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody().getData().getAccount().get(0).getAccountId()).isEqualTo(account.getAccount().getAccountId());
    assertThat(response.getBody().getData().getAccount().get(0).getCurrency()).isEqualTo(account.getAccount().getCurrency());
    assertThat(response.getBody().getData().getAccount().get(0).getAccountType()).isEqualTo(toOBExternalAccountType1Code(account.getAccount().getAccountType()));
    assertThat(response.getBody().getData().getAccount().get(0).getAccount().get(0).getIdentification()).isEqualTo(account.getAccount().getAccounts().get(0).getIdentification());
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadAccount2(uk.org.openbanking.datamodel.account.OBReadAccount2) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 32 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class AccountsApiControllerIT method testGetAnAccount.

@Test
public void testGetAnAccount() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_AISP);
    FRAccount account = JMockData.mock(FRAccount.class);
    frAccountRepository.save(account);
    // When
    HttpResponse<OBReadAccount6> response = Unirest.get("https://rs-store:" + port + "/open-banking/v3.1.7/aisp/accounts/" + account.getId()).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-url", "http://localhost").header("x-ob-permissions", OBExternalPermissions1Code.READACCOUNTSDETAIL.name() + "," + OBExternalPermissions1Code.READPAN.name()).asObject(OBReadAccount6.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    OBAccount6 returnedAccount = response.getBody().getData().getAccount().get(0);
    assertThat(returnedAccount).isNotNull();
    assertThat(returnedAccount.getAccountId()).isEqualTo(account.getAccount().getAccountId());
    assertThat(returnedAccount.getCurrency()).isEqualTo(account.getAccount().getCurrency());
    assertThat(returnedAccount.getAccountType()).isEqualTo(toOBExternalAccountType1Code(account.getAccount().getAccountType()));
    assertThat(returnedAccount.getAccountSubType()).isEqualTo(toOBExternalAccountSubType1Code(account.getAccount().getAccountSubType()));
    assertThat(returnedAccount.getDescription()).isEqualTo(account.getAccount().getDescription());
    assertThat(returnedAccount.getNickname()).isEqualTo(account.getAccount().getNickname());
    assertThat(returnedAccount.getServicer().getSchemeName()).isEqualTo(account.getAccount().getServicer().getSchemeName());
    assertThat(returnedAccount.getServicer().getIdentification()).isEqualTo(account.getAccount().getServicer().getIdentification());
    assertThat(returnedAccount.getAccount().get(0).getIdentification()).isEqualTo(account.getAccount().getAccounts().get(0).getIdentification());
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadAccount6(uk.org.openbanking.datamodel.account.OBReadAccount6) OBAccount6(uk.org.openbanking.datamodel.account.OBAccount6) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class DataApiControllerIT method shouldReturnPayloadTooLargeWhenCreatingNewDataWithDataAlreadySaved.

@Test
public void shouldReturnPayloadTooLargeWhenCreatingNewDataWithDataAlreadySaved() throws Exception {
    // Given
    OBAccount6 account = new OBAccount6().accountId(UUID.randomUUID().toString());
    List<FRAccountData> accountDatas = Collections.singletonList(FRAccountData.builder().account(account).balances(Collections.singletonList(new OBCashBalance1().accountId(account.getAccountId()).type(OBBalanceType1Code.INTERIMAVAILABLE))).build());
    FRAccount savedAccount = frAccountRepository.save(FRAccount.builder().id(account.getAccountId()).userID(UUID.randomUUID().toString()).build());
    frBalanceRepository.save(FRBalance.builder().accountId(account.getAccountId()).build());
    FRUserData userData = new FRUserData();
    userData.setAccountDatas(accountDatas);
    userData.setUserName(savedAccount.getUserID());
    // When
    mockMvc.perform(post("/api/data/user").content(mapper.writeValueAsString(userData)).contentType("application/json")).andExpect(status().isPayloadTooLarge());
}
Also used : FRUserData(com.forgerock.openbanking.common.model.data.FRUserData) OBCashBalance1(uk.org.openbanking.datamodel.account.OBCashBalance1) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRAccountData(com.forgerock.openbanking.common.model.data.FRAccountData) OBAccount6(uk.org.openbanking.datamodel.account.OBAccount6) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class FRAccountRepositoryImpl method byAccountId.

@Override
public FRAccount byAccountId(String accountId, List<FRExternalPermissionsCode> permissions) {
    Optional<FRAccount> isAccount = accountsRepository.findById(accountId);
    if (!isAccount.isPresent()) {
        return null;
    }
    FRAccount account = isAccount.get();
    try {
        filterAccount(account, permissions);
        return account;
    } catch (IllegalArgumentException e) {
        return null;
    }
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)

Example 35 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class AcceptDomesticPaymentTaskTest method shouldDebitAccount.

@Test
public void shouldDebitAccount() throws CurrencyConverterException {
    // Given
    FRDomesticConsent payment = defaultPayment();
    given(paymentsService.getAllPaymentsInProcess()).willReturn(Collections.singleton(payment));
    FRAccount account = defaultAccount(DEBIT_ACCOUNT);
    given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
    FRAmount instructedAmount = payment.getInitiation().getInstructedAmount();
    // When
    acceptDomesticPaymentTask.autoAcceptPayment();
    // Then
    verify(moneyService).moveMoney(eq(account), eq(instructedAmount), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
    verify(paymentsService).updatePayment(argThat(p -> p.getStatus().equals(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) FRWriteDomesticDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticDataInitiation) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) 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) DomesticPaymentService(com.forgerock.openbanking.common.services.store.payment.DomesticPaymentService) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) FRWriteDomesticConsentData(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsentData) FRWriteDomesticConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsent) Test(org.junit.Test) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) Optional(java.util.Optional) PaymentNotificationFacade(com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) Test(org.junit.Test)

Aggregations

FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)48 Test (org.junit.Test)31 Collections (java.util.Collections)26 Optional (java.util.Optional)25 AccountStoreService (com.forgerock.openbanking.common.services.store.account.AccountStoreService)24 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)23 RunWith (org.junit.runner.RunWith)23 InjectMocks (org.mockito.InjectMocks)23 Mock (org.mockito.Mock)23 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)23 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 CurrencyConverterException (com.tunyk.currencyconverter.api.CurrencyConverterException)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 Mockito.doThrow (org.mockito.Mockito.doThrow)22