adamsaghy commented on code in PR #3544:
URL: https://github.com/apache/fineract/pull/3544#discussion_r1375230217


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargePaymentWithAdvancedPaymentAllocationTest.java:
##########
@@ -0,0 +1,325 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.integrationtests;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+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.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.fineract.client.models.AdvancedPaymentData;
+import org.apache.fineract.client.models.BusinessDateRequest;
+import org.apache.fineract.client.models.PaymentAllocationOrder;
+import org.apache.fineract.client.models.PostClientsResponse;
+import org.apache.fineract.client.models.PostLoansLoanIdRequest;
+import org.apache.fineract.client.models.PostLoansRequest;
+import org.apache.fineract.client.models.PostLoansResponse;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
+import org.apache.fineract.integrationtests.common.BusinessDateHelper;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.CommonConstants;
+import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
+import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.apache.fineract.integrationtests.common.accounting.Account;
+import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
+import 
org.apache.fineract.integrationtests.common.accounting.PeriodicAccrualAccountingHelper;
+import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
+import 
org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
+import 
org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
+import 
org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
+import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
+import 
org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
+import 
org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
+import 
org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
+import 
org.apache.fineract.portfolio.loanaccount.domain.transactionprocessor.impl.AdvancedPaymentScheduleTransactionProcessor;
+import org.apache.fineract.portfolio.loanproduct.domain.PaymentAllocationType;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@ExtendWith(LoanTestLifecycleExtension.class)
+public class LoanChargePaymentWithAdvancedPaymentAllocationTest {
+
+    private static final String DATETIME_PATTERN = "dd MMMM yyyy";
+    private static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
+    private static final String MINIMUM_OPENING_BALANCE = "1000.0";
+    private static final String DEPOSIT_AMOUNT = "7000";
+    private static final Logger LOG = 
LoggerFactory.getLogger(LoanSpecificDueDateChargeAfterMaturityTest.class);
+    private static final String DATE_OF_JOINING = "01 January 2011";
+    private static final Float LP_PRINCIPAL = 10000.0f;
+    private static final String LP_REPAYMENTS = "1";
+    private static final String LP_REPAYMENT_PERIOD = "1";
+    private static final String EXPECTED_DISBURSAL_DATE = "04 March 2011";
+    private static final String LOAN_APPLICATION_SUBMISSION_DATE = "03 March 
2011";
+    private static final String LOAN_TERM_FREQUENCY = "1";
+    private static final String INDIVIDUAL_LOAN = "individual";
+    private static final BusinessDateHelper BUSINESS_DATE_HELPER = new 
BusinessDateHelper();
+    private static final DateTimeFormatter DATE_FORMATTER = new 
DateTimeFormatterBuilder().appendPattern(DATETIME_PATTERN).toFormatter();
+    private static RequestSpecification requestSpec;
+    private static ResponseSpecification responseSpec;
+    private static LoanTransactionHelper loanTransactionHelper;
+    private static AccountHelper accountHelper;
+    private static PeriodicAccrualAccountingHelper 
periodicAccrualAccountingHelper;
+    private static Integer commonLoanProductId;
+    private static PostClientsResponse client;
+    private static BusinessDateHelper businessDateHelper;
+    private static SchedulerJobHelper scheduleJobHelper;
+    private static SavingsAccountHelper savingsAccountHelper;
+    private static SavingsProductHelper savingsProductHelper;
+
+    @BeforeAll
+    public static void setup() {
+        Utils.initializeRESTAssured();
+        ClientHelper clientHelper = new ClientHelper(requestSpec, 
responseSpec);
+        requestSpec = new 
RequestSpecBuilder().setContentType(ContentType.JSON).build();
+        requestSpec.header("Authorization", "Basic " + 
Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+        requestSpec.header("Fineract-Platform-TenantId", "default");
+        responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+
+        loanTransactionHelper = new LoanTransactionHelper(requestSpec, 
responseSpec);
+        accountHelper = new AccountHelper(requestSpec, responseSpec);
+        periodicAccrualAccountingHelper = new 
PeriodicAccrualAccountingHelper(requestSpec, responseSpec);
+        final Account assetAccount = accountHelper.createAssetAccount();
+        final Account incomeAccount = accountHelper.createIncomeAccount();
+        final Account expenseAccount = accountHelper.createExpenseAccount();
+        final Account overpaymentAccount = 
accountHelper.createLiabilityAccount();
+        client = 
clientHelper.createClient(ClientHelper.defaultClientCreationRequest());
+        businessDateHelper = new BusinessDateHelper();
+        scheduleJobHelper = new SchedulerJobHelper(requestSpec);
+        savingsAccountHelper = new SavingsAccountHelper(requestSpec, 
responseSpec);
+        savingsProductHelper = new SavingsProductHelper();
+        commonLoanProductId = createLoanProduct("500", "15", "4", 
assetAccount, incomeAccount, expenseAccount, overpaymentAccount);
+    }
+
+    @Test
+    public void chargePaymentWithDefaultAllocationRuleTest() {
+        ;
+        final Account assetAccount = accountHelper.createAssetAccount();
+        final Account incomeAccount = accountHelper.createIncomeAccount();
+        final Account expenseAccount = accountHelper.createExpenseAccount();
+        final Account overpaymentAccount = 
accountHelper.createLiabilityAccount();
+
+        final String jobName = "Transfer Fee For Loans From Savings";
+        final String startDate = "10 April 2022";
+
+        GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, 
responseSpec, Boolean.TRUE);
+        businessDateHelper.updateBusinessDate(new 
BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()).date("2023.02.15")
+                .dateFormat("yyyy.MM.dd").locale("en"));
+
+        final Integer savingsId = 
createSavingsAccountDailyPosting(client.getClientId().intValue(), startDate);
+
+        savingsAccountHelper.depositToSavingsAccount(savingsId, "10000", 
startDate, CommonConstants.RESPONSE_RESOURCE_ID);
+
+        final PostLoansResponse loanResponse = 
applyForLoanApplication(client.getClientId(), commonLoanProductId, 1000L, 45, 
15, 3, 0,
+                "01 January 2023", "01 January 2023");
+
+        int loanId = loanResponse.getLoanId().intValue();
+
+        loanTransactionHelper.updateLoan(loanId,
+                updateLoanJson(client.getClientId().intValue(), 
commonLoanProductId, savingsId.toString()));
+
+        loanTransactionHelper.approveLoan(loanResponse.getLoanId(), new 
PostLoansLoanIdRequest()
+                
.approvedLoanAmount(BigDecimal.valueOf(1000)).dateFormat(DATETIME_PATTERN).approvedOnDate("01
 January 2023").locale("en"));
+
+        loanTransactionHelper.disburseLoan(loanResponse.getLoanId(), new 
PostLoansLoanIdRequest().actualDisbursementDate("01 January 2023")
+                
.dateFormat(DATETIME_PATTERN).transactionAmount(BigDecimal.valueOf(1000.00)).locale("en"));
+
+        final float feePortion = 50.0f;
+        final float penaltyPortion = 100.0f;
+
+        Integer flat = ChargesHelper.createCharges(requestSpec, responseSpec,
+                
ChargesHelper.getLoanSpecifiedDueDateWithAccountTransferJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT,
 "100", false));
+
+        LocalDate targetDate = LocalDate.of(2011, 3, 4);
+
+        String loanDetails = loanTransactionHelper.getLoanDetails(requestSpec, 
responseSpec, loanId);

Review Comment:
   Please use the fineract-client to retrieve the loan details. This way you 
got the details in a type-safe way.



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