budaidev commented on code in PR #6084:
URL: https://github.com/apache/fineract/pull/6084#discussion_r3525603467


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/client/feign/helpers/FeignLoanHelper.java:
##########
@@ -95,9 +124,61 @@ public Long createSimpleLoanProduct() {
         return createLoanProduct(request);
     }
 
-    public Long createLoanProduct(PostLoanProductsRequest request) {
-        PostLoanProductsResponse response = ok(() -> 
fineractClient.loanProducts().createLoanProduct(request));
-        return response.getResourceId();
+    public PostLoanProductsResponse createLoanProduct(PostLoanProductsRequest 
request) {
+        return ok(() -> 
fineractClient.loanProducts().createLoanProduct(request));
+    }
+
+    /**
+     * WARNING: This method uses ObjectMapperFactory which silences unknown 
property errors. Do not use this method in
+     * tests expecting strict deserialization.
+     */
+    public Long createLoanProductFromJson(String loanProductJson) {
+        try {
+            String sanitizedJson = 
loanProductJson.replaceAll("(?<=\\d),(?=\\d{3})", "");
+            PostLoanProductsRequest request = 
ObjectMapperFactory.getShared().readValue(sanitizedJson, 
PostLoanProductsRequest.class);
+            return createLoanProduct(request).getResourceId();
+        } catch (com.fasterxml.jackson.core.JsonProcessingException e) {
+            throw new IllegalArgumentException("Invalid loan product json", e);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> T extractErrorAttribute(CallFailedRuntimeException exception, 
String jsonAttributeToGetBack) {
+        if (!(exception.getCause() instanceof 
org.apache.fineract.client.feign.FeignException feignException)) {
+            throw new IllegalStateException("Expected FeignException cause");
+        }
+        try {
+            Map<String, Object> body = 
ObjectMapperFactory.getShared().readValue(feignException.responseBodyAsString(),
 Map.class);
+            return (T) body.get(jsonAttributeToGetBack);
+        } catch (com.fasterxml.jackson.core.JsonProcessingException e) {
+            throw new IllegalStateException("Failed to parse error response 
for attribute " + jsonAttributeToGetBack, e);
+        }
+    }
+
+    public <T> T getLoanProductError(String loanProductJson, String 
jsonAttributeToGetBack) {
+        try {
+            String sanitizedJson = 
loanProductJson.replaceAll("(?<=\\d),(?=\\d{3})", "");
+            PostLoanProductsRequest request = 
ObjectMapperFactory.getShared().readValue(sanitizedJson, 
PostLoanProductsRequest.class);
+            CallFailedRuntimeException ex = fail(() -> 
fineractClient.loanProducts().createLoanProduct(request));
+            return extractErrorAttribute(ex, jsonAttributeToGetBack);
+        } catch (com.fasterxml.jackson.core.JsonProcessingException e) {
+            throw new IllegalArgumentException("Invalid loan product json", e);
+        }
+    }
+
+    public CallFailedRuntimeException addLoanChargeExpectingError(Long loanId, 
PostLoansLoanIdChargesRequest request) {
+        return fail(() -> 
fineractClient.loanCharges().executeLoanCharge(loanId, request, (String) null));
+    }
+
+    public List<AdvancedPaymentData> getAdvancedPaymentAllocationRules(Long 
loanId) {

Review Comment:
   Can't we use:
   ```
     public List<AdvancedPaymentData> getAdvancedPaymentAllocationRules(Long 
loanId) {
         return ok(() -> 
fineractClient.defaultApi().getAdvancedPaymentAllocationRulesOfLoan(loanId));
     }
   ```
   



-- 
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