@@ -69,7 +69,6 @@ public void journalEntryDataCheck(String transactionType, String transactionDate
6969 DateTimeFormatter formatter = DateTimeFormatter .ofPattern (DATE_FORMAT );
7070 Response <PostLoansResponse > loanResponse = testContext ().get (TestContextKey .LOAN_CREATE_RESPONSE );
7171 long loanId = loanResponse .body ().getLoanId ();
72- String resourceId = String .valueOf (loanId );
7372
7473 Response <GetLoansLoanIdResponse > loanDetailsResponse = loansApi .retrieveLoan (loanId , false , "transactions" , "" , "" ).execute ();
7574 ErrorHelper .checkSuccessfulApiCall (loanDetailsResponse );
@@ -83,6 +82,50 @@ public void journalEntryDataCheck(String transactionType, String transactionDate
8382 && transactionTypeExpected .equals (t .getType ().getCode ().substring (20 )))
8483 .collect (Collectors .toList ());
8584
85+ List <List <JournalEntryTransactionItem >> journalLinesActualList = getJournalLinesActualList (transactionsMatch );
86+ checkJournalEntryData (journalLinesActualList , loanId , table );
87+ }
88+
89+ public void checkJournalEntryData (List <List <JournalEntryTransactionItem >> journalLinesActualList , long loanId , DataTable table ) {
90+ String resourceId = String .valueOf (loanId );
91+
92+ List <List <String >> data = table .asLists ();
93+ final int expectedCount = data .size () - 1 ;
94+ final int actualCount = journalLinesActualList .stream ().mapToInt (List ::size ).sum ();
95+ assertThat (actualCount ).as ("The number of journal entries for the transaction does not match the expected count! Expected: "
96+ + expectedCount + ", Actual: " + actualCount ).isEqualTo (expectedCount );
97+ for (int i = 1 ; i < data .size (); i ++) {
98+ List <List <List <String >>> possibleActualValuesList = new ArrayList <>();
99+ List <String > expectedValues = data .get (i );
100+ boolean containsAnyExpected = false ;
101+
102+ for (int j = 0 ; j < journalLinesActualList .size (); j ++) {
103+ List <JournalEntryTransactionItem > journalLinesActual = journalLinesActualList .get (j );
104+
105+ List <List <String >> actualValuesList = journalLinesActual .stream ().map (t -> {
106+ List <String > actualValues = new ArrayList <>();
107+ actualValues .add (t .getGlAccountType ().getValue () == null ? null : t .getGlAccountType ().getValue ());
108+ actualValues .add (t .getGlAccountCode () == null ? null : t .getGlAccountCode ());
109+ actualValues .add (t .getGlAccountName () == null ? null : t .getGlAccountName ());
110+ actualValues .add ("DEBIT" .equals (t .getEntryType ().getValue ()) ? String .valueOf (t .getAmount ()) : null );
111+ actualValues .add ("CREDIT" .equals (t .getEntryType ().getValue ()) ? String .valueOf (t .getAmount ()) : null );
112+
113+ return actualValues ;
114+ }).collect (Collectors .toList ());
115+ possibleActualValuesList .add (actualValuesList );
116+
117+ boolean containsExpectedValues = actualValuesList .stream ().anyMatch (actualValues -> actualValues .equals (expectedValues ));
118+ if (containsExpectedValues ) {
119+ containsAnyExpected = true ;
120+ }
121+ }
122+ assertThat (containsAnyExpected )
123+ .as (ErrorMessageHelper .wrongValueInLineInJournalEntries (resourceId , i , possibleActualValuesList , expectedValues ))
124+ .isTrue ();
125+ }
126+ }
127+
128+ public List <List <JournalEntryTransactionItem >> getJournalLinesActualList (List <GetLoansLoanIdTransactions > transactionsMatch ) {
86129 List <List <JournalEntryTransactionItem >> journalLinesActualList = transactionsMatch .stream ().map (t -> {
87130 String transactionId = "L" + t .getId ();
88131 Response <GetJournalEntriesTransactionIdResponse > journalEntryDataResponse = null ;
@@ -116,40 +159,33 @@ public void journalEntryDataCheck(String transactionType, String transactionDate
116159 return journalEntryDataResponse .body ().getPageItems ();
117160 }).collect (Collectors .toList ());
118161
119- List <List <String >> data = table .asLists ();
120- final int expectedCount = data .size () - 1 ;
121- final int actualCount = journalLinesActualList .stream ().mapToInt (List ::size ).sum ();
122- assertThat (actualCount ).as ("The number of journal entries for the transaction does not match the expected count! Expected: "
123- + expectedCount + ", Actual: " + actualCount ).isEqualTo (expectedCount );
124- for (int i = 1 ; i < data .size (); i ++) {
125- List <List <List <String >>> possibleActualValuesList = new ArrayList <>();
126- List <String > expectedValues = data .get (i );
127- boolean containsAnyExpected = false ;
162+ return journalLinesActualList ;
163+ }
128164
129- for (int j = 0 ; j < journalLinesActualList .size (); j ++) {
130- List <JournalEntryTransactionItem > journalLinesActual = journalLinesActualList .get (j );
165+ @ Then ("Loan Transactions tab has {int} a {string} transactions with date {string} which has the following Journal entries:" )
166+ public void journalEntryDataCheck (int numberTrns , String transactionType , String transactionDate , DataTable table ) throws IOException {
167+ DateTimeFormatter formatter = DateTimeFormatter .ofPattern (DATE_FORMAT );
168+ Response <PostLoansResponse > loanResponse = testContext ().get (TestContextKey .LOAN_CREATE_RESPONSE );
169+ long loanId = loanResponse .body ().getLoanId ();
131170
132- List <List <String >> actualValuesList = journalLinesActual .stream ().map (t -> {
133- List <String > actualValues = new ArrayList <>();
134- actualValues .add (t .getGlAccountType ().getValue () == null ? null : t .getGlAccountType ().getValue ());
135- actualValues .add (t .getGlAccountCode () == null ? null : t .getGlAccountCode ());
136- actualValues .add (t .getGlAccountName () == null ? null : t .getGlAccountName ());
137- actualValues .add ("DEBIT" .equals (t .getEntryType ().getValue ()) ? String .valueOf (t .getAmount ()) : null );
138- actualValues .add ("CREDIT" .equals (t .getEntryType ().getValue ()) ? String .valueOf (t .getAmount ()) : null );
171+ Response <GetLoansLoanIdResponse > loanDetailsResponse = loansApi .retrieveLoan (loanId , false , "transactions" , "" , "" ).execute ();
172+ ErrorHelper .checkSuccessfulApiCall (loanDetailsResponse );
139173
140- return actualValues ;
141- }).collect (Collectors .toList ());
142- possibleActualValuesList .add (actualValuesList );
174+ TransactionType transactionType1 = TransactionType .valueOf (transactionType );
175+ String transactionTypeExpected = transactionType1 .getValue ();
143176
144- boolean containsExpectedValues = actualValuesList .stream ().anyMatch (actualValues -> actualValues .equals (expectedValues ));
145- if (containsExpectedValues ) {
146- containsAnyExpected = true ;
147- }
148- }
149- assertThat (containsAnyExpected )
150- .as (ErrorMessageHelper .wrongValueInLineInJournalEntries (resourceId , i , possibleActualValuesList , expectedValues ))
151- .isTrue ();
152- }
177+ List <GetLoansLoanIdTransactions > transactions = loanDetailsResponse .body ().getTransactions ();
178+ List <GetLoansLoanIdTransactions > transactionsMatch = transactions .stream ()
179+ .filter (t -> transactionDate .equals (formatter .format (t .getDate ()))
180+ && transactionTypeExpected .equals (t .getType ().getCode ().substring (20 )))
181+ .collect (Collectors .toList ());
182+ assertThat (transactionsMatch .size ())
183+ .as ("The number of journal entries for the transaction does not match the expected count! Expected: " + numberTrns
184+ + ", Actual: " + transactionsMatch .size ())
185+ .isEqualTo (numberTrns );
186+
187+ List <List <JournalEntryTransactionItem >> journalLinesActualList = getJournalLinesActualList (transactionsMatch );
188+ checkJournalEntryData (journalLinesActualList , loanId , table );
153189 }
154190
155191 @ Then ("Reversed loan capitalized income amortization transaction has the following Journal entries:" )
0 commit comments