5959import org .apache .fineract .integrationtests .common .loans .LoanProductTestBuilder ;
6060import org .apache .fineract .integrationtests .common .loans .LoanStatusChecker ;
6161import org .apache .fineract .integrationtests .common .loans .LoanTransactionHelper ;
62- import org .junit .jupiter .api .AfterEach ;
6362import org .junit .jupiter .api .Assertions ;
6463import org .junit .jupiter .api .BeforeAll ;
6564import org .junit .jupiter .api .Test ;
@@ -107,12 +106,6 @@ public static void setupInvestorBusinessStep() {
107106 setProperFinancialActivity (TRANSFER_ACCOUNT );
108107 }
109108
110- @ AfterEach
111- public void tearDown () {
112- // Restore business date configuration after each test
113- cleanUpAndRestoreBusinessDate ();
114- }
115-
116109 private static void setProperFinancialActivity (Account transferAccount ) {
117110 List <GetFinancialActivityAccountsResponse > financialMappings = FINANCIAL_ACTIVITY_ACCOUNT_HELPER .getAllFinancialActivityAccounts ();
118111 financialMappings .forEach (mapping -> FINANCIAL_ACTIVITY_ACCOUNT_HELPER .deleteFinancialActivityAccount (mapping .getId ()));
@@ -151,16 +144,13 @@ public void testLoanCOBPartitioningQuery() throws InterruptedException {
151144
152145 // Force close loans 3, 4, ... , N-3, N-2
153146 Collections .sort (loanIds );
154- List <Integer > forelosedLoanIds = new ArrayList <>();
155147 final CountDownLatch closeLatch = new CountDownLatch (N - 5 );
156148 // Warm up (EclipseLink sometimes fails if JPQL cache is not warm up but concurrent queries are executed)
157149 LOAN_TRANSACTION_HELPER .forecloseLoan ("02 March 2020" , loanIds .get (2 ));
158- forelosedLoanIds .add (loanIds .get (2 ));
159150 for (int i = 3 ; i < N - 2 ; i ++) {
160151 final int idx = i ;
161152 futures .add (executorService .submit (() -> {
162153 LOAN_TRANSACTION_HELPER .forecloseLoan ("02 March 2020" , loanIds .get (idx ));
163- forelosedLoanIds .add (loanIds .get (idx ));
164154 closeLatch .countDown ();
165155 }));
166156 }
@@ -173,45 +163,24 @@ public void testLoanCOBPartitioningQuery() throws InterruptedException {
173163 });
174164 closeLatch .await ();
175165
176- // Create list of active (non-foreclosed) loan IDs
177- List <Integer > activeLoanIds = new ArrayList <>(loanIds );
178- activeLoanIds .removeAll (forelosedLoanIds );
179- log .info ("Active loan IDs after foreclosure: {}" , activeLoanIds );
180-
181166 // Let's retrieve the partitions
182- List <Map <String , Object >> allPartitions = CobHelper .getCobPartitions (REQUEST_SPEC , RESPONSE_SPEC , 3 , "" );
183- log .info ("\n Loans created by this test: {}\n All partitions retrieved: {}" , loanIds , allPartitions );
184-
185- // Filter partitions to only include ACTIVE loans created by THIS test
186- // This ensures test isolation - we don't care about leftover loans from other tests
187- List <Map <String , Object >> testLoanPartitions = filterPartitionsForTestLoans (allPartitions , activeLoanIds );
188- log .info ("Filtered partitions containing only our active test loans: {}" , testLoanPartitions );
189-
190- // Verify partitioning works correctly for our 4 active loans (10 created - 6 foreclosed)
191- // Expected: 2 partitions with page size 3
192- // Partition 0: loans 0, 1, 8 (3 loans)
193- // Partition 1: loan 9 (1 loan)
194- Assertions .assertEquals (2 , testLoanPartitions .size (), "Expected 2 partitions for our 4 active test loans" );
195-
196- // Verify first partition
197- Assertions .assertEquals (0 , testLoanPartitions .get (0 ).get ("pageNo" ));
198- Assertions .assertEquals (3 , testLoanPartitions .get (0 ).get ("count" ));
199- Assertions .assertTrue (isLoanIdInRange (loanIds .get (0 ), testLoanPartitions .get (0 )),
200- "First active loan should be in first partition" );
201- Assertions .assertTrue (isLoanIdInRange (loanIds .get (1 ), testLoanPartitions .get (0 )),
202- "Second active loan should be in first partition" );
203- Assertions .assertTrue (isLoanIdInRange (loanIds .get (8 ), testLoanPartitions .get (0 )),
204- "Ninth active loan should be in first partition" );
205-
206- // Verify second partition
207- Assertions .assertEquals (1 , testLoanPartitions .get (1 ).get ("pageNo" ));
208- Assertions .assertEquals (1 , testLoanPartitions .get (1 ).get ("count" ));
209- Assertions .assertTrue (isLoanIdInRange (loanIds .get (9 ), testLoanPartitions .get (1 )), "Tenth loan should be in second partition" );
167+ List <Map <String , Object >> cobPartitions = CobHelper .getCobPartitions (REQUEST_SPEC , RESPONSE_SPEC , 3 , "" );
168+ log .info ("\n Loans created: {},\n Retrieved partitions: {}" , loanIds , cobPartitions );
169+ Assertions .assertEquals (2 , cobPartitions .size ());
170+
171+ Assertions .assertEquals (0 , cobPartitions .get (0 ).get ("pageNo" ));
172+ Assertions .assertEquals (loanIds .get (0 ), cobPartitions .get (0 ).get ("minId" ));
173+ Assertions .assertEquals (loanIds .get (8 ), cobPartitions .get (0 ).get ("maxId" ));
174+ Assertions .assertEquals (3 , cobPartitions .get (0 ).get ("count" ));
175+
176+ Assertions .assertEquals (1 , cobPartitions .get (1 ).get ("pageNo" ));
177+ Assertions .assertEquals (loanIds .get (9 ), cobPartitions .get (1 ).get ("minId" ));
178+ Assertions .assertEquals (loanIds .get (9 ), cobPartitions .get (1 ).get ("maxId" ));
179+ Assertions .assertEquals (1 , cobPartitions .get (1 ).get ("count" ));
210180
211181 executorService .shutdown ();
212- } catch (Exception e ) {
213- log .error ("Test failed with exception" , e );
214- throw e ;
182+ } finally {
183+ cleanUpAndRestoreBusinessDate ();
215184 }
216185 }
217186
@@ -322,41 +291,4 @@ private HashMap<String, String> collaterals(Integer collateralId, BigDecimal qua
322291 return collateral ;
323292 }
324293
325- /**
326- * Filters partitions to only include those containing loans from the test's loan IDs. This ensures test isolation
327- * by ignoring any leftover loans from previous test runs.
328- */
329- private List <Map <String , Object >> filterPartitionsForTestLoans (List <Map <String , Object >> allPartitions , List <Integer > testLoanIds ) {
330- List <Map <String , Object >> filteredPartitions = new ArrayList <>();
331-
332- for (Map <String , Object > partition : allPartitions ) {
333- Integer minId = (Integer ) partition .get ("minId" );
334- Integer maxId = (Integer ) partition .get ("maxId" );
335-
336- // Check if this partition contains any of our test loan IDs
337- boolean containsTestLoans = testLoanIds .stream ().anyMatch (loanId -> loanId >= minId && loanId <= maxId );
338-
339- if (containsTestLoans ) {
340- // Count how many of OUR loans are in this partition's range
341- long testLoansInPartition = testLoanIds .stream ().filter (loanId -> loanId >= minId && loanId <= maxId ).count ();
342-
343- // Create a new partition entry with corrected count
344- Map <String , Object > filteredPartition = new HashMap <>(partition );
345- filteredPartition .put ("count" , (int ) testLoansInPartition );
346- filteredPartitions .add (filteredPartition );
347- }
348- }
349-
350- return filteredPartitions ;
351- }
352-
353- /**
354- * Checks if a loan ID falls within the min/max range of a partition.
355- */
356- private boolean isLoanIdInRange (Integer loanId , Map <String , Object > partition ) {
357- Integer minId = (Integer ) partition .get ("minId" );
358- Integer maxId = (Integer ) partition .get ("maxId" );
359- return loanId >= minId && loanId <= maxId ;
360- }
361-
362294}
0 commit comments