FINERACT-1724: Fix batch api response code

This commit is contained in:
abraham.menyhart
2023-08-23 12:33:02 +02:00
committed by Arnold Gálovics
parent 3885104767
commit 3210a09375
2 changed files with 20 additions and 3 deletions
@@ -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));
}
@@ -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"));
}
/**