adamsaghy commented on code in PR #5353:
URL: https://github.com/apache/fineract/pull/5353#discussion_r2755280227


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/ReportExecutionIntegrationTest.java:
##########
@@ -0,0 +1,216 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.integrationtests;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.MediaType;
+import okhttp3.ResponseBody;
+import org.apache.fineract.client.models.GetReportsResponse;
+import org.apache.fineract.client.models.PostClientsRequest;
+import org.apache.fineract.client.models.PostLoanProductsRequest;
+import org.apache.fineract.client.models.PostLoanProductsResponse;
+import org.apache.fineract.client.models.PostLoansLoanIdRequest;
+import org.apache.fineract.client.models.PostLoansRequest;
+import org.apache.fineract.client.models.PostLoansResponse;
+import org.apache.fineract.client.models.RunReportsResponse;
+import org.apache.fineract.integrationtests.client.IntegrationTest;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.junit.jupiter.api.Test;
+import retrofit2.Call;
+import retrofit2.Response;
+import retrofit2.http.GET;
+
+@Slf4j
+class ReportExecutionIntegrationTest extends IntegrationTest {
+
+    // Internal interface to reuse the working FineractClient configuration
+    interface MetricsApi {
+
+        @GET("../../actuator/metrics/fineract.report.execution")
+        Call<ResponseBody> getReportExecutionMetrics();
+    }
+
+    @Test
+    void verifyClientListingReportAndMetrics() throws IOException {
+        String uniqueClientName = "ReportTestClient_" + 
UUID.randomUUID().toString().substring(0, 8);
+        Long clientId = createClient(uniqueClientName);
+        assertThat(clientId).isNotNull();
+
+        // Run the Client Listing Report (Table/JSON format)
+        Response<RunReportsResponse> response = okR(
+                fineractClient().reportsRun.runReportGetData("Client Listing", 
Map.of("R_officeId", "1"), false));
+
+        assertThat(response.code()).isEqualTo(200);
+        RunReportsResponse body = response.body();
+        assertThat(body).isNotNull();
+        assertThat(body.getColumnHeaders()).isNotEmpty();
+        assertThat(body.getData()).isNotNull();
+        assertThat(body.getData().toString()).contains(uniqueClientName);
+
+        // Run the Client Listing Report (CSV format)
+        Response<ResponseBody> csvResponse = okR(
+                fineractClient().reportsRun.runReportGetFile("Client Listing", 
Map.of("R_officeId", "1", "exportCSV", "true"), false));
+
+        assertThat(csvResponse.body()).isNotNull();
+
+        try (ResponseBody csvBody = csvResponse.body()) {
+            
assertThat(csvBody.contentType()).isEqualTo(MediaType.parse("text/csv"));
+            String csvContent = csvBody.string();
+            assertThat(csvContent).contains(uniqueClientName);
+        }
+    }
+
+    @Test
+    void verifyLoanListingReport() {
+        String uniqueClientName = "LoanReportClient_" + 
UUID.randomUUID().toString().substring(0, 8);
+        Long clientId = createClient(uniqueClientName);
+        Long loanProductId = createLoanProduct();
+        Long loanId = applyForLoan(clientId, loanProductId);
+        approveLoan(loanId);
+        disburseLoan(loanId, BigDecimal.valueOf(1000.0));
+
+        Response<RunReportsResponse> response = okR(
+                fineractClient().reportsRun.runReportGetData("Active Loans - 
Details", Map.of("R_officeId", "1", "R_loanOfficerId", "-1",
+                        "R_currencyId", "-1", "R_fundId", "-1", 
"R_loanProductId", "-1", "R_loanPurposeId", "-1"), false));
+
+        assertThat(response.code()).isEqualTo(200);
+        RunReportsResponse body = response.body();
+        assertThat(body).isNotNull();
+        assertThat(body.getData()).isNotNull();
+        assertThat(body.getData().toString()).contains(String.valueOf(loanId));
+    }
+
+    @Test
+    void verifyAllReportsExecution() throws IOException {
+        // Setup Data needed to populate reports with context
+        String uniqueClientName = "LoanReportClient_" + 
UUID.randomUUID().toString().substring(0, 8);
+        Long clientId = createClient(uniqueClientName);
+        Long loanProductId = createLoanProduct();
+        Long loanId = applyForLoan(clientId, loanProductId);
+        approveLoan(loanId);
+        disburseLoan(loanId, BigDecimal.valueOf(1000.0));
+
+        // Build the map of parameters
+        Map<String, String> commonParams = new HashMap<>();
+        commonParams.put("R_officeId", "1");
+        commonParams.put("R_clientId", clientId.toString());
+        commonParams.put("R_loanId", loanId.toString());
+        commonParams.put("R_loanProductId", loanProductId.toString());
+        commonParams.put("R_loanOfficerId", "-1");
+        commonParams.put("R_currencyId", "-1");
+        commonParams.put("R_fundId", "-1");
+        commonParams.put("R_startDate", "2023-01-01");
+        commonParams.put("R_endDate", "2025-12-31");
+
+        // Fetch ALL reports
+        Response<List<GetReportsResponse>> reportListResponse = 
okR(fineractClient().reports.retrieveReportList());
+        assertThat(reportListResponse.isSuccessful()).isTrue();
+        List<GetReportsResponse> allReports = reportListResponse.body();
+        assertThat(allReports).isNotEmpty();
+
+        // Execution Loop
+        int successCount = 0;
+        Map<String, String> failedReports = new HashMap<>(); // Track failures
+
+        log.info("Starting dynamic execution of {} reports...", 
allReports.size());
+
+        for (GetReportsResponse report : allReports) {

Review Comment:
   based on report type you can filter PENTAHO reports out.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to