Skip to content

Commit 4a02c26

Browse files
committed
FINERACT-2421: Fix flaky guarantor test
1 parent 93f5292 commit 4a02c26

File tree

5 files changed

+173
-98
lines changed

5 files changed

+173
-98
lines changed

integration-tests/src/test/java/org/apache/fineract/integrationtests/BaseLoanIntegrationTest.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
import org.apache.fineract.client.models.PostLoansResponse;
8585
import org.apache.fineract.client.models.PostRolesRequest;
8686
import org.apache.fineract.client.models.PostUsersRequest;
87-
import org.apache.fineract.client.models.PutGlobalConfigurationsRequest;
8887
import org.apache.fineract.client.models.PutLoanProductsProductIdRequest;
8988
import org.apache.fineract.client.models.PutLoansApprovedAmountRequest;
9089
import org.apache.fineract.client.models.PutLoansApprovedAmountResponse;
@@ -96,13 +95,10 @@
9695
import org.apache.fineract.client.util.CallFailedRuntimeException;
9796
import org.apache.fineract.client.util.Calls;
9897
import org.apache.fineract.client.util.FineractClient;
99-
import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants;
10098
import org.apache.fineract.infrastructure.event.external.data.ExternalEventResponse;
10199
import org.apache.fineract.integrationtests.client.IntegrationTest;
102100
import org.apache.fineract.integrationtests.common.BatchHelper;
103-
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
104101
import org.apache.fineract.integrationtests.common.ClientHelper;
105-
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
106102
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
107103
import org.apache.fineract.integrationtests.common.Utils;
108104
import org.apache.fineract.integrationtests.common.accounting.Account;
@@ -138,9 +134,6 @@
138134
@ExtendWith({ LoanTestLifecycleExtension.class, ExternalEventsExtension.class })
139135
public abstract class BaseLoanIntegrationTest extends IntegrationTest {
140136

141-
protected static final String DATETIME_PATTERN = "dd MMMM yyyy";
142-
protected static final String LOCALE = "en";
143-
144137
static {
145138
Utils.initializeRESTAssured();
146139
}
@@ -184,9 +177,7 @@ public abstract class BaseLoanIntegrationTest extends IntegrationTest {
184177
protected final InlineLoanCOBHelper inlineLoanCOBHelper = new InlineLoanCOBHelper(requestSpec, responseSpec);
185178
protected final LoanAccountLockHelper loanAccountLockHelper = new LoanAccountLockHelper(requestSpec,
186179
createResponseSpecification(Matchers.is(202)));
187-
protected BusinessDateHelper businessDateHelper = new BusinessDateHelper();
188180
protected DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATETIME_PATTERN);
189-
protected GlobalConfigurationHelper globalConfigurationHelper = new GlobalConfigurationHelper();
190181
protected final CodeHelper codeHelper = new CodeHelper();
191182
protected final ChargesHelper chargesHelper = new ChargesHelper();
192183
protected final ExternalEventHelper externalEventHelper = new ExternalEventHelper();
@@ -1331,19 +1322,6 @@ protected void runFromToInclusive(String fromDate, String toDate, Runnable runna
13311322
}
13321323
}
13331324

1334-
protected void runAt(String date, Runnable runnable) {
1335-
try {
1336-
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
1337-
new PutGlobalConfigurationsRequest().enabled(true));
1338-
businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE)
1339-
.date(date).dateFormat(DATETIME_PATTERN).locale("en"));
1340-
runnable.run();
1341-
} finally {
1342-
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
1343-
new PutGlobalConfigurationsRequest().enabled(false));
1344-
}
1345-
}
1346-
13471325
protected void runAsNonByPass(Runnable runnable) {
13481326
RequestSpecificationImpl requestSpecImpl = (RequestSpecificationImpl) requestSpec;
13491327
try {

integration-tests/src/test/java/org/apache/fineract/integrationtests/GroupSavingsIntegrationTest.java

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.fineract.integrationtests;
2020

21+
import static org.apache.fineract.integrationtests.common.BusinessDateHelper.runAt;
2122
import static org.junit.jupiter.api.Assertions.assertEquals;
2223

2324
import io.restassured.builder.RequestSpecBuilder;
@@ -55,7 +56,6 @@
5556
import org.apache.fineract.integrationtests.guarantor.GuarantorTestBuilder;
5657
import org.junit.jupiter.api.Assertions;
5758
import org.junit.jupiter.api.BeforeEach;
58-
import org.junit.jupiter.api.Disabled;
5959
import org.junit.jupiter.api.Test;
6060
import org.junit.jupiter.api.extension.ExtendWith;
6161
import org.slf4j.Logger;
@@ -903,7 +903,6 @@ private Map<String, Object> savingsArray(final Long paymentId, final Integer sav
903903
* </ul>
904904
*/
905905
@Test
906-
@Disabled("Using GROUP as Client guarantor causes issues... need to be fixed to support GROUP as guarantor")
907906
public void testOnHoldTransactionsApiForGroupSavingsAccount() {
908907
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
909908

@@ -1076,52 +1075,57 @@ public void testGroupGuarantorWithInvalidGroupId() {
10761075
*/
10771076
@Test
10781077
public void testGroupGuarantorWithClientIdButGroupType() {
1079-
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
1080-
1081-
// Create TWO clients - one for loan, one to misuse as "group"
1082-
final Integer loanClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
1083-
Assertions.assertNotNull(loanClientID);
1084-
1085-
final Integer otherClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
1086-
Assertions.assertNotNull(otherClientID);
1087-
1088-
// Create savings account for the other client
1089-
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, null, null,
1090-
"false");
1091-
final Integer clientSavingsId = this.savingsAccountHelper.applyForSavingsApplication(otherClientID, savingsProductID, "INDIVIDUAL");
1092-
this.savingsAccountHelper.approveSavings(clientSavingsId);
1093-
this.savingsAccountHelper.activateSavings(clientSavingsId);
1094-
1095-
// Create loan product
1096-
LoanProductTestBuilder loanProductBuilder = new LoanProductTestBuilder().withPrincipal(PRINCIPAL).withNumberOfRepayments("4")
1097-
.withRepaymentAfterEvery("1").withRepaymentTypeAsWeek().withinterestRatePerPeriod("2")
1098-
.withInterestRateFrequencyTypeAsMonths().withAmortizationTypeAsEqualPrincipalPayment().withInterestTypeAsDecliningBalance()
1099-
.withOnHoldFundDetails("0", "0", "0");
1100-
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(loanProductBuilder.build(null));
1101-
1102-
// Create loan
1103-
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(PRINCIPAL).withLoanTermFrequency("4")
1104-
.withLoanTermFrequencyAsWeeks().withNumberOfRepayments("4").withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsWeeks()
1105-
.withInterestRatePerPeriod("2").withAmortizationTypeAsEqualInstallments().withInterestTypeAsDecliningBalance()
1106-
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod().withSubmittedOnDate(SavingsAccountHelper.TRANSACTION_DATE)
1107-
.withExpectedDisbursementDate(SavingsAccountHelper.TRANSACTION_DATE)
1108-
.build(loanClientID.toString(), loanProductID.toString(), null);
1109-
final Integer loanID = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
1110-
1111-
// Try to create guarantor with CLIENT ID but GROUP type (type mismatch)
1112-
String guarantorJSON = new GuarantorTestBuilder()
1113-
.existingGroupWithGuaranteeAmount(String.valueOf(otherClientID), String.valueOf(clientSavingsId), GUARANTEE_AMOUNT).build();
1114-
1115-
final ResponseSpecification errorResponse = new ResponseSpecBuilder().build();
1116-
final RequestSpecification errorRequest = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
1117-
errorRequest.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
1118-
1119-
ArrayList<HashMap> error = (ArrayList<HashMap>) this.guarantorHelper.createGuarantorWithError(loanID, guarantorJSON, errorRequest,
1120-
errorResponse);
1121-
// Verify we got an error response (status code may be 403 or 404 depending on environment)
1122-
Assertions.assertNotNull(error, "Should return error for client ID used with GROUP type");
1123-
1124-
LOG.info("SUCCESS: Client ID with GROUP type correctly rejected");
1078+
runAt("01 January 2023", () -> {
1079+
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
1080+
1081+
// Create TWO clients - one for loan, one to misuse as "group"
1082+
final Integer loanClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
1083+
Assertions.assertNotNull(loanClientID);
1084+
1085+
final Integer otherClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
1086+
Assertions.assertNotNull(otherClientID);
1087+
1088+
// Create savings account for the other client
1089+
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, null, null,
1090+
"false");
1091+
final Integer clientSavingsId = this.savingsAccountHelper.applyForSavingsApplication(otherClientID, savingsProductID,
1092+
"INDIVIDUAL");
1093+
this.savingsAccountHelper.approveSavings(clientSavingsId);
1094+
this.savingsAccountHelper.activateSavings(clientSavingsId);
1095+
1096+
// Create loan product
1097+
LoanProductTestBuilder loanProductBuilder = new LoanProductTestBuilder().withPrincipal(PRINCIPAL).withNumberOfRepayments("4")
1098+
.withRepaymentAfterEvery("1").withRepaymentTypeAsWeek().withinterestRatePerPeriod("2")
1099+
.withInterestRateFrequencyTypeAsMonths().withAmortizationTypeAsEqualPrincipalPayment()
1100+
.withInterestTypeAsDecliningBalance().withOnHoldFundDetails("0", "0", "0");
1101+
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(loanProductBuilder.build(null));
1102+
1103+
// Create loan
1104+
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(PRINCIPAL).withLoanTermFrequency("4")
1105+
.withLoanTermFrequencyAsWeeks().withNumberOfRepayments("4").withRepaymentEveryAfter("1")
1106+
.withRepaymentFrequencyTypeAsWeeks().withInterestRatePerPeriod("2").withAmortizationTypeAsEqualInstallments()
1107+
.withInterestTypeAsDecliningBalance().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
1108+
.withSubmittedOnDate(SavingsAccountHelper.TRANSACTION_DATE)
1109+
.withExpectedDisbursementDate(SavingsAccountHelper.TRANSACTION_DATE)
1110+
.build(loanClientID.toString(), loanProductID.toString(), null);
1111+
final Integer loanID = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
1112+
1113+
// Try to create guarantor with CLIENT ID but GROUP type (type mismatch)
1114+
String guarantorJSON = new GuarantorTestBuilder()
1115+
.existingGroupWithGuaranteeAmount(String.valueOf(otherClientID), String.valueOf(clientSavingsId), GUARANTEE_AMOUNT)
1116+
.build();
1117+
1118+
final ResponseSpecification errorResponse = new ResponseSpecBuilder().build();
1119+
final RequestSpecification errorRequest = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
1120+
errorRequest.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
1121+
1122+
ArrayList<HashMap> error = (ArrayList<HashMap>) this.guarantorHelper.createGuarantorWithError(loanID, guarantorJSON,
1123+
errorRequest, errorResponse);
1124+
// Verify we got an error response (status code may be 403 or 404 depending on environment)
1125+
Assertions.assertNotNull(error, "Should return error for client ID used with GROUP type");
1126+
1127+
LOG.info("SUCCESS: Client ID with GROUP type correctly rejected");
1128+
});
11251129
}
11261130

11271131
/**

integration-tests/src/test/java/org/apache/fineract/integrationtests/client/IntegrationTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020

2121
import java.math.BigDecimal;
2222
import java.util.Optional;
23+
import org.apache.fineract.client.models.BusinessDateUpdateRequest;
24+
import org.apache.fineract.client.models.PutGlobalConfigurationsRequest;
2325
import org.apache.fineract.client.util.Calls;
2426
import org.apache.fineract.client.util.FineractClient;
27+
import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants;
28+
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
2529
import org.apache.fineract.integrationtests.common.FineractClientHelper;
30+
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
2631
import org.assertj.core.api.AbstractBigDecimalAssert;
2732
import org.assertj.core.api.AbstractBooleanAssert;
2833
import org.assertj.core.api.AbstractDoubleAssert;
@@ -52,6 +57,11 @@
5257
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
5358
public abstract class IntegrationTest {
5459

60+
protected static final String DATETIME_PATTERN = "dd MMMM yyyy";
61+
protected static final String LOCALE = "en";
62+
protected GlobalConfigurationHelper globalConfigurationHelper = new GlobalConfigurationHelper();
63+
protected BusinessDateHelper businessDateHelper = new BusinessDateHelper();
64+
5565
protected FineractClient fineractClient() {
5666
return FineractClientHelper.getFineractClient();
5767
}
@@ -118,4 +128,17 @@ public static AbstractStringAssert<?> assertThat(String actual) {
118128
public static <T> OptionalAssert<T> assertThat(Optional<T> actual) {
119129
return Assertions.assertThat(actual);
120130
}
131+
132+
protected void runAt(String date, Runnable runnable) {
133+
try {
134+
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
135+
new PutGlobalConfigurationsRequest().enabled(true));
136+
businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE)
137+
.date(date).dateFormat(DATETIME_PATTERN).locale("en"));
138+
runnable.run();
139+
} finally {
140+
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
141+
new PutGlobalConfigurationsRequest().enabled(false));
142+
}
143+
}
121144
}

0 commit comments

Comments
 (0)