Skip to content

Commit 3c471b6

Browse files
authored
Merge pull request #5760 from openMF/FINERACT-2455/working-capital-transaction-type-repayment
FINERACT-2455: WC - Transaction Type - Repayment
2 parents 4ca443f + ada62f9 commit 3c471b6

37 files changed

Lines changed: 3068 additions & 41 deletions

File tree

fineract-core/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,14 @@ public CommandWrapperBuilder updateDiscountWorkingCapitalLoanApplication(final L
872872
return this;
873873
}
874874

875+
public CommandWrapperBuilder repaymentWorkingCapitalLoanTransaction(final Long loanId) {
876+
this.actionName = ACTION_REPAYMENT;
877+
this.entityName = ENTITY_WORKINGCAPITALLOAN;
878+
this.entityId = loanId;
879+
this.href = "/working-capital-loans/" + loanId + "/transactions?command=repayment";
880+
return this;
881+
}
882+
875883
public CommandWrapperBuilder createClientIdentifier(final Long clientId) {
876884
this.actionName = ACTION_CREATE;
877885
this.entityName = ENTITY_CLIENTIDENTIFIER;

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/factory/WorkingCapitalRequestFactory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.fineract.client.models.PostPaymentAllocation;
4242
import org.apache.fineract.client.models.PostWorkingCapitalLoanProductsRequest;
4343
import org.apache.fineract.client.models.PostWorkingCapitalLoanProductsRequest.AccountingRuleEnum;
44+
import org.apache.fineract.client.models.PostWorkingCapitalLoanTransactionsRequest;
4445
import org.apache.fineract.client.models.PutWorkingCapitalLoanProductsProductIdRequest;
4546
import org.apache.fineract.client.models.WorkingCapitalBreachRequest;
4647
import org.apache.fineract.test.data.accounttype.AccountTypeResolver;
@@ -245,6 +246,12 @@ public WorkingCapitalBreachRequest defaultWorkingCapitalBreachRequest() {
245246
.breachAmount(DEFAULT_WC_BREACH_AMOUNT);
246247
}
247248

249+
public PostWorkingCapitalLoanTransactionsRequest defaultWorkingCapitalLoanRepaymentRequest() {
250+
return new PostWorkingCapitalLoanTransactionsRequest() //
251+
.dateFormat(DATE_FORMAT) //
252+
.locale(LOCALE_EN);
253+
}
254+
248255
private Long getWCDelinquencyBucketIdByName(String bucketName) {
249256
try {
250257
List<DelinquencyBucketResponse> buckets = fineractClient.delinquencyRangeAndBucketsManagement().getBuckets(Map.of());
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.test.helper;
20+
21+
import java.math.BigDecimal;
22+
import java.math.RoundingMode;
23+
import java.time.LocalDate;
24+
25+
public final class WorkingCapitalScheduleMatcher {
26+
27+
private WorkingCapitalScheduleMatcher() {}
28+
29+
public static boolean isBlank(final String value) {
30+
return value == null || value.isBlank();
31+
}
32+
33+
public static boolean matchesInteger(final Integer actual, final String expected) {
34+
if (isBlank(expected)) {
35+
return actual == null;
36+
}
37+
return actual != null && actual.equals(Integer.valueOf(expected));
38+
}
39+
40+
public static boolean matchesLong(final Long actual, final String expected) {
41+
if (isBlank(expected)) {
42+
return actual == null;
43+
}
44+
return actual != null && actual.equals(Long.valueOf(expected));
45+
}
46+
47+
public static boolean matchesDate(final LocalDate actual, final String expected) {
48+
if (isBlank(expected)) {
49+
return actual == null;
50+
}
51+
return actual != null && actual.equals(LocalDate.parse(expected));
52+
}
53+
54+
public static boolean matchesFormattedDate(final String actualFormatted, final String expected) {
55+
if (isBlank(expected)) {
56+
return actualFormatted == null;
57+
}
58+
return expected.equals(actualFormatted);
59+
}
60+
61+
public static boolean matchesDecimal(final BigDecimal actual, final String expected) {
62+
if (isBlank(expected)) {
63+
return actual == null;
64+
}
65+
if (actual == null) {
66+
return false;
67+
}
68+
return actual.compareTo(new BigDecimal(expected)) == 0;
69+
}
70+
71+
public static boolean matchesDecimalWithScale(final BigDecimal actual, final String expected, final int scale) {
72+
if (isBlank(expected)) {
73+
return actual == null;
74+
}
75+
if (actual == null) {
76+
return false;
77+
}
78+
return actual.setScale(scale, RoundingMode.HALF_UP).compareTo(new BigDecimal(expected).setScale(scale, RoundingMode.HALF_UP)) == 0;
79+
}
80+
}

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/WorkingCapitalAmortizationScheduleStepDef.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.fineract.client.models.ProjectedAmortizationScheduleData;
3636
import org.apache.fineract.client.models.ProjectedAmortizationScheduleGenerateRequest;
3737
import org.apache.fineract.client.models.ProjectedAmortizationSchedulePaymentData;
38+
import org.apache.fineract.test.helper.WorkingCapitalScheduleMatcher;
3839
import org.apache.fineract.test.stepdef.AbstractStepDef;
3940
import org.apache.fineract.test.support.TestContext;
4041
import org.apache.fineract.test.support.TestContextKey;
@@ -147,49 +148,46 @@ private void verifyPaymentDetails(final DataTable dataTable) {
147148

148149
private static void assertDecimal(final SoftAssertions assertions, final String field, final BigDecimal actual,
149150
final String expectedStr) {
150-
if (expectedStr == null || expectedStr.isBlank()) {
151+
if (WorkingCapitalScheduleMatcher.isBlank(expectedStr)) {
151152
return;
152153
}
153-
final BigDecimal expected = new BigDecimal(expectedStr);
154-
assertions.assertThat(actual).as(field).isNotNull();
155-
if (actual != null) {
156-
assertions.assertThat(actual.compareTo(expected)).as("%s: expected=%s actual=%s", field, expected, actual).isEqualTo(0);
157-
}
154+
assertions.assertThat(WorkingCapitalScheduleMatcher.matchesDecimal(actual, expectedStr))
155+
.as("%s: expected=%s actual=%s", field, expectedStr, actual).isTrue();
158156
}
159157

160158
private static void assertNullableDecimal(final SoftAssertions assertions, final String field, final BigDecimal actual,
161159
final String expectedStr) {
162-
if (expectedStr == null || expectedStr.isBlank()) {
160+
if (WorkingCapitalScheduleMatcher.isBlank(expectedStr)) {
163161
assertions.assertThat(actual).as(field + " should be null").isNull();
164162
return;
165163
}
166164
assertDecimal(assertions, field, actual, expectedStr);
167165
}
168166

169167
private static void assertInt(final SoftAssertions assertions, final String field, final Integer actual, final String expectedStr) {
170-
if (expectedStr == null || expectedStr.isBlank()) {
168+
if (WorkingCapitalScheduleMatcher.isBlank(expectedStr)) {
171169
return;
172170
}
173-
assertions.assertThat(actual).as(field).isEqualTo(Integer.parseInt(expectedStr));
171+
assertions.assertThat(WorkingCapitalScheduleMatcher.matchesInteger(actual, expectedStr)).as(field).isTrue();
174172
}
175173

176174
private static void assertLong(final SoftAssertions assertions, final String field, final Long actual, final String expectedStr) {
177-
if (expectedStr == null || expectedStr.isBlank()) {
175+
if (WorkingCapitalScheduleMatcher.isBlank(expectedStr)) {
178176
return;
179177
}
180-
assertions.assertThat(actual).as(field).isEqualTo(Long.parseLong(expectedStr));
178+
assertions.assertThat(WorkingCapitalScheduleMatcher.matchesLong(actual, expectedStr)).as(field).isTrue();
181179
}
182180

183181
private static void assertDate(final SoftAssertions assertions, final String field, final LocalDate actual, final String expectedStr) {
184-
if (expectedStr == null || expectedStr.isBlank()) {
182+
if (WorkingCapitalScheduleMatcher.isBlank(expectedStr)) {
185183
return;
186184
}
187-
assertions.assertThat(actual).as(field).isEqualTo(LocalDate.parse(expectedStr));
185+
assertions.assertThat(WorkingCapitalScheduleMatcher.matchesDate(actual, expectedStr)).as(field).isTrue();
188186
}
189187

190188
private static void assertOptionalDecimal(final SoftAssertions assertions, final String field, final BigDecimal actual,
191189
final String expectedStr) {
192-
if (expectedStr == null || expectedStr.isBlank()) {
190+
if (WorkingCapitalScheduleMatcher.isBlank(expectedStr)) {
193191
assertions.assertThat(actual).as(field + " should not be null").isNotNull();
194192
return;
195193
}

0 commit comments

Comments
 (0)