Skip to content

Commit 45eee33

Browse files
peter-kovacs-dpcruzeynalov
authored andcommitted
FINERACT-2455: WC - Loan account CRUD - E2E tests
Co-authored-by: Peter Kovacs <peter.kovacs@dpc.hu> Co-authored-by: Rustam Zeinalov <truezeynalov@gmail.com>
1 parent b1c6c4f commit 45eee33

7 files changed

Lines changed: 1119 additions & 5 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.data.workingcapitalproduct;
20+
21+
import static org.apache.fineract.client.feign.util.FeignCalls.ok;
22+
23+
import java.util.List;
24+
import java.util.Map;
25+
import lombok.RequiredArgsConstructor;
26+
import lombok.extern.slf4j.Slf4j;
27+
import org.apache.fineract.client.feign.FineractFeignClient;
28+
import org.apache.fineract.client.models.GetWorkingCapitalLoanProductsResponse;
29+
import org.springframework.stereotype.Component;
30+
31+
@Component
32+
@RequiredArgsConstructor
33+
@Slf4j
34+
public class WorkingCapitalLoanProductResolver {
35+
36+
private final FineractFeignClient fineractClient;
37+
38+
public long resolve(WorkingCapitalLoanProduct workingCapitalLoanProduct) {
39+
String productName = workingCapitalLoanProduct.getName();
40+
log.debug("Resolving working capital loan product by name [{}]", productName);
41+
List<GetWorkingCapitalLoanProductsResponse> productResponses = ok(
42+
() -> fineractClient.workingCapitalLoanProducts().retrieveAllWorkingCapitalLoanProducts(Map.of()));
43+
44+
GetWorkingCapitalLoanProductsResponse foundProduct = productResponses.stream()
45+
.filter(product -> productName.equals(product.getName())).findAny()
46+
.orElseThrow(() -> new IllegalArgumentException("Working capital loan product [%s] not found".formatted(productName)));
47+
return foundProduct.getId();
48+
}
49+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.factory;
20+
21+
import java.math.BigDecimal;
22+
import java.time.format.DateTimeFormatter;
23+
import lombok.RequiredArgsConstructor;
24+
import org.apache.fineract.client.models.PostWorkingCapitalLoansRequest;
25+
import org.apache.fineract.client.models.PutWorkingCapitalLoansLoanIdRequest;
26+
import org.apache.fineract.test.data.workingcapitalproduct.DefaultWorkingCapitalLoanProduct;
27+
import org.apache.fineract.test.data.workingcapitalproduct.WorkingCapitalLoanProductResolver;
28+
import org.apache.fineract.test.helper.Utils;
29+
import org.springframework.stereotype.Component;
30+
31+
@Component
32+
@RequiredArgsConstructor
33+
public class WorkingCapitalLoanRequestFactory {
34+
35+
private final WorkingCapitalLoanProductResolver workingCapitalLoanProductResolver;
36+
37+
public static final String DATE_FORMAT = "dd MMMM yyyy";
38+
public static final String DEFAULT_LOCALE = "en";
39+
public static final DefaultWorkingCapitalLoanProduct DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT = DefaultWorkingCapitalLoanProduct.WCLP;
40+
public static final BigDecimal DEFAULT_PRINCIPAL = new BigDecimal(100);
41+
public static final BigDecimal DEFAULT_TOTAL_PAYMENT = new BigDecimal(100);
42+
public static final BigDecimal DEFAULT_PERIOD_PAYMENT_RATE = new BigDecimal(1);
43+
public static final BigDecimal DEFAULT_DISCOUNT = BigDecimal.ZERO;
44+
45+
public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(DATE_FORMAT);
46+
public static final String DATE_SUBMIT_STRING = FORMATTER.format(Utils.now().minusMonths(1L));
47+
48+
public PostWorkingCapitalLoansRequest defaultWorkingCapitalLoansRequest(Long clientId) {
49+
return new PostWorkingCapitalLoansRequest()//
50+
.clientId(clientId)//
51+
.productId(workingCapitalLoanProductResolver.resolve(DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT))//
52+
.submittedOnDate(DATE_SUBMIT_STRING)//
53+
.expectedDisbursementDate(DATE_SUBMIT_STRING)//
54+
.principalAmount(DEFAULT_PRINCIPAL)//
55+
.totalPayment(DEFAULT_TOTAL_PAYMENT)//
56+
.periodPaymentRate(DEFAULT_PERIOD_PAYMENT_RATE)//
57+
.discount(DEFAULT_DISCOUNT)//
58+
.locale(DEFAULT_LOCALE)//
59+
.dateFormat(DATE_FORMAT);//
60+
}
61+
62+
public PutWorkingCapitalLoansLoanIdRequest defaultModifyWorkingCapitalLoansRequest() {
63+
return new PutWorkingCapitalLoansLoanIdRequest()//
64+
.locale(DEFAULT_LOCALE)//
65+
.dateFormat(DATE_FORMAT);//
66+
}
67+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public PutWorkingCapitalLoanProductsProductIdRequest defaultWorkingCapitalLoanPr
8787
String shortName = loanProductsRequestFactory.generateShortNameSafely();
8888

8989
PostAllowAttributeOverrides allowAttributeOverrides = new PostAllowAttributeOverrides().delinquencyBucketClassification(true)
90-
.discountDefault(false).flatPercentageAmount(true).periodPaymentFrequencyType(false).periodPaymentFrequency(true);
90+
.discountDefault(false).periodPaymentFrequencyType(false).periodPaymentFrequency(true);
9191

9292
return new PutWorkingCapitalLoanProductsProductIdRequest()//
9393
.name(name)//

0 commit comments

Comments
 (0)