This is an automated email from the ASF dual-hosted git repository.

arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 3210a0937 FINERACT-1724: Fix batch api response code
3210a0937 is described below

commit 3210a09375cee79fcc6cf4673c1c17a236d1d800
Author: abraham.menyhart <[email protected]>
AuthorDate: Tue Aug 22 13:51:28 2023 +0200

    FINERACT-1724: Fix batch api response code
---
 .../apache/fineract/batch/service/BatchApiServiceImpl.java |  9 +++++++++
 .../org/apache/fineract/integrationtests/BatchApiTest.java | 14 +++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git 
a/fineract-core/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java
 
b/fineract-core/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java
index 2538d1c39..a14a8d9d2 100644
--- 
a/fineract-core/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java
+++ 
b/fineract-core/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java
@@ -18,7 +18,10 @@
  */
 package org.apache.fineract.batch.service;
 
+import static org.springframework.http.HttpStatus.BAD_REQUEST;
+
 import com.google.gson.Gson;
+import com.jayway.jsonpath.JsonPathException;
 import io.github.resilience4j.core.functions.Either;
 import jakarta.persistence.EntityManager;
 import jakarta.persistence.PersistenceContext;
@@ -156,6 +159,12 @@ public class BatchApiServiceImpl implements 
BatchApiService {
                 BatchRequest resolvedChildRequest;
                 try {
                     resolvedChildRequest = 
this.resolutionHelper.resoluteRequest(childNode.getRequest(), response);
+                } catch (JsonPathException jsonPathException) {
+                    BatchResponse childResponse = new 
BatchResponse().setRequestId(childNode.getRequest().getRequestId())
+                            
.setHeaders(childNode.getRequest().getHeaders()).setStatusCode(BAD_REQUEST.value())
+                            .setBody(jsonPathException.getMessage());
+                    responseList.add(childResponse);
+                    return;
                 } catch (RuntimeException ex) {
                     throw new BatchExecutionException(childNode.getRequest(), 
ex, errorHandler.handle(ex));
                 }
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchApiTest.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchApiTest.java
index c7d88d714..0c6dd7df7 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchApiTest.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchApiTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.fineract.integrationtests;
 
+import static org.hamcrest.Matchers.containsString;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
@@ -65,6 +66,7 @@ import 
org.apache.fineract.integrationtests.common.system.DatatableHelper;
 import 
org.apache.fineract.integrationtests.useradministration.users.UserHelper;
 import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
 import org.apache.http.HttpStatus;
+import org.hamcrest.MatcherAssert;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -2148,11 +2150,17 @@ public class BatchApiTest {
 
         LOG.info("Batch Response : {}", new 
Gson().toJson(responseOfQueryAndUpdateDatatableBatch));
 
-        final BatchResponse batchQueryAndUpdateResponse = 
responseOfQueryAndUpdateDatatableBatch.get(0);
+        final BatchResponse queryResponse = 
responseOfQueryAndUpdateDatatableBatch.get(0);
 
-        Assertions.assertEquals(2L, 
batchQueryAndUpdateResponse.getRequestId());
-        Assertions.assertEquals(HttpStatus.SC_BAD_REQUEST, 
batchQueryAndUpdateResponse.getStatusCode(),
+        Assertions.assertEquals(1L, queryResponse.getRequestId());
+        Assertions.assertEquals(HttpStatus.SC_OK, 
queryResponse.getStatusCode(), "Verify Status Code 200 for query datatable 
entry");
+
+        final BatchResponse updateResponse = 
responseOfQueryAndUpdateDatatableBatch.get(1);
+
+        Assertions.assertEquals(2L, updateResponse.getRequestId());
+        Assertions.assertEquals(HttpStatus.SC_BAD_REQUEST, 
updateResponse.getStatusCode(),
                 "Verify Status Code 400 for update datatable entry");
+        MatcherAssert.assertThat(updateResponse.getBody(), containsString("No 
results for path"));
     }
 
     /**

Reply via email to