Skip to content

Commit

Permalink
Update TransferApiTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Jadavpadma authored Dec 19, 2024
1 parent b971f0d commit 80c2116
Showing 1 changed file with 46 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,103 +1,63 @@
/*
* Open Banking
* OpenAPI specification for Finicity APIs. Open Banking solutions in the US are provided by Finicity, a Mastercard company.
*
* The version of the OpenAPI document: 1.17.1
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


package com.mastercard.openbanking.client.api;

import com.mastercard.openbanking.client.ApiException;
import com.mastercard.openbanking.client.model.TransactionsReportConstraints;
import com.mastercard.openbanking.client.model.DepositSwitchDetails;
import com.mastercard.openbanking.client.model.DepositSwitchesSummary;
import com.mastercard.openbanking.client.test.ModelFactory;
import com.mastercard.openbanking.client.test.BaseTest;
import com.mastercard.openbanking.client.test.utils.AccountUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

import static java.time.ZoneOffset.UTC;
import org.junit.jupiter.api.Disabled;
import static org.junit.jupiter.api.Assertions.*;


class TransactionsApiTest extends BaseTest {

private static final TransactionsApi api = new TransactionsApi(apiClient);
private static String existingAccountId;
private static Long existingTransactionId;
private static String customerAccountList;
/**
* API tests for TransferApi
*/
@Disabled
class TransferApiTest extends BaseTest{

private static final Long fromDate = LocalDateTime.now().minusYears(10).toEpochSecond(UTC);
private static final Long toDate = LocalDateTime.now().toEpochSecond(UTC);

@BeforeAll
protected static void beforeAll() {
try {
// Find the last account ID
var accounts = AccountUtils.getCustomerAccounts(new AccountsApi(apiClient), CUSTOMER_ID);
var account = accounts.get(accounts.size() - 1);
existingAccountId = account.getId();

// Find an existing transaction ID
var transaction = api.getAllCustomerTransactions(CUSTOMER_ID, fromDate, toDate, null, null, null, true)
.getTransactions()
.stream()
.findFirst();
if (transaction.isEmpty()) {
Assertions.fail();
}
existingTransactionId = transaction.get().getId();

// Fetch some accounts IDs to be included in reports
customerAccountList = AccountUtils.getCustomerAccountListString(new AccountsApi(apiClient), CUSTOMER_ID);
} catch (ApiException e) {
Assertions.fail(e);
}
}
private final TransferApi api = new TransferApi();

/**
* Get Deposit Switches by Customer ID
*
* Retrieve summary of deposit switches performed by given customer ID. _Supported regions_: ![🇺🇸](https://flagcdn.com/20x15/us.png)
*
* @throws ApiException if the Api call fails
*/
@Test
void generateTransactionsReportTest() {
try {
var constraints = new TransactionsReportConstraints().accountIds(customerAccountList);
var reportAck = api.generateTransactionsReport(CUSTOMER_ID, fromDate,toDate, constraints, null, true);
assertEquals("inProgress", reportAck.getStatus());
assertEquals("transactions", reportAck.getType());
} catch (ApiException e) {
// Status code: 429, Reason: Too Many Requests
logApiException(e);
}
void getAllDepositSwitchesTest() throws ApiException {
String customerId = CUSTOMER_ID;
DepositSwitchesSummary summary = api.getAllDepositSwitches(customerId);
assertNotNull(summary.getSwitches());
}

/**
* Get Deposit Switch by ID
*
* Retrieve deposit switch details by switch ID. _Supported regions_: ![🇺🇸](https://flagcdn.com/20x15/us.png)
*
* @throws ApiException if the Api call fails
*/
@Test
void getAllCustomerTransactionsTest() {
try {
var transactions = api.getAllCustomerTransactions(CUSTOMER_ID, fromDate, toDate, null, null, null, true);
assertTrue(transactions.getTransactions().size() > 0);
} catch (ApiException e) {
Assertions.fail(e);
}
void getDepositSwitchDetailsTest() throws ApiException {
String customerId = CUSTOMER_ID;
String switchId = ModelFactory.randomStr();
DepositSwitchDetails switchDetails = api.getDepositSwitchDetails(customerId, switchId);
assertNotNull(switchDetails.getSwitchId());
}

@Test
void getCustomerAccountTransactionsTest() {
try {
var transactions = api.getCustomerAccountTransactions(CUSTOMER_ID, existingAccountId, fromDate, toDate, null, null, null, true);
assertTrue(transactions.getTransactions().size() > 0);
} catch (ApiException e) {
Assertions.fail(e);
}
}

@Test
void getCustomerTransactionTest() {
try {
var transaction = api.getCustomerTransaction(CUSTOMER_ID, existingTransactionId);
assertNotNull(transaction);
} catch (ApiException e) {
Assertions.fail(e);
}
}

@Test
void loadHistoricTransactionsForCustomerAccountTest() {
try {
api.loadHistoricTransactionsForCustomerAccount(CUSTOMER_ID, existingAccountId);
} catch (ApiException e) {
Assertions.fail(e);
}
}
}

0 comments on commit 80c2116

Please sign in to comment.