@@ -3454,14 +3454,81 @@ public void transactionsExcluded(String excludedTypes) throws IOException {
3454
3454
}
3455
3455
3456
3456
@ Then ("Log out transaction list by loanExternalId, filtered out the following transaction types: {string}" )
3457
- public void transactionsExcludedBzExternalId (String excludedTypes ) throws IOException {
3457
+ public void transactionsExcludedByExternalId (String excludedTypes ) throws IOException {
3458
3458
Response <PostLoansResponse > loanCreateResponse = testContext ().get (TestContextKey .LOAN_CREATE_RESPONSE );
3459
3459
String loanExternalId = loanCreateResponse .body ().getResourceExternalId ();
3460
3460
3461
- Response <GetLoansLoanIdTransactionsResponse > transactionsByLoanIdFiltered = getTransactionsByLoanIExternalIdFiltered (loanExternalId ,
3462
- excludedTypes );
3461
+ Response <GetLoansLoanIdTransactionsResponse > transactionsByLoanIExternalIdFiltered = getTransactionsByLoanIExternalIdFiltered (
3462
+ loanExternalId , excludedTypes );
3463
3463
log .info ("Transaction list without the following transaction types: {} \n {}" , excludedTypes ,
3464
- transactionsByLoanIdFiltered .body ().toString ());
3464
+ transactionsByLoanIExternalIdFiltered .body ().toString ());
3465
+ }
3466
+
3467
+ @ Then ("Filtered out transactions list contains the the following entries when filtered out by loanId for transaction types: {string}" )
3468
+ public void transactionsExcludedCheck (String excludedTypes , DataTable table ) throws IOException {
3469
+ Response <PostLoansResponse > loanCreateResponse = testContext ().get (TestContextKey .LOAN_CREATE_RESPONSE );
3470
+ long loanId = loanCreateResponse .body ().getLoanId ();
3471
+ String resourceId = String .valueOf (loanId );
3472
+
3473
+ Response <GetLoansLoanIdTransactionsResponse > transactionsByLoanIdFiltered = getTransactionsByLoanIdFiltered (loanId , excludedTypes );
3474
+ ErrorHelper .checkSuccessfulApiCall (transactionsByLoanIdFiltered );
3475
+ List <GetLoansLoanIdTransactionsTransactionIdResponse > transactions = transactionsByLoanIdFiltered .body ().getContent ();
3476
+ List <List <String >> data = table .asLists ();
3477
+ for (int i = 1 ; i < data .size (); i ++) {
3478
+ List <String > expectedValues = data .get (i );
3479
+ String transactionDateExpected = expectedValues .get (0 );
3480
+ List <List <String >> actualValuesList = transactions .stream ()//
3481
+ .filter (t -> transactionDateExpected .equals (FORMATTER .format (t .getDate ())))//
3482
+ .map (t -> fetchValuesOfFilteredTransaction (table .row (0 ), t ))//
3483
+ .collect (Collectors .toList ());//
3484
+ boolean containsExpectedValues = actualValuesList .stream ()//
3485
+ .anyMatch (actualValues -> actualValues .equals (expectedValues ));//
3486
+ assertThat (containsExpectedValues )
3487
+ .as (ErrorMessageHelper .wrongValueInLineInTransactionsTab (resourceId , i , actualValuesList , expectedValues )).isTrue ();
3488
+ }
3489
+ assertThat (transactions .size ())
3490
+ .as (ErrorMessageHelper .nrOfLinesWrongInTransactionsTab (resourceId , transactions .size (), data .size () - 1 ))
3491
+ .isEqualTo (data .size () - 1 );
3492
+ }
3493
+
3494
+ @ Then ("Filtered out transactions list contains the the following entries when filtered out by loanExternalId for transaction types: {string}" )
3495
+ public void transactionsExcludedByLoanExternalIdCheck (String excludedTypes , DataTable table ) throws IOException {
3496
+ Response <PostLoansResponse > loanCreateResponse = testContext ().get (TestContextKey .LOAN_CREATE_RESPONSE );
3497
+ String loanExternalId = loanCreateResponse .body ().getResourceExternalId ();
3498
+ long loanId = loanCreateResponse .body ().getLoanId ();
3499
+ String resourceId = String .valueOf (loanId );
3500
+
3501
+ Response <GetLoansLoanIdTransactionsResponse > transactionsByLoanExternalIdFiltered = getTransactionsByLoanIExternalIdFiltered (
3502
+ loanExternalId , excludedTypes );
3503
+ ErrorHelper .checkSuccessfulApiCall (transactionsByLoanExternalIdFiltered );
3504
+
3505
+ List <GetLoansLoanIdTransactionsTransactionIdResponse > transactions = transactionsByLoanExternalIdFiltered .body ().getContent ();
3506
+ List <List <String >> data = table .asLists ();
3507
+ for (int i = 1 ; i < data .size (); i ++) {
3508
+ List <String > expectedValues = data .get (i );
3509
+ String transactionDateExpected = expectedValues .get (0 );
3510
+ List <List <String >> actualValuesList = transactions .stream ()//
3511
+ .filter (t -> transactionDateExpected .equals (FORMATTER .format (t .getDate ())))//
3512
+ .map (t -> fetchValuesOfFilteredTransaction (table .row (0 ), t ))//
3513
+ .collect (Collectors .toList ());//
3514
+ boolean containsExpectedValues = actualValuesList .stream ()//
3515
+ .anyMatch (actualValues -> actualValues .equals (expectedValues ));//
3516
+ assertThat (containsExpectedValues )
3517
+ .as (ErrorMessageHelper .wrongValueInLineInTransactionsTab (resourceId , i , actualValuesList , expectedValues )).isTrue ();
3518
+ }
3519
+ assertThat (transactions .size ())
3520
+ .as (ErrorMessageHelper .nrOfLinesWrongInTransactionsTab (resourceId , transactions .size (), data .size () - 1 ))
3521
+ .isEqualTo (data .size () - 1 );
3522
+ }
3523
+
3524
+ @ Then ("Filtered out transactions list request results an error when filtered out by loanExternalId for transaction type not exist: {string}" )
3525
+ public void transactionsExcludedErrorNotPresent (String transactionsExcluded ) throws IOException {
3526
+ // Response<PostLoansResponse> loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
3527
+ // long loanId = loanCreateResponse.body().getLoanId();
3528
+
3529
+ // Response<GetLoansLoanIdTransactionsResponse> transactionsByLoanIdFiltered =
3530
+ // getTransactionsByLoanIdFiltered(loanId, transactionsExcluded);
3531
+ // TODO make checks here
3465
3532
}
3466
3533
3467
3534
private Response <GetLoansLoanIdTransactionsResponse > getTransactionsByLoanIdFiltered (Long loanId , String excludedTypes )
@@ -3473,4 +3540,39 @@ private Response<GetLoansLoanIdTransactionsResponse> getTransactionsByLoanIExter
3473
3540
String excludedTypes ) throws IOException {
3474
3541
return loanTransactionsApi .retrieveTransactionsByExternalLoanId (loanExternalId , excludedTypes , null , null , null ).execute ();
3475
3542
}
3543
+
3544
+ private List <String > fetchValuesOfFilteredTransaction (List <String > header , GetLoansLoanIdTransactionsTransactionIdResponse t ) {
3545
+ List <String > actualValues = new ArrayList <>();
3546
+ for (String headerName : header ) {
3547
+ switch (headerName ) {
3548
+ case "Transaction date" -> actualValues .add (t .getDate () == null ? null : FORMATTER .format (t .getDate ()));
3549
+ case "Transaction Type" -> actualValues .add (t .getType ().getCode () == null ? null : t .getType ().getCode ().substring (20 ));
3550
+ case "Amount" -> actualValues .add (t .getAmount () == null ? null : String .valueOf (t .getAmount ()));
3551
+ case "Principal" -> actualValues .add (t .getPrincipalPortion () == null ? null : String .valueOf (t .getPrincipalPortion ()));
3552
+ case "Interest" -> actualValues .add (t .getInterestPortion () == null ? null : String .valueOf (t .getInterestPortion ()));
3553
+ case "Fees" -> actualValues .add (t .getFeeChargesPortion () == null ? null : String .valueOf (t .getFeeChargesPortion ()));
3554
+ case "Penalties" ->
3555
+ actualValues .add (t .getPenaltyChargesPortion () == null ? null : String .valueOf (t .getPenaltyChargesPortion ()));
3556
+ case "Loan Balance" ->
3557
+ actualValues .add (t .getOutstandingLoanBalance () == null ? null : String .valueOf (t .getOutstandingLoanBalance ()));
3558
+ case "Overpayment" ->
3559
+ actualValues .add (t .getOverpaymentPortion () == null ? null : String .valueOf (t .getOverpaymentPortion ()));
3560
+ default -> throw new IllegalStateException (String .format ("Header name %s cannot be found" , headerName ));
3561
+ }
3562
+ }
3563
+ return actualValues ;
3564
+ }
3565
+
3566
+ @ Then ("Filtered out transactions list has {int} pages in case of size set to {int} and transactions are filtered out for transaction types: {string}" )
3567
+ public void checkPagination (Integer totalPagesExpected , Integer size , String excludedTypes ) throws IOException {
3568
+ Response <PostLoansResponse > loanCreateResponse = testContext ().get (TestContextKey .LOAN_CREATE_RESPONSE );
3569
+ long loanId = loanCreateResponse .body ().getLoanId ();
3570
+ Response <GetLoansLoanIdTransactionsResponse > transactionsByLoanIdFiltered = loanTransactionsApi
3571
+ .retrieveTransactionsByLoanId (loanId , excludedTypes , null , size , null ).execute ();
3572
+
3573
+ Integer totalPagesActual = transactionsByLoanIdFiltered .body ().getTotalPages ();
3574
+
3575
+ assertThat (totalPagesActual ).as (ErrorMessageHelper .wrongValueInTotalPages (totalPagesActual , totalPagesExpected ))
3576
+ .isEqualTo (totalPagesExpected );
3577
+ }
3476
3578
}
0 commit comments