DeathGun44 commented on code in PR #6084:
URL: https://github.com/apache/fineract/pull/6084#discussion_r3535500585
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanReschedulingWithinCenterTest.java:
##########
@@ -19,382 +19,279 @@
package org.apache.fineract.integrationtests;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.google.gson.Gson;
-import io.restassured.builder.RequestSpecBuilder;
-import io.restassured.builder.ResponseSpecBuilder;
-import io.restassured.http.ContentType;
-import io.restassured.path.json.JsonPath;
-import io.restassured.specification.RequestSpecification;
-import io.restassured.specification.ResponseSpecification;
+import com.google.gson.JsonObject;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
+import java.time.Month;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
+import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
+import org.apache.fineract.client.models.GetLoansLoanIdResponse;
+import org.apache.fineract.client.models.PostClientsRequest;
+import org.apache.fineract.client.models.PostLoansDisbursementData;
+import org.apache.fineract.integrationtests.client.feign.FeignLoanTestBase;
+import
org.apache.fineract.integrationtests.client.feign.helpers.FeignGroupCenterHelper;
+import
org.apache.fineract.integrationtests.client.feign.helpers.FeignOfficeHelper;
+import
org.apache.fineract.integrationtests.client.feign.modules.LoanRequestBuilders;
+import org.apache.fineract.integrationtests.client.feign.modules.LoanTestData;
import org.apache.fineract.integrationtests.common.CalendarHelper;
-import org.apache.fineract.integrationtests.common.CenterDomain;
-import org.apache.fineract.integrationtests.common.CenterHelper;
-import org.apache.fineract.integrationtests.common.ClientHelper;
-import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
-import org.apache.fineract.integrationtests.common.GroupHelper;
-import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.Utils;
-import org.apache.fineract.integrationtests.common.accounting.Account;
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.LoanTransactionHelper;
-import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class LoanReschedulingWithinCenterTest extends BaseLoanIntegrationTest {
+public class LoanReschedulingWithinCenterTest extends FeignLoanTestBase {
private static final Logger LOG =
LoggerFactory.getLogger(LoanReschedulingWithinCenterTest.class);
- private RequestSpecification requestSpec;
- private ResponseSpecification responseSpec;
- private LoanTransactionHelper loanTransactionHelper;
- private ResponseSpecification generalResponseSpec;
- private LoanApplicationApprovalTest loanApplicationApprovalTest;
-
- @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.requestSpec.header("Fineract-Platform-TenantId", "default");
- this.loanTransactionHelper = new
LoanTransactionHelper(this.requestSpec, this.responseSpec);
- this.loanApplicationApprovalTest = new LoanApplicationApprovalTest();
- this.generalResponseSpec = new ResponseSpecBuilder().build();
-
- globalConfigurationHelper.verifyAllDefaultGlobalConfigurations();
- }
+ private static final Long LEGAL_FORM_PERSON = 1L;
- @SuppressWarnings("rawtypes")
@Test
public void testCenterReschedulingLoansWithInterestRecalculationEnabled() {
-
- Integer officeId = new OfficeHelper().createOffice(LocalDate.of(2007,
7, 1)).getResourceId().intValue();
+ Long officeId = new
FeignOfficeHelper(fineractClient()).createOffice(LocalDate.of(2007, Month.JULY,
1)).getResourceId();
String name = "TestFullCreation" + new Timestamp(new
java.util.Date().getTime());
String externalId = UUID.randomUUID().toString();
- int staffId = StaffHelper.createStaff(requestSpec, responseSpec);
- int[] groupMembers = generateGroupMembers(1, officeId);
+ int staffId =
FeignGroupCenterHelper.createStaff(officeId.intValue()).intValue();
+ long groupId = FeignGroupCenterHelper.createGroup(officeId.intValue());
final String centerActivationDate = "01 July 2007";
- Integer centerId = CenterHelper.createCenter(name, officeId,
externalId, staffId, groupMembers, centerActivationDate, requestSpec,
- responseSpec);
- CenterDomain center = CenterHelper.retrieveByID(centerId, requestSpec,
responseSpec);
- Integer groupId = groupMembers[0];
- Assertions.assertNotNull(center);
- Assertions.assertTrue(center.getStaffId() == staffId);
- Assertions.assertTrue(center.isActive() == true);
+ Long centerId = FeignGroupCenterHelper.createCenter(name,
officeId.intValue(), externalId, staffId, new long[] { groupId },
+ centerActivationDate);
+ JsonObject center = FeignGroupCenterHelper.retrieveCenter(centerId);
+ assertNotNull(center);
+ assertEquals(staffId, center.get("staffId").getAsInt());
+ assertTrue(center.get("active").getAsBoolean());
Long calendarId = createCalendarMeeting(centerId);
- Integer clientId = createClient(officeId);
+ Long clientId = createClient(officeId.intValue(), "01 July 2014");
- associateClientsToGroup(groupId, clientId);
+ FeignGroupCenterHelper.associateClientToGroup(groupId, clientId);
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy",
Locale.US);
dateFormat.setTimeZone(Utils.getTimeZoneOfTenant());
Calendar today = Calendar.getInstance(Utils.getTimeZoneOfTenant());
today.add(Calendar.DAY_OF_MONTH, -14);
- // CREATE A LOAN PRODUCT
final String disbursalDate = dateFormat.format(today.getTime());
final String recalculationRestFrequencyDate = "01 January 2012";
final boolean isMultiTrancheLoan = false;
- List<HashMap> collaterals = new ArrayList<>();
+ Long collateralId = FeignGroupCenterHelper.createCollateralProduct();
+ assertNotNull(collateralId);
+ Long clientCollateralId =
FeignGroupCenterHelper.createClientCollateral(clientId, collateralId);
+ assertNotNull(clientCollateralId);
- final Integer collateralId =
CollateralManagementHelper.createCollateralProduct(this.requestSpec,
this.responseSpec);
- Assertions.assertNotNull(collateralId);
- final Integer clientCollateralId =
CollateralManagementHelper.createClientCollateral(this.requestSpec,
this.responseSpec,
- String.valueOf(clientId), collateralId);
- Assertions.assertNotNull(clientCollateralId);
- addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+ List<HashMap> collaterals = new ArrayList<>();
+ collaterals.add(collateral(clientCollateralId.intValue(),
BigDecimal.valueOf(1)));
- // CREATE LOAN MULTIDISBURSAL PRODUCT WITH INTEREST RECALCULATION
- final Integer loanProductID =
createLoanProductWithInterestRecalculation(LoanProductTestBuilder.RBI_INDIA_STRATEGY,
+ Long loanProductId =
createLoanProductWithInterestRecalculation(LoanProductTestBuilder.RBI_INDIA_STRATEGY,
LoanProductTestBuilder.RECALCULATION_COMPOUNDING_METHOD_NONE,
LoanProductTestBuilder.RECALCULATION_STRATEGY_REDUCE_NUMBER_OF_INSTALLMENTS,
LoanProductTestBuilder.RECALCULATION_FREQUENCY_TYPE_DAILY,
"0", recalculationRestFrequencyDate,
-
LoanProductTestBuilder.INTEREST_APPLICABLE_STRATEGY_ON_PRE_CLOSE_DATE, null,
isMultiTrancheLoan, null, null);
+
LoanProductTestBuilder.INTEREST_APPLICABLE_STRATEGY_ON_PRE_CLOSE_DATE,
isMultiTrancheLoan);
- // APPLY FOR TRANCHE LOAN WITH INTEREST RECALCULATION
- final Integer loanId =
applyForLoanApplicationForInterestRecalculation(clientId, groupId, calendarId,
loanProductID, disbursalDate,
- recalculationRestFrequencyDate,
LoanApplicationTestBuilder.RBI_INDIA_STRATEGY, new ArrayList<HashMap>(0), null,
- collaterals);
+ Long loanId =
applyForLoanApplicationForInterestRecalculation(clientId, groupId, calendarId,
loanProductId, disbursalDate,
+ recalculationRestFrequencyDate,
LoanApplicationTestBuilder.RBI_INDIA_STRATEGY, collaterals);
- // Test for loan account is created
- Assertions.assertNotNull(loanId);
- HashMap loanStatusHashMap =
LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanId);
+ assertNotNull(loanId);
+ verifyLoanStatus(loanId, LoanStatus.SUBMITTED_AND_PENDING_APPROVAL);
- // Test for loan account is created, can be approved
- this.loanTransactionHelper.approveLoan(disbursalDate, loanId);
- loanStatusHashMap =
LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanId);
- LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ approveLoan(loanId, approveLoanRequest(10000.0, disbursalDate));
+ verifyLoanStatus(loanId, LoanStatus.APPROVED);
- // Test for loan account approved can be disbursed
- String loanDetails =
this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec,
loanId);
-
this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount(disbursalDate,
loanId,
-
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
- loanStatusHashMap =
LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanId);
- LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+ GetLoansLoanIdResponse approvedLoan = getLoanDetails(loanId);
+ disburseLoanWithNetDisbursalAmount(loanId, disbursalDate,
approvedLoan.getNetDisbursalAmount().toPlainString());
+ verifyLoanStatus(loanId, LoanStatus.ACTIVE);
LOG.info("---------------------------------CHANGING GROUP MEETING DATE
------------------------------------------");
- Calendar todaysdate =
Calendar.getInstance(Utils.getTimeZoneOfTenant());
- todaysdate.add(Calendar.DAY_OF_MONTH, 14);
- String oldMeetingDate = dateFormat.format(todaysdate.getTime());
- todaysdate.add(Calendar.DAY_OF_MONTH, 1);
- final String centerMeetingNewStartDate =
dateFormat.format(todaysdate.getTime());
- CalendarHelper.updateMeetingCalendarForCenter(centerId.longValue(),
calendarId.toString(), oldMeetingDate,
- centerMeetingNewStartDate);
-
- ArrayList loanRepaymnetSchedule =
this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec,
generalResponseSpec, loanId);
- // VERIFY RESCHEDULED DATE
- ArrayList dueDateLoanSchedule = (ArrayList) ((HashMap)
loanRepaymnetSchedule.get(2)).get("dueDate");
- assertEquals(getDateAsArray(todaysdate, 0), dueDateLoanSchedule);
-
- // VERIFY THE INTEREST
- Float interestDue = (Float) ((HashMap)
loanRepaymnetSchedule.get(2)).get("interestDue");
- assertEquals("90.82", String.valueOf(interestDue));
- }
-
- private void addCollaterals(List<HashMap> collaterals, Integer
collateralId, BigDecimal amount) {
- collaterals.add(collaterals(collateralId, amount));
- }
-
- private HashMap<String, String> collaterals(Integer collateralId,
BigDecimal amount) {
- HashMap<String, String> collateral = new HashMap<String, String>(1);
- collateral.put("clientCollateralId", collateralId.toString());
- collateral.put("amount", amount.toString());
- return collateral;
- }
-
- private void associateClientsToGroup(Integer groupId, Integer clientId) {
- // Associate client to the group
- GroupHelper.associateClient(this.requestSpec, this.responseSpec,
groupId.toString(), clientId.toString());
- GroupHelper.verifyGroupMembers(this.requestSpec, this.responseSpec,
groupId, clientId);
+ Calendar rescheduledDate =
Calendar.getInstance(Utils.getTimeZoneOfTenant());
+ rescheduledDate.add(Calendar.DAY_OF_MONTH, 14);
+ String oldMeetingDate = dateFormat.format(rescheduledDate.getTime());
+ rescheduledDate.add(Calendar.DAY_OF_MONTH, 1);
+ final String centerMeetingNewStartDate =
dateFormat.format(rescheduledDate.getTime());
+ CalendarHelper.updateMeetingCalendarForCenter(centerId,
calendarId.toString(), oldMeetingDate, centerMeetingNewStartDate);
+
+ GetLoansLoanIdResponse loanDetails = getLoanDetails(loanId);
+ GetLoansLoanIdRepaymentPeriod installment =
loanDetails.getRepaymentSchedule().getPeriods().get(2);
+ assertEquals(toLocalDate(rescheduledDate), installment.getDueDate());
+ assertEquals(0, new
BigDecimal("90.82").compareTo(installment.getInterestDue()));
}
- private Integer createClient(Integer officeId) {
- // CREATE CLIENT
- final String clientActivationDate = "01 July 2014";
- Integer clientId = ClientHelper.createClient(this.requestSpec,
this.responseSpec, clientActivationDate, officeId.toString());
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec,
this.responseSpec, clientId);
- return clientId;
- }
-
- private Long createCalendarMeeting(Integer centerId) {
- DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy",
Locale.US);
- dateFormat.setTimeZone(Utils.getTimeZoneOfTenant());
- Calendar today = Calendar.getInstance(Utils.getTimeZoneOfTenant());
- final String startDate = dateFormat.format(today.getTime());
- final String frequency = "2"; // 2:Weekly
- final String interval = "2"; // Every one week
- Integer repeatsOnDay = today.get(Calendar.DAY_OF_WEEK) - 1;
-
- if (repeatsOnDay.intValue() == 0) {
- repeatsOnDay = 7;
- }
-
- Long calendarId = CalendarHelper
- .createMeetingForGroup(centerId.longValue(), startDate,
frequency, interval, repeatsOnDay.toString()).getResourceId();
- LOG.info("calendarId {}", calendarId);
- return calendarId;
- }
-
- @SuppressWarnings("rawtypes")
@Test
public void
testCenterReschedulingMultiTrancheLoansWithInterestRecalculationEnabled() {
-
- Integer officeId = new OfficeHelper().createOffice(LocalDate.of(2007,
7, 1)).getResourceId().intValue();
+ Long officeId = new
FeignOfficeHelper(fineractClient()).createOffice(LocalDate.of(2007, Month.JULY,
1)).getResourceId();
Review Comment:
Moved it out of both test bodies into a private static FeignOfficeHelper
officeHelper initialised in @BeforeAll.
--
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]