DeathGun44 commented on code in PR #6084:
URL: https://github.com/apache/fineract/pull/6084#discussion_r3535478905
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanChargeExternalIntegrationTest.java:
##########
@@ -18,131 +18,74 @@
*/
package org.apache.fineract.integrationtests;
-import com.google.gson.Gson;
-import io.restassured.builder.RequestSpecBuilder;
-import io.restassured.builder.ResponseSpecBuilder;
-import io.restassured.http.ContentType;
-import io.restassured.specification.RequestSpecification;
-import io.restassured.specification.ResponseSpecification;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import org.apache.fineract.integrationtests.common.ClientHelper;
-import org.apache.fineract.integrationtests.common.Utils;
-import org.apache.fineract.integrationtests.common.accounting.Account;
-import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.apache.fineract.client.feign.util.CallFailedRuntimeException;
+import org.apache.fineract.client.models.GetLoansLoanIdChargesChargeIdResponse;
+import org.apache.fineract.client.models.PostLoansLoanIdChargesRequest;
+import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse;
+import org.apache.fineract.integrationtests.client.feign.FeignLoanTestBase;
import
org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
import
org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
-import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
-import
org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
-import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-@SuppressWarnings({ "rawtypes", "unchecked" })
-@ExtendWith(LoanTestLifecycleExtension.class)
-public class ClientLoanChargeExternalIntegrationTest {
+public class ClientLoanChargeExternalIntegrationTest extends FeignLoanTestBase
{
- private static final Logger LOG =
LoggerFactory.getLogger(ClientLoanChargeExternalIntegrationTest.class);
-
- public static final String MINIMUM_OPENING_BALANCE = "1000.0";
- public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
private static final String NONE = "1";
- private ResponseSpecification responseSpec;
- private RequestSpecification requestSpec;
- private LoanTransactionHelper loanTransactionHelper;
+ private static Long clientId;
@BeforeEach
public void setup() {
- Utils.initializeRESTAssured();
- this.requestSpec = new
RequestSpecBuilder().setContentType(ContentType.JSON).build();
- this.requestSpec.header("Authorization", "Basic " +
Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
- this.responseSpec = new
ResponseSpecBuilder().expectStatusCode(200).build();
- this.loanTransactionHelper = new
LoanTransactionHelper(this.requestSpec, this.responseSpec);
+ clientId = createClient("20 September 2011");
}
@Test
public void checkNewClientLoanChargeSavesExternalId() {
- final Integer clientID = ClientHelper.createClient(this.requestSpec,
this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec,
this.responseSpec, clientID);
-
- final Integer loanProductID = createLoanProduct(false, NONE);
+ final Long loanProductId = createLoanProduct(false, NONE);
- List<HashMap> collaterals = new ArrayList<>();
- final Integer loanID = applyForLoanApplication(clientID,
loanProductID, null, null, "12,000.00", collaterals);
- HashMap loanStatusHashMap = this.loanTransactionHelper.approveLoan("20
September 2011", loanID);
- LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
- loanStatusHashMap =
this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("20 September
2011", loanID, "12,000.00");
- LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+ final Long loanId = applyForLoanApplication(clientId, loanProductId,
"12,000.00");
+ approveLoan(loanId, approveLoanRequest(12000.0, "20 September 2011"));
+ disburseLoanWithNetDisbursalAmount(loanId, "20 September 2011",
"12,000.00");
- final Integer charge = ChargesHelper.createCharges(requestSpec,
responseSpec, ChargesHelper
-
.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST,
"1", false));
+ final Long chargeDefId =
chargesHelper.createLoanSpecifiedDueDatePercentageAmountAndInterestFee(1.0).getResourceId();
- final float amount = 1.0f;
- final String externalId = "extId" + loanID.toString();
- final Integer chargeID =
this.loanTransactionHelper.addChargesForLoan(loanID,
- getLoanChargeAsJSON(String.valueOf(charge), "22 September
2011", String.valueOf(amount), externalId));
- Assertions.assertNotNull(chargeID);
-
- HashMap loanChargeMap =
this.loanTransactionHelper.getLoanCharge(loanID, chargeID);
- Assertions.assertNotNull(loanChargeMap.get("externalId"));
- Assertions.assertEquals(loanChargeMap.get("externalId"), externalId,
"Incorrect External Id Saved");
+ final String externalId = "extId" + loanId.toString();
+ PostLoansLoanIdChargesResponse chargeResponse = addLoanCharge(loanId,
new PostLoansLoanIdChargesRequest().chargeId(chargeDefId)
+ .amount(1.0).dueDate("22 September
2011").externalId(externalId).dateFormat("dd MMMM yyyy").locale("en"));
+ assertNotNull(chargeResponse);
+ Long chargeId = chargeResponse.getResourceId();
+ GetLoansLoanIdChargesChargeIdResponse loanCharge =
getLoanCharge(loanId, chargeId);
+ assertNotNull(loanCharge.getExternalId());
+ assertEquals(externalId, loanCharge.getExternalId(), "Incorrect
External Id Saved");
}
@Test
public void checkNewClientLoanChargeFindsDuplicateExternalId() {
- final Integer clientID = ClientHelper.createClient(this.requestSpec,
this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec,
this.responseSpec, clientID);
-
- final Integer loanProductID = createLoanProduct(false, NONE);
+ final Long loanProductId = createLoanProduct(false, NONE);
- List<HashMap> collaterals = new ArrayList<>();
- final Integer loanID = applyForLoanApplication(clientID,
loanProductID, null, null, "12,000.00", collaterals);
- HashMap loanStatusHashMap = this.loanTransactionHelper.approveLoan("20
September 2011", loanID);
- LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
- loanStatusHashMap =
this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("20 September
2011", loanID, "12,000.00");
- LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+ final Long loanId = applyForLoanApplication(clientId, loanProductId,
"12,000.00");
+ approveLoan(loanId, approveLoanRequest(12000.0, "20 September 2011"));
+ disburseLoanWithNetDisbursalAmount(loanId, "20 September 2011",
"12,000.00");
- final Integer charge = ChargesHelper.createCharges(requestSpec,
responseSpec, ChargesHelper
-
.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST,
"1", false));
+ final Long chargeDefId =
chargesHelper.createLoanSpecifiedDueDatePercentageAmountAndInterestFee(1.0).getResourceId();
- final String externalId = "extId" + loanID.toString();
- final float amount = 1.0f;
- final Integer chargeID =
this.loanTransactionHelper.addChargesForLoan(loanID,
- getLoanChargeAsJSON(String.valueOf(charge), "22 September
2011", String.valueOf(amount), externalId));
- Assertions.assertNotNull(chargeID);
+ final String externalId = "extId" + loanId.toString();
+ PostLoansLoanIdChargesResponse chargeResponse = addLoanCharge(loanId,
new PostLoansLoanIdChargesRequest().chargeId(chargeDefId)
+ .amount(1.0).dueDate("22 September
2011").externalId(externalId).dateFormat("dd MMMM yyyy").locale("en"));
+ assertNotNull(chargeResponse);
- final float amount2 = 2.0f;
- ResponseSpecification responseSpec403 = new
ResponseSpecBuilder().expectStatusCode(403).build();
- final Integer chargeID2 =
this.loanTransactionHelper.addChargesForLoan(loanID,
- getLoanChargeAsJSON(String.valueOf(charge), "23 September
2011", String.valueOf(amount2), externalId), responseSpec403);
-
- Assertions.assertNull(chargeID2);
- }
-
- private static String getLoanChargeAsJSON(final String chargeId, final
String dueDate, final String amount, final String externalId) {
- final HashMap<String, String> map = new HashMap<>();
- map.put("locale", "en_GB");
- map.put("dateFormat", "dd MMMM yyyy");
- map.put("amount", amount);
- map.put("dueDate", dueDate);
- map.put("chargeId", chargeId);
- map.put("externalId", externalId);
- String json = new Gson().toJson(map);
- LOG.info("{}", json);
- return json;
+ assertThrows(CallFailedRuntimeException.class, () ->
addLoanCharge(loanId, new PostLoansLoanIdChargesRequest().chargeId(chargeDefId)
Review Comment:
Done both , assertEquals(403, exception.getStatus()) and
assertErrorGlobalisationCode(exception,
"error.msg.loan.charge.duplicate.externalId") (confirmed the exact code against
the live server).
--
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]