taskain7 commented on code in PR #3352:
URL: https://github.com/apache/fineract/pull/3352#discussion_r1284276491


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/DateValidationTest.java:
##########
@@ -0,0 +1,237 @@
+/**
+ * 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 static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+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.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.client.models.PostClientsRequest;
+import org.apache.fineract.client.models.PostClientsResponse;
+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.accounting.AccountHelper;
+import 
org.apache.fineract.integrationtests.common.fixeddeposit.FixedDepositAccountHelper;
+import 
org.apache.fineract.integrationtests.common.fixeddeposit.FixedDepositProductHelper;
+import 
org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
+import 
org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
+import org.apache.fineract.integrationtests.interoperation.InteropHelper;
+import org.apache.fineract.interoperation.domain.InteropInitiatorType;
+import org.apache.fineract.interoperation.domain.InteropTransactionRole;
+import org.apache.fineract.interoperation.domain.InteropTransactionScenario;
+import org.apache.fineract.interoperation.util.InteropUtil;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+@Slf4j
+public class DateValidationTest {
+
+    public static final String WHOLE_TERM = "1";
+    public static final String MINIMUM_OPENING_BALANCE = "1000.0";
+    public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
+
+    private ResponseSpecification responseSpec;
+    private ResponseSpecification errorResponseSpec;
+    private RequestSpecification requestSpec;
+    private ClientHelper clientHelper;
+    private LoanTransactionHelper loanTransactionHelper;
+    private InteropHelper interopHelper;
+    private AccountHelper accountHelper;
+
+    @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.errorResponseSpec = new 
ResponseSpecBuilder().expectStatusCode(400).build();
+        this.clientHelper = new ClientHelper(this.requestSpec, 
this.responseSpec);
+        this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, 
responseSpec);
+        this.interopHelper = new InteropHelper(requestSpec, errorResponseSpec);
+        this.accountHelper = new AccountHelper(requestSpec, responseSpec);
+    }
+
+    @Test
+    public void testShouldFailIfDateIsInvalid() {
+
+        String invalidDate = "31 June 2022";
+
+        PostClientsRequest postClientsRequest = 
ClientHelper.defaultClientCreationRequest();
+
+        PostClientsResponse client = 
clientHelper.createClient(postClientsRequest);
+        Long clientId = client.getClientId();
+
+        final String loanProductJSON = new 
LoanProductTestBuilder().withPrincipal("1000").withRepaymentTypeAsMonth()
+                
.withRepaymentAfterEvery("1").withNumberOfRepayments("1").withRepaymentTypeAsMonth().withinterestRatePerPeriod("0")
+                
.withInterestRateFrequencyTypeAsMonths().withAmortizationTypeAsEqualPrincipalPayment().withInterestTypeAsDecliningBalance()
+                
.withAccountingRuleAsNone().withInterestCalculationPeriodTypeAsRepaymentPeriod(true).withDaysInMonth("30")
+                .withDaysInYear("365").withMoratorium("0", 
"0").withInArrearsTolerance("1001").withMultiDisburse()
+                .withDisallowExpectedDisbursements(true).build(null);
+        final Integer loanProductID = 
loanTransactionHelper.getLoanProductId(loanProductJSON);
+
+        loanTransactionHelper = new LoanTransactionHelper(requestSpec, 
errorResponseSpec);
+
+        final String loanApplicationJSON = new 
LoanApplicationTestBuilder().withPrincipal("1000").withLoanTermFrequency("1")
+                
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("1").withRepaymentEveryAfter("1")
+                
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("0").withInterestTypeAsFlatBalance()
+                
.withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
+                
.withExpectedDisbursementDate(invalidDate).withSubmittedOnDate("01 March 
2022").withLoanType("individual")
+                .build(clientId.toString(), loanProductID.toString(), null);
+        HashMap<String, Object> response = (HashMap) 
loanTransactionHelper.createLoanAccount(loanApplicationJSON, "");
+        List<HashMap<String, Object>> errors = (List) response.get("errors");
+        assertNotNull(errors);
+        HashMap<String, Object> error = errors.get(0);
+        assertNotNull(error);
+        assertEquals(
+                "The parameter `expectedDisbursementDate` is invalid based on 
the dateFormat: `dd MMMM uuuu` and locale: `en_GB` provided:",
+                error.get("developerMessage"));
+    }
+
+    @Test
+    public void testShouldFailWithInvalidDateTime() {
+        String requestCode = UUID.randomUUID().toString();
+        InteropTransactionRole role = InteropTransactionRole.PAYER;
+        String requestBody = buildRequestBody(requestCode, role);
+        String response = interopHelper.postTransactionRequest(requestCode, 
role, requestBody);
+        HashMap<String, Object> map = new Gson().fromJson(response, new 
TypeToken<HashMap<String, Object>>() {}.getType());
+        List<Map<String, Object>> errors = (List) map.get("errors");
+        assertNotNull(errors);
+        Map<String, Object> error = errors.get(0);
+        assertNotNull(error);
+        assertEquals("The parameter `expiration` is invalid based on the 
dateFormat: `dd MMMM uuuu HH:mm:ss` and locale: `en` provided:",
+                error.get("developerMessage"));
+    }
+
+    @Test
+    public void testShouldFailWithInvalidMonthDay() {
+        final Account assetAccount = this.accountHelper.createAssetAccount();
+        final Account incomeAccount = this.accountHelper.createIncomeAccount();
+        final Account expenseAccount = 
this.accountHelper.createExpenseAccount();
+        final Account liabilityAccount = 
this.accountHelper.createLiabilityAccount();
+
+        DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", 
Locale.US);
+        new SimpleDateFormat("dd MMM", Locale.US);
+        DateFormat currentDateFormat = new SimpleDateFormat("dd");
+
+        Calendar todaysDate = Calendar.getInstance();
+        todaysDate.add(Calendar.MONTH, -3);
+        final String VALID_FROM = dateFormat.format(todaysDate.getTime());
+        todaysDate.add(Calendar.YEAR, 10);
+        final String VALID_TO = dateFormat.format(todaysDate.getTime());
+
+        todaysDate = Calendar.getInstance();
+        todaysDate.add(Calendar.MONTH, -1);
+        final String SUBMITTED_ON_DATE = 
dateFormat.format(todaysDate.getTime());
+
+        Integer currentDate = 
Integer.valueOf(currentDateFormat.format(todaysDate.getTime()));

Review Comment:
   removed



##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/DateValidationTest.java:
##########
@@ -0,0 +1,237 @@
+/**
+ * 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 static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+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.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.client.models.PostClientsRequest;
+import org.apache.fineract.client.models.PostClientsResponse;
+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.accounting.AccountHelper;
+import 
org.apache.fineract.integrationtests.common.fixeddeposit.FixedDepositAccountHelper;
+import 
org.apache.fineract.integrationtests.common.fixeddeposit.FixedDepositProductHelper;
+import 
org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
+import 
org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
+import org.apache.fineract.integrationtests.interoperation.InteropHelper;
+import org.apache.fineract.interoperation.domain.InteropInitiatorType;
+import org.apache.fineract.interoperation.domain.InteropTransactionRole;
+import org.apache.fineract.interoperation.domain.InteropTransactionScenario;
+import org.apache.fineract.interoperation.util.InteropUtil;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+@Slf4j
+public class DateValidationTest {
+
+    public static final String WHOLE_TERM = "1";
+    public static final String MINIMUM_OPENING_BALANCE = "1000.0";
+    public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
+
+    private ResponseSpecification responseSpec;
+    private ResponseSpecification errorResponseSpec;
+    private RequestSpecification requestSpec;
+    private ClientHelper clientHelper;
+    private LoanTransactionHelper loanTransactionHelper;
+    private InteropHelper interopHelper;
+    private AccountHelper accountHelper;
+
+    @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.errorResponseSpec = new 
ResponseSpecBuilder().expectStatusCode(400).build();
+        this.clientHelper = new ClientHelper(this.requestSpec, 
this.responseSpec);
+        this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, 
responseSpec);
+        this.interopHelper = new InteropHelper(requestSpec, errorResponseSpec);
+        this.accountHelper = new AccountHelper(requestSpec, responseSpec);
+    }
+
+    @Test
+    public void testShouldFailIfDateIsInvalid() {
+
+        String invalidDate = "31 June 2022";
+
+        PostClientsRequest postClientsRequest = 
ClientHelper.defaultClientCreationRequest();
+
+        PostClientsResponse client = 
clientHelper.createClient(postClientsRequest);
+        Long clientId = client.getClientId();
+
+        final String loanProductJSON = new 
LoanProductTestBuilder().withPrincipal("1000").withRepaymentTypeAsMonth()
+                
.withRepaymentAfterEvery("1").withNumberOfRepayments("1").withRepaymentTypeAsMonth().withinterestRatePerPeriod("0")
+                
.withInterestRateFrequencyTypeAsMonths().withAmortizationTypeAsEqualPrincipalPayment().withInterestTypeAsDecliningBalance()
+                
.withAccountingRuleAsNone().withInterestCalculationPeriodTypeAsRepaymentPeriod(true).withDaysInMonth("30")
+                .withDaysInYear("365").withMoratorium("0", 
"0").withInArrearsTolerance("1001").withMultiDisburse()
+                .withDisallowExpectedDisbursements(true).build(null);
+        final Integer loanProductID = 
loanTransactionHelper.getLoanProductId(loanProductJSON);
+
+        loanTransactionHelper = new LoanTransactionHelper(requestSpec, 
errorResponseSpec);
+
+        final String loanApplicationJSON = new 
LoanApplicationTestBuilder().withPrincipal("1000").withLoanTermFrequency("1")
+                
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("1").withRepaymentEveryAfter("1")
+                
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("0").withInterestTypeAsFlatBalance()
+                
.withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
+                
.withExpectedDisbursementDate(invalidDate).withSubmittedOnDate("01 March 
2022").withLoanType("individual")
+                .build(clientId.toString(), loanProductID.toString(), null);
+        HashMap<String, Object> response = (HashMap) 
loanTransactionHelper.createLoanAccount(loanApplicationJSON, "");
+        List<HashMap<String, Object>> errors = (List) response.get("errors");
+        assertNotNull(errors);
+        HashMap<String, Object> error = errors.get(0);
+        assertNotNull(error);
+        assertEquals(
+                "The parameter `expectedDisbursementDate` is invalid based on 
the dateFormat: `dd MMMM uuuu` and locale: `en_GB` provided:",
+                error.get("developerMessage"));
+    }
+
+    @Test
+    public void testShouldFailWithInvalidDateTime() {
+        String requestCode = UUID.randomUUID().toString();
+        InteropTransactionRole role = InteropTransactionRole.PAYER;
+        String requestBody = buildRequestBody(requestCode, role);
+        String response = interopHelper.postTransactionRequest(requestCode, 
role, requestBody);
+        HashMap<String, Object> map = new Gson().fromJson(response, new 
TypeToken<HashMap<String, Object>>() {}.getType());
+        List<Map<String, Object>> errors = (List) map.get("errors");
+        assertNotNull(errors);
+        Map<String, Object> error = errors.get(0);
+        assertNotNull(error);
+        assertEquals("The parameter `expiration` is invalid based on the 
dateFormat: `dd MMMM uuuu HH:mm:ss` and locale: `en` provided:",
+                error.get("developerMessage"));
+    }
+
+    @Test
+    public void testShouldFailWithInvalidMonthDay() {
+        final Account assetAccount = this.accountHelper.createAssetAccount();
+        final Account incomeAccount = this.accountHelper.createIncomeAccount();
+        final Account expenseAccount = 
this.accountHelper.createExpenseAccount();
+        final Account liabilityAccount = 
this.accountHelper.createLiabilityAccount();
+
+        DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", 
Locale.US);
+        new SimpleDateFormat("dd MMM", Locale.US);
+        DateFormat currentDateFormat = new SimpleDateFormat("dd");
+
+        Calendar todaysDate = Calendar.getInstance();

Review Comment:
   fixed



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