Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public enum DefaultJob implements Job {
ADD_ACCRUAL_TRANSACTIONS_FOR_LOANS_WITH_INCOME_POSTED_AS_TRANSACTIONS(
"Add Accrual Transactions For Loans With Income Posted As Transactions", "LA_AATR"), //
RECALCULATE_INTEREST_FOR_LOANS("Recalculate Interest For Loans", "LA_RINT"), //
WORKING_CAPITAL_LOAN_COB("Working Capital Loan COB", "WC_COB"); //
WORKING_CAPITAL_LOAN_COB("Working Capital Loan COB", "WC_COB"), //
JOURNAL_ENTRY_AGGREGATION("Journal Entry Aggregation", "JRNL_AGG"); //

private final String customName;
private final String shortName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ public void createAssetExternalizationRequestByLoanIdUserGeneratedExtId(DataTabl
}

@When("Admin makes asset externalization request by Loan ID with unique ownerExternalId, system-generated transferExternalId and the following data:")
public void createAssetExternalizationRequestByLoanIdSystemGeneratedExtId(DataTable table) throws IOException {
public void createAssetExternalizationRequestByLoanIdSystemGeneratedExtId(DataTable table) {
createAssetExternalizationRequestByLoanId(table, null);
}

private void createAssetExternalizationRequestByLoanId(DataTable table, String transferExternalId) throws IOException {
private void createAssetExternalizationRequestByLoanId(DataTable table, String transferExternalId) {
createAssetExternalizationRequestByLoanId(table, transferExternalId, true);
}

private void createAssetExternalizationRequestByLoanId(DataTable table, String transferExternalId, boolean regenerateOwner)
throws IOException {
private void createAssetExternalizationRequestByLoanId(DataTable table, String transferExternalId, boolean regenerateOwner) {
List<List<String>> data = table.asLists();
List<String> transferData = data.get(1);

Expand Down Expand Up @@ -286,7 +285,7 @@ private void logAssetExternalizationResponseDetails(long loanId, String ownerExt
}

@Then("Fetching Asset externalization details by loan id gives numberOfElements: {int} with correct ownerExternalId and the following data:")
public void checkAssetExternalizationDetailsByLoanId(int numberOfElements, DataTable table) throws IOException {
public void checkAssetExternalizationDetailsByLoanId(int numberOfElements, DataTable table) {
PostLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanResponse.getLoanId();

Expand All @@ -296,7 +295,7 @@ public void checkAssetExternalizationDetailsByLoanId(int numberOfElements, DataT
}

@Then("Fetching Asset externalization details by loan external id gives numberOfElements: {int} with correct ownerExternalId and the following data:")
public void checkAssetExternalizationDetailsByLoanExternalId(int numberOfElements, DataTable table) throws IOException {
public void checkAssetExternalizationDetailsByLoanExternalId(int numberOfElements, DataTable table) {
PostLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
String loanExternalId = loanResponse.getResourceExternalId();

Expand All @@ -305,7 +304,7 @@ public void checkAssetExternalizationDetailsByLoanExternalId(int numberOfElement
}

@Then("Fetching Asset externalization details by transfer external id gives numberOfElements: {int} with correct ownerExternalId and the following data:")
public void checkAssetExternalizationDetailsByTransferExternalId(int numberOfElements, DataTable table) throws IOException {
public void checkAssetExternalizationDetailsByTransferExternalId(int numberOfElements, DataTable table) {
String transferExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_SALES_TRANSFER_EXTERNAL_ID_FROM_RESPONSE);

PageExternalTransferData response = externalAssetOwnersApi().getTransfers(Map.of("transferExternalId", transferExternalId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class SchedulerStepDef extends AbstractStepDef {
@Autowired
private FineractFeignClient fineractClient;

@And("Admin runs the {string} job")
public void runPeriodicAccrualTransaction(String jobName) {
DefaultJob job = DefaultJob.valueOf(jobName);
jobService.executeAndWait(job);
}

@And("Admin runs the Add Accrual Transactions job")
public void runAccrualTransaction() {
jobService.executeAndWait(DefaultJob.ADD_ACCRUAL_TRANSACTIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,34 @@ public void transactionSummaryReportWithAssetOwnerColumnNonEmpty(final String da
verifyColumnNullability("Transaction Summary Report with Asset Owner", dateStr, columnName, false);
}

@Then("Transaction Summary Report with Asset Owner for date {string} has originatorId, asset owner externalId and the following data:")
public void transactionSummaryReportWithAssetOwnerHasDataWithOwnerExternalIdAndOriginatorId(final String dateStr,
final DataTable dataTable) {
verifyReportDataWithOwnerExternalIdAndOriginatorId("Transaction Summary Report with Asset Owner", dateStr, dataTable);
}

@Then("Transaction Summary Report with Asset Owner for date {string} column {string} has empty value for all rows")
public void transactionSummaryReportWithAssetOwnerColumnEmpty(final String dateStr, final String columnName) {
verifyColumnNullability("Transaction Summary Report with Asset Owner", dateStr, columnName, true);
}

@Then("Trial Balance Summary Report with Asset Owner for date {string} has originatorId, asset owner externalId and the following data:")
public void trialBalanceSummaryReportWithAssetOwnerHasDataWithOwnerExternalIdAndOriginatorId(final String dateStr,
final DataTable dataTable) {
verifyBalanceReportDataWithOwnerExternalIdAndOriginatorId("Trial Balance Summary Report with Asset Owner", dateStr, dataTable);
}

private void verifyReportData(final String reportName, final String dateStr, final DataTable dataTable) {
final RunReportsResponse response = executeReport(reportName, dateStr);

final List<List<String>> expected = dataTable.asLists();
final List<String> headers = expected.getFirst();

verifyReportData(reportName, response, expected, headers);
}

private List<List<String>> verifyReportDataHeaders(final String reportName, final RunReportsResponse response,
final List<List<String>> expected, List<String> headers) {
assertThat(response.getColumnHeaders()).isNotNull();
final int[] colIdx = headers.stream().mapToInt(h -> findColumnIndex(response.getColumnHeaders(), h)).toArray();

Expand All @@ -86,11 +103,34 @@ private void verifyReportData(final String reportName, final String dateStr, fin
assertThat(actual).as("Report '%s' row count mismatch.\nActual rows:\n%s", reportName, formatRows(actual))
.hasSize(expected.size() - 1);

return actual;
}

private void verifyReportDataRows(final String reportName, List<List<String>> actual, final List<List<String>> expected,
List<String> headers) {
for (int i = 1; i < expected.size(); i++) {
final List<String> expRow = expected.get(i).stream().map(v -> v == null ? "" : v).toList();
final List<String> actRow = actual.get(i - 1);
for (int j = 0; j < headers.size(); j++) {
if (expRow.get(j).isEmpty()) {
continue;
}
if (!valuesMatch(expRow.get(j), actRow.get(j))) {
fail("Report '%s', row %d, column '%s': expected='%s', actual='%s'\nAll actual rows:\n%s", reportName, i,
headers.get(j), expRow.get(j), actRow.get(j), formatRows(actual));
}
}
}
}

private void verifyReportDataRowsWithEmptyValues(final String reportName, List<List<String>> actual, final List<List<String>> expected,
List<String> headers) {
for (int i = 1; i < expected.size(); i++) {
final List<String> expRow = expected.get(i).stream().map(v -> v == null ? "" : v).toList();
final List<String> actRow = actual.get(i - 1);
for (int j = 0; j < headers.size(); j++) {
if (expRow.get(j).isEmpty()) {
assertThat(actRow.get(j).isEmpty() || actRow.get(j).equals("null")).isTrue();
continue;
}
if (!valuesMatch(expRow.get(j), actRow.get(j))) {
Expand All @@ -101,6 +141,114 @@ private void verifyReportData(final String reportName, final String dateStr, fin
}
}

private void verifyBalanceReportData(final String reportName, List<List<String>> actual, final List<List<String>> expected,
List<String> headers) {
for (int i = 1; i < expected.size(); i++) {
final List<String> expRow = expected.get(i).stream().map(v -> v == null ? "" : v).toList();
String expectedDescription = expRow.get(3);
String expectedAssetOwnerId = expRow.get(4);
final List<String> actRow = actual.stream()
.filter(actualRow -> actualRow.contains(expectedDescription) && actualRow.contains(expectedAssetOwnerId)).findFirst()
.orElseThrow(() -> new RuntimeException(String.format("No such row is found in %s report!", reportName)));
for (int j = 0; j < headers.size(); j++) {
if (expRow.get(j).isEmpty()) {
assertThat(actRow.get(j).isEmpty() || actRow.get(j).equals("null")).isTrue();
continue;
}
if (!valuesMatch(expRow.get(j), actRow.get(j))) {
fail("Report '%s', row %d, column '%s': expected='%s', actual='%s'\nAll actual rows:\n%s", reportName, i,
headers.get(j), expRow.get(j), actRow.get(j), formatRows(actual));
}
}
}
}

private void verifyReportDataWithEmptyValues(final String reportName, final RunReportsResponse response,
final List<List<String>> expected, List<String> headers) {
final List<List<String>> actual = verifyReportDataHeaders(reportName, response, expected, headers);
verifyReportDataRowsWithEmptyValues(reportName, actual, expected, headers);
}

private void verifyReportData(final String reportName, final RunReportsResponse response, final List<List<String>> expected,
List<String> headers) {
final List<List<String>> actual = verifyReportDataHeaders(reportName, response, expected, headers);
verifyReportDataRows(reportName, actual, expected, headers);
}

private void verifyBalanceReportData(final String reportName, final RunReportsResponse response, final List<List<String>> expected,
List<String> headers) {
final List<List<String>> actual = verifyReportDataHeaders(reportName, response, expected, headers);
verifyBalanceReportData(reportName, actual, expected, headers);
}

private void verifyReportDataWithOwnerExternalIdAndOriginatorId(final String reportName, final String dateStr,
final DataTable dataTable) {
String originatorExternalId = testContext().get(TestContextKey.ORIGINATOR_EXTERNAL_ID);
String ownerExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_OWNER_EXTERNAL_ID);
String previousOwnerExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_PREVIOUS_OWNER_EXTERNAL_ID);

final RunReportsResponse response = executeReport(reportName, dateStr);

final List<List<String>> expected = dataTable.asLists();
final List<String> headers = expected.getFirst();

expected.stream().skip(1).forEach(expectedRow -> {
if (expectedRow.contains("previous_owner_external_id")) {
int index = expectedRow.indexOf("previous_owner_external_id");
if (index != -1) {
expectedRow.set(index, previousOwnerExternalId);
}
}
if (expectedRow.contains("owner_external_id")) {
int index = expectedRow.indexOf("owner_external_id");
if (index != -1) {
expectedRow.set(index, ownerExternalId);
}
}

if (expectedRow.contains("originator_external_id")) {
int index = expectedRow.indexOf("originator_external_id");
if (index != -1) {
expectedRow.set(index, originatorExternalId);
}
}
});
verifyReportDataWithEmptyValues(reportName, response, expected, headers);
}

private void verifyBalanceReportDataWithOwnerExternalIdAndOriginatorId(final String reportName, final String dateStr,
final DataTable dataTable) {
String originatorExternalId = testContext().get(TestContextKey.ORIGINATOR_EXTERNAL_ID);
String ownerExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_OWNER_EXTERNAL_ID);
String previousOwnerExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_PREVIOUS_OWNER_EXTERNAL_ID);

final RunReportsResponse response = executeReport(reportName, dateStr);

final List<List<String>> expected = dataTable.asLists();
expected.stream().skip(1).forEach(expectedRow -> {
if (expectedRow.contains("previous_owner_external_id")) {
int index = expectedRow.indexOf("previous_owner_external_id");
if (index != -1) {
expectedRow.set(index, previousOwnerExternalId);
}
} else if (expectedRow.contains("owner_external_id")) {
int index = expectedRow.indexOf("owner_external_id");
if (index != -1) {
expectedRow.set(index, ownerExternalId);
}
}
if (expectedRow.contains("originator_external_id")) {
int index = expectedRow.indexOf("originator_external_id");
if (index != -1) {
expectedRow.set(index, originatorExternalId);
}
}
});
final List<String> headers = expected.getFirst();

verifyBalanceReportData(reportName, response, expected, headers);
}

private void verifyColumnNullability(final String reportName, final String dateStr, final String columnName,
final boolean expectEmpty) {
final RunReportsResponse response = executeReport(reportName, dateStr);
Expand Down
Loading
Loading