FINERACT-2421: Generate better client names during testing

This commit is contained in:
Adam Saghy
2026-02-06 09:34:00 +01:00
committed by Arnold Gálovics
parent d61b5e65f9
commit 967e0ea306
21 changed files with 149 additions and 103 deletions
@@ -34,8 +34,8 @@ public class ClientRequestFactory {
return new PostClientsRequest()// return new PostClientsRequest()//
.officeId(HEAD_OFFICE_ID)// .officeId(HEAD_OFFICE_ID)//
.legalFormId(LEGAL_FORM_ID_PERSON)// .legalFormId(LEGAL_FORM_ID_PERSON)//
.firstname(Utils.randomNameGenerator("Client_FirstName_", 5))// .firstname(Utils.randomFirstNameGenerator())//
.lastname(Utils.randomNameGenerator("Client_LastName_", 5))// .lastname(Utils.randomLastNameGenerator())//
.externalId(randomClientId("ID_", 7))// .externalId(randomClientId("ID_", 7))//
.dateFormat(DATE_FORMAT)// .dateFormat(DATE_FORMAT)//
.locale(DEFAULT_LOCALE)// .locale(DEFAULT_LOCALE)//
@@ -129,7 +129,7 @@ public class LoanProductsRequestFactory {
public static final String CHARGE_OFF_REASONS = "ChargeOffReasons"; public static final String CHARGE_OFF_REASONS = "ChargeOffReasons";
public PostLoanProductsRequest defaultLoanProductsRequestLP1() { public PostLoanProductsRequest defaultLoanProductsRequestLP1() {
String name = Utils.randomNameGenerator(NAME_PREFIX, 10); String name = Utils.randomStringGenerator(NAME_PREFIX, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -239,7 +239,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP1InterestFlat() { public PostLoanProductsRequest defaultLoanProductsRequestLP1InterestFlat() {
String name = Utils.randomNameGenerator(NAME_PREFIX_INTEREST_FLAT, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_INTEREST_FLAT, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -347,7 +347,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP1InterestDeclining() { public PostLoanProductsRequest defaultLoanProductsRequestLP1InterestDeclining() {
String name = Utils.randomNameGenerator(NAME_PREFIX_INTEREST_DECLINING, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_INTEREST_DECLINING, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -455,7 +455,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP11MonthInterestDecliningBalanceDailyRecalculationCompoundingMonthly() { public PostLoanProductsRequest defaultLoanProductsRequestLP11MonthInterestDecliningBalanceDailyRecalculationCompoundingMonthly() {
String name = Utils.randomNameGenerator(NAME_PREFIX_INTEREST_DECLINING_RECALCULATION, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_INTEREST_DECLINING_RECALCULATION, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -568,7 +568,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP1InterestDecliningBalanceDailyRecalculationCompoundingNone() { public PostLoanProductsRequest defaultLoanProductsRequestLP1InterestDecliningBalanceDailyRecalculationCompoundingNone() {
String name = Utils.randomNameGenerator(NAME_PREFIX_INTEREST_DECLINING_RECALCULATION, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_INTEREST_DECLINING_RECALCULATION, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -678,7 +678,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2InterestDailyRecalculation() { public PostLoanProductsRequest defaultLoanProductsRequestLP2InterestDailyRecalculation() {
final String name = Utils.randomNameGenerator(NAME_PREFIX_INTEREST_RECALCULATION, 10); final String name = Utils.randomStringGenerator(NAME_PREFIX_INTEREST_RECALCULATION, 10);
final String shortName = generateShortNameSafely(); final String shortName = generateShortNameSafely();
List<LoanProductChargeToGLAccountMapper> penaltyToIncomeAccountMappings = new ArrayList<>(); List<LoanProductChargeToGLAccountMapper> penaltyToIncomeAccountMappings = new ArrayList<>();
@@ -793,7 +793,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2() { public PostLoanProductsRequest defaultLoanProductsRequestLP2() {
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_LP2, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -906,7 +906,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2InterestFlat() { public PostLoanProductsRequest defaultLoanProductsRequestLP2InterestFlat() {
String name = Utils.randomNameGenerator(NAME_PREFIX_INTEREST_FLAT_LP2, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_INTEREST_FLAT_LP2, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -1017,7 +1017,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2Emi() { public PostLoanProductsRequest defaultLoanProductsRequestLP2Emi() {
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2_EMI, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_LP2_EMI, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -1127,7 +1127,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2EmiWithChargeOff() { public PostLoanProductsRequest defaultLoanProductsRequestLP2EmiWithChargeOff() {
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2_EMI, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_LP2_EMI, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -1257,7 +1257,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2ChargeOffReasonToExpenseAccountMappings() { public PostLoanProductsRequest defaultLoanProductsRequestLP2ChargeOffReasonToExpenseAccountMappings() {
final String name = Utils.randomNameGenerator(NAME_PREFIX_LP2, 10); final String name = Utils.randomStringGenerator(NAME_PREFIX_LP2, 10);
final String shortName = generateShortNameSafely(); final String shortName = generateShortNameSafely();
final List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); final List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -1379,7 +1379,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2EmiCashAccounting() { public PostLoanProductsRequest defaultLoanProductsRequestLP2EmiCashAccounting() {
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2_EMI, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_LP2_EMI, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -1506,7 +1506,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2CapitalizedIncome() { public PostLoanProductsRequest defaultLoanProductsRequestLP2CapitalizedIncome() {
final String name = Utils.randomNameGenerator(NAME_PREFIX_LP2, 10); final String name = Utils.randomStringGenerator(NAME_PREFIX_LP2, 10);
final String shortName = generateShortNameSafely(); final String shortName = generateShortNameSafely();
final List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); final List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
final List<Integer> numberOfRepaymentVariationsForBorrowerCycle = new ArrayList<>(); final List<Integer> numberOfRepaymentVariationsForBorrowerCycle = new ArrayList<>();
@@ -1655,7 +1655,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2BuyDownFees() { public PostLoanProductsRequest defaultLoanProductsRequestLP2BuyDownFees() {
final String name = Utils.randomNameGenerator(NAME_PREFIX_LP2, 10); final String name = Utils.randomStringGenerator(NAME_PREFIX_LP2, 10);
final String shortName = generateShortNameSafely(); final String shortName = generateShortNameSafely();
final List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); final List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
final List<Integer> numberOfRepaymentVariationsForBorrowerCycle = new ArrayList<>(); final List<Integer> numberOfRepaymentVariationsForBorrowerCycle = new ArrayList<>();
@@ -1793,7 +1793,7 @@ public class LoanProductsRequestFactory {
} }
public PostLoanProductsRequest defaultLoanProductsRequestLP2EmiUSD() { public PostLoanProductsRequest defaultLoanProductsRequestLP2EmiUSD() {
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2_EMI, 10); String name = Utils.randomStringGenerator(NAME_PREFIX_LP2_EMI, 10);
String shortName = generateShortNameSafely(); String shortName = generateShortNameSafely();
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>(); List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
@@ -1901,7 +1901,7 @@ public class LoanProductsRequestFactory {
int counter = 0; int counter = 0;
do { do {
counter++; counter++;
generatedShortName = Utils.randomNameGenerator("", 4); generatedShortName = Utils.randomStringGenerator("", 4);
if (counter > 999) { if (counter > 999) {
throw new RuntimeException("Unable to generate unique short name"); throw new RuntimeException("Unable to generate unique short name");
} }
@@ -21,10 +21,28 @@ package org.apache.fineract.test.helper;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.time.Clock; import java.time.Clock;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List;
public final class Utils { public final class Utils {
private static final SecureRandom random = new SecureRandom(); private static final SecureRandom random = new SecureRandom();
private static final List<String> firstNames = List.of("Adam", "Alex", "Andrew", "Anthony", "Arthur", "Benjamin", "Brian", "Brandon",
"Bruce", "Caleb", "Charles", "Christian", "Christopher", "Daniel", "David", "Dennis", "Dominic", "Edward", "Ethan", "Felix",
"Frank", "Gabriel", "George", "Gregory", "Harry", "Henry", "Isaac", "Jack", "Jacob", "James", "Jason", "John", "Jonathan",
"Joseph", "Joshua", "Julian", "Kevin", "Kyle", "Leo", "Liam", "Logan", "Lucas", "Luke", "Marcus", "Mark", "Martin", "Matthew",
"Michael", "Nathan", "Nicholas", "Noah", "Oliver", "Oscar", "Patrick", "Paul", "Peter", "Philip", "Raymond", "Richard",
"Robert", "Ryan", "Samuel", "Scott", "Sean", "Simon", "Stephen", "Steven", "Thomas", "Timothy", "Victor", "William", "Zachary",
"Aaron", "Adrian", "Alan", "Albert", "Allen", "Antonio", "Austin", "Blake", "Cameron", "Carlos", "Colin", "Dylan", "Eric",
"Harrison", "Ian", "Jeremy", "Jordan", "Kevin", "Louis", "Mitchell", "Neil", "Roger", "Trevor");
private static final List<String> lastNames = List.of("Anderson", "Armstrong", "Baker", "Barnes", "Bell", "Bennett", "Brooks", "Brown",
"Bryant", "Butler", "Campbell", "Carter", "Clark", "Collins", "Cook", "Cooper", "Cox", "Davis", "Diaz", "Edwards", "Evans",
"Fisher", "Foster", "Garcia", "Gomez", "Gonzalez", "Gray", "Green", "Hall", "Harris", "Hernandez", "Hill", "Howard", "Hughes",
"Jackson", "James", "Jenkins", "Johnson", "Jones", "Kelly", "Kim", "King", "Lee", "Lewis", "Lopez", "Martin", "Martinez",
"Miller", "Mitchell", "Moore", "Morgan", "Morris", "Murphy", "Nelson", "Nguyen", "Parker", "Perez", "Peterson", "Phillips",
"Powell", "Price", "Ramirez", "Reed", "Richardson", "Rivera", "Roberts", "Robinson", "Rodriguez", "Rogers", "Ross", "Russell",
"Sanchez", "Scott", "Smith", "Stewart", "Taylor", "Thomas", "Thompson", "Torres", "Turner", "Walker", "Ward", "Watson", "White",
"Williams", "Wilson", "Wood", "Wright", "Young", "Zhang");
private Utils() {} private Utils() {}
@@ -41,8 +59,12 @@ public final class Utils {
return randomStringGenerator(prefix, len, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); return randomStringGenerator(prefix, len, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
} }
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { public static String randomFirstNameGenerator() {
return randomStringGenerator(prefix, lenOfRandomSuffix); return firstNames.get(random.nextInt(firstNames.size()));
}
public static String randomLastNameGenerator() {
return lastNames.get(random.nextInt(lastNames.size()));
} }
public static LocalDate now() { public static LocalDate now() {
@@ -115,7 +115,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
// if user created transferExternalId previously, it will use that, otherwise create a new one // if user created transferExternalId previously, it will use that, otherwise create a new one
String transferExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED); String transferExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED);
if (transferExternalId == null) { if (transferExternalId == null) {
transferExternalId = Utils.randomNameGenerator("TestTransferExtId_", 3); transferExternalId = Utils.randomStringGenerator("TestTransferExtId_", 10);
testContext().set(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED, transferExternalId); testContext().set(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED, transferExternalId);
} }
@@ -155,7 +155,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
} else if ((transferData.get(0).equals(TRANSACTION_TYPE_SALE) || transferData.get(0).equals(TRANSACTION_TYPE_INTERMEDIARY_SALE))) { } else if ((transferData.get(0).equals(TRANSACTION_TYPE_SALE) || transferData.get(0).equals(TRANSACTION_TYPE_INTERMEDIARY_SALE))) {
String ownerExternalId; String ownerExternalId;
if (regenerateOwner) { if (regenerateOwner) {
ownerExternalId = Utils.randomNameGenerator(OWNER_EXTERNAL_ID_PREFIX, 3); ownerExternalId = Utils.randomStringGenerator(OWNER_EXTERNAL_ID_PREFIX, 10);
} else { } else {
ownerExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_OWNER_EXTERNAL_ID); ownerExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_OWNER_EXTERNAL_ID);
} }
@@ -208,7 +208,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
// if user created transferExternalId previously, it will use that, otherwise create a new one // if user created transferExternalId previously, it will use that, otherwise create a new one
String transferExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED); String transferExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED);
if (transferExternalId == null) { if (transferExternalId == null) {
transferExternalId = Utils.randomNameGenerator("TestTransferExtId_", 3); transferExternalId = Utils.randomStringGenerator("TestTransferExtId_", 10);
testContext().set(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED, transferExternalId); testContext().set(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED, transferExternalId);
} }
@@ -240,7 +240,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
testContext().set(TestContextKey.ASSET_EXTERNALIZATION_BUYBACK_TRANSFER_EXTERNAL_ID_FROM_RESPONSE, testContext().set(TestContextKey.ASSET_EXTERNALIZATION_BUYBACK_TRANSFER_EXTERNAL_ID_FROM_RESPONSE,
response.getResourceExternalId()); response.getResourceExternalId());
} else if (transferData.get(0).equals(TRANSACTION_TYPE_SALE)) { } else if (transferData.get(0).equals(TRANSACTION_TYPE_SALE)) {
String ownerExternalId = Utils.randomNameGenerator(OWNER_EXTERNAL_ID_PREFIX, 3); String ownerExternalId = Utils.randomStringGenerator(OWNER_EXTERNAL_ID_PREFIX, 10);
request.settlementDate(transferData.get(1))// request.settlementDate(transferData.get(1))//
.ownerExternalId(ownerExternalId)// .ownerExternalId(ownerExternalId)//
@@ -494,7 +494,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
.dateFormat(DATE_FORMAT_ASSET_EXT)// .dateFormat(DATE_FORMAT_ASSET_EXT)//
.locale(DEFAULT_LOCALE);// .locale(DEFAULT_LOCALE);//
} else if (transferData.get(0).equals(TRANSACTION_TYPE_SALE)) { } else if (transferData.get(0).equals(TRANSACTION_TYPE_SALE)) {
String ownerExternalId = Utils.randomNameGenerator(OWNER_EXTERNAL_ID_PREFIX, 3); String ownerExternalId = Utils.randomStringGenerator(OWNER_EXTERNAL_ID_PREFIX, 10);
request.settlementDate(transferData.get(1))// request.settlementDate(transferData.get(1))//
.ownerExternalId(ownerExternalId)// .ownerExternalId(ownerExternalId)//
@@ -788,7 +788,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
String transferExternalId = testContext() String transferExternalId = testContext()
.get(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED + "_" + type); .get(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED + "_" + type);
if (transferExternalId == null) { if (transferExternalId == null) {
transferExternalId = Utils.randomNameGenerator("TestTransferExtId_", 3); transferExternalId = Utils.randomStringGenerator("TestTransferExtId_", 10);
testContext().set(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED + "_" + type, transferExternalId); testContext().set(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED + "_" + type, transferExternalId);
} }
@@ -923,7 +923,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
public void createAssetExternalizationRequestByLoanIdUserGeneratedExtIdForceTransferIdNoTestOwner(String type, DataTable table) public void createAssetExternalizationRequestByLoanIdUserGeneratedExtIdForceTransferIdNoTestOwner(String type, DataTable table)
throws IOException { throws IOException {
// if user created transferExternalId previously, it will use that, otherwise create a new one // if user created transferExternalId previously, it will use that, otherwise create a new one
String transferExternalId = Utils.randomNameGenerator("TestTransferExtId_", 3); String transferExternalId = Utils.randomStringGenerator("TestTransferExtId_", 10);
testContext().set(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED + "_" + type, transferExternalId); testContext().set(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED + "_" + type, transferExternalId);
createAssetExternalizationRequestByLoanId(table, transferExternalId, false); createAssetExternalizationRequestByLoanId(table, transferExternalId, false);
@@ -47,7 +47,7 @@ public class UserStepDef extends AbstractStepDef {
@When("Admin creates new user with {string} username, {string} role name and given permissions:") @When("Admin creates new user with {string} username, {string} role name and given permissions:")
public void createUserWithUsernameAndRoles(String username, String roleName, List<String> permissions) { public void createUserWithUsernameAndRoles(String username, String roleName, List<String> permissions) {
ok(() -> fineractClient.roles().retrieveAllRoles()); ok(() -> fineractClient.roles().retrieveAllRoles());
PostRolesRequest newRoleRequest = new PostRolesRequest().name(Utils.randomNameGenerator(roleName, 8)).description(roleName); PostRolesRequest newRoleRequest = new PostRolesRequest().name(Utils.randomStringGenerator(roleName, 8)).description(roleName);
PostRolesResponse createNewRole = ok(() -> fineractClient.roles().createRole(newRoleRequest)); PostRolesResponse createNewRole = ok(() -> fineractClient.roles().createRole(newRoleRequest));
Long roleId = createNewRole.getResourceId(); Long roleId = createNewRole.getResourceId();
Map<String, Boolean> permissionMap = new HashMap<>(); Map<String, Boolean> permissionMap = new HashMap<>();
@@ -56,12 +56,12 @@ public class UserStepDef extends AbstractStepDef {
.permissions(permissionMap); .permissions(permissionMap);
ok(() -> fineractClient.roles().updateRolePermissions(roleId, putRolesRoleIdPermissionsRequest)); ok(() -> fineractClient.roles().updateRolePermissions(roleId, putRolesRoleIdPermissionsRequest));
String generatedUsername = Utils.randomNameGenerator(username, 8); String generatedUsername = Utils.randomStringGenerator(username, 8);
PostUsersRequest postUsersRequest = new PostUsersRequest() // PostUsersRequest postUsersRequest = new PostUsersRequest() //
.username(generatedUsername) // .username(generatedUsername) //
.email(EMAIL) // .email(EMAIL) //
.firstname(username) // .firstname(Utils.randomFirstNameGenerator()) //
.lastname(username) // .lastname(Utils.randomLastNameGenerator()) //
.sendPasswordToEmail(Boolean.FALSE) // .sendPasswordToEmail(Boolean.FALSE) //
.officeId(1L) // .officeId(1L) //
.password(PWD_USER_WITH_ROLE) // .password(PWD_USER_WITH_ROLE) //
@@ -3161,7 +3161,7 @@ public class LoanStepDef extends AbstractStepDef {
PostLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE); PostLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanResponse.getLoanId(); long loanId = loanResponse.getLoanId();
String reversalExternalId = Utils.randomNameGenerator("reversalExtId_", 3); String reversalExternalId = Utils.randomStringGenerator("reversalExtId_", 10);
PostLoansLoanIdTransactionsRequest chargeOffUndoRequest = LoanRequestFactory.defaultUndoChargeOffRequest() PostLoansLoanIdTransactionsRequest chargeOffUndoRequest = LoanRequestFactory.defaultUndoChargeOffRequest()
.reversalExternalId(reversalExternalId); .reversalExternalId(reversalExternalId);
@@ -368,8 +368,8 @@ public abstract class BaseLoanIntegrationTest extends IntegrationTest {
Calls.ok(fineractClient().roles.updateRolePermissions(roleId, Calls.ok(fineractClient().roles.updateRolePermissions(roleId,
new PutRolesRoleIdPermissionsRequest().putPermissionsItem(permission, false))); new PutRolesRoleIdPermissionsRequest().putPermissionsItem(permission, false)));
// create user with role // create user with role
String firstname = "Test"; String firstname = Utils.randomFirstNameGenerator();
String lastname = Utils.uniqueRandomStringGenerator("User", 6); String lastname = Utils.randomLastNameGenerator();
String userName = Utils.uniqueRandomStringGenerator("testUserName", 4); String userName = Utils.uniqueRandomStringGenerator("testUserName", 4);
String password = "AKleRbDhK421$"; String password = "AKleRbDhK421$";
String email = firstname + "." + lastname + "@whatever.mifos.org"; String email = firstname + "." + lastname + "@whatever.mifos.org";
@@ -7118,8 +7118,8 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest {
} }
private PostClientsRequest createRandomClientWithDate(String date) { private PostClientsRequest createRandomClientWithDate(String date) {
return new PostClientsRequest().officeId(1L).legalFormId(1L).firstname(Utils.randomStringGenerator("", 5)) return new PostClientsRequest().officeId(1L).legalFormId(1L).firstname(Utils.randomFirstNameGenerator())
.lastname(Utils.randomStringGenerator("", 5)).active(true).locale("en").activationDate(date).dateFormat(DATETIME_PATTERN); .lastname(Utils.randomLastNameGenerator()).active(true).locale("en").activationDate(date).dateFormat(DATETIME_PATTERN);
} }
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, final List<HashMap> charges) { private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, final List<HashMap> charges) {
@@ -270,9 +270,9 @@ public class ClientTest {
@Test @Test
public void testClientName() { public void testClientName() {
String firstName = Utils.randomStringGenerator("FN", 48); String firstName = Utils.randomFirstNameGenerator();
String middleName = Utils.randomStringGenerator("MN", 48); String middleName = Utils.randomFirstNameGenerator();
String lastName = Utils.randomStringGenerator("LN", 48); String lastName = Utils.randomLastNameGenerator();
String fullName = firstName + ' ' + middleName + ' ' + lastName; String fullName = firstName + ' ' + middleName + ' ' + lastName;
PostClientsRequest request = new PostClientsRequest().officeId(1L).legalFormId(LEGALFORM_ID_PERSON).firstname(firstName) PostClientsRequest request = new PostClientsRequest().officeId(1L).legalFormId(LEGALFORM_ID_PERSON).firstname(firstName)
@@ -63,10 +63,9 @@ public class NotificationApiTest {
String username = Utils.uniqueRandomStringGenerator("NotificationUser", 4); String username = Utils.uniqueRandomStringGenerator("NotificationUser", 4);
String password = Utils.randomStringGenerator("A1b2c3d4e5f$", 1); // prefix is to conform with the password String password = Utils.randomStringGenerator("A1b2c3d4e5f$", 1); // prefix is to conform with the password
// rules // rules
PostUsersRequest createUserRequest = new PostUsersRequest().username(username) PostUsersRequest createUserRequest = new PostUsersRequest().username(username).firstname(Utils.randomFirstNameGenerator())
.firstname(Utils.randomStringGenerator("NotificationFN", 4)).lastname(Utils.randomStringGenerator("NotificationLN", 4)) .lastname(Utils.randomLastNameGenerator()).email("whatever@mifos.org").password(password).repeatPassword(password)
.email("whatever@mifos.org").password(password).repeatPassword(password).sendPasswordToEmail(false) .sendPasswordToEmail(false).roles(List.of(SUPER_USER_ROLE_ID)).officeId(headOffice.getId());
.roles(List.of(SUPER_USER_ROLE_ID)).officeId(headOffice.getId());
PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest); PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest);
Assertions.assertNotNull(userCreationResponse.getResourceId()); Assertions.assertNotNull(userCreationResponse.getResourceId());
@@ -191,10 +191,10 @@ public class UserAdministrationTest extends IntegrationTest {
String originalPassword = "QwE!5rTy#9uP0"; String originalPassword = "QwE!5rTy#9uP0";
String simpleUsername = Utils.uniqueRandomStringGenerator("NotificationUser", 4); String simpleUsername = Utils.uniqueRandomStringGenerator("NotificationUser", 4);
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec); GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
PostUsersRequest createUserRequest = new PostUsersRequest().username(simpleUsername) PostUsersRequest createUserRequest = new PostUsersRequest().username(simpleUsername).firstname(Utils.randomFirstNameGenerator())
.firstname(Utils.randomStringGenerator("NotificationFN", 4)).lastname(Utils.randomStringGenerator("NotificationLN", 4)) .lastname(Utils.randomLastNameGenerator()).email("whatever@mifos.org").password(originalPassword)
.email("whatever@mifos.org").password(originalPassword).repeatPassword(originalPassword).sendPasswordToEmail(false) .repeatPassword(originalPassword).sendPasswordToEmail(false).officeId(headOffice.getId())
.officeId(headOffice.getId()).roles(List.of(Long.valueOf(roleId))); .roles(List.of(Long.valueOf(roleId)));
PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest); PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest);
Long userId = userCreationResponse.getResourceId(); Long userId = userCreationResponse.getResourceId();
@@ -224,10 +224,10 @@ public class UserAdministrationTest extends IntegrationTest {
String originalPassword = "QwE!5rTy#9uP0"; String originalPassword = "QwE!5rTy#9uP0";
String simpleUsername = Utils.uniqueRandomStringGenerator("NotificationUser", 4); String simpleUsername = Utils.uniqueRandomStringGenerator("NotificationUser", 4);
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec); GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
PostUsersRequest createUserRequest = new PostUsersRequest().username(simpleUsername) PostUsersRequest createUserRequest = new PostUsersRequest().username(simpleUsername).firstname(Utils.randomFirstNameGenerator())
.firstname(Utils.randomStringGenerator("NotificationFN", 4)).lastname(Utils.randomStringGenerator("NotificationLN", 4)) .lastname(Utils.randomLastNameGenerator()).email("whatever@mifos.org").password(originalPassword)
.email("whatever@mifos.org").password(originalPassword).repeatPassword(originalPassword).sendPasswordToEmail(false) .repeatPassword(originalPassword).sendPasswordToEmail(false).officeId(headOffice.getId())
.officeId(headOffice.getId()).roles(List.of(Long.valueOf(roleId))); .roles(List.of(Long.valueOf(roleId)));
PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest); PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest);
Long userId = userCreationResponse.getResourceId(); Long userId = userCreationResponse.getResourceId();
@@ -258,10 +258,9 @@ public class UserAdministrationTest extends IntegrationTest {
String password = "QwE!5rTy#9uP0"; String password = "QwE!5rTy#9uP0";
String simpleUsername = Utils.uniqueRandomStringGenerator("NotificationUser", 4); String simpleUsername = Utils.uniqueRandomStringGenerator("NotificationUser", 4);
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec); GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
PostUsersRequest createUserRequest = new PostUsersRequest().username(simpleUsername) PostUsersRequest createUserRequest = new PostUsersRequest().username(simpleUsername).firstname(Utils.randomFirstNameGenerator())
.firstname(Utils.randomStringGenerator("NotificationFN", 4)).lastname(Utils.randomStringGenerator("NotificationLN", 4)) .lastname(Utils.randomLastNameGenerator()).email("whatever@mifos.org").password(password).repeatPassword(password)
.email("whatever@mifos.org").password(password).repeatPassword(password).sendPasswordToEmail(false) .sendPasswordToEmail(false).officeId(headOffice.getId()).roles(List.of(Long.valueOf(roleId)));
.officeId(headOffice.getId()).roles(List.of(Long.valueOf(roleId)));
PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest); PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest);
Long userId = userCreationResponse.getResourceId(); Long userId = userCreationResponse.getResourceId();
@@ -49,7 +49,7 @@ public class FeignDocumentTest extends FeignIntegrationTest {
@Order(1) @Order(1)
void setupClient() { void setupClient() {
FeignClientHelper clientHelper = new FeignClientHelper(fineractClient()); FeignClientHelper clientHelper = new FeignClientHelper(fineractClient());
clientId = clientHelper.createClient("Feign", "Test"); clientId = clientHelper.createClient();
assertThat(clientId).isNotNull(); assertThat(clientId).isNotNull();
} }
@@ -52,8 +52,8 @@ public class StaffTest extends IntegrationTest {
} }
Long create() { Long create() {
return ok(fineractClient().staff.create3(new StaffRequest().officeId(1L).firstname(Utils.randomStringGenerator("StaffTest", 6)) return ok(fineractClient().staff.create3(new StaffRequest().officeId(1L).firstname(Utils.randomFirstNameGenerator())
.lastname(Utils.randomStringGenerator("Staffer_", 6)).externalId(Utils.randomStringGenerator("", 12)) .lastname(Utils.randomLastNameGenerator()).externalId(Utils.randomStringGenerator("", 12))
.joiningDate(LocalDate.now(ZoneId.of("UTC")).toString()).dateFormat("yyyy-MM-dd").locale("en_US"))).getResourceId(); .joiningDate(LocalDate.now(ZoneId.of("UTC")).toString()).dateFormat("yyyy-MM-dd").locale("en_US"))).getResourceId();
} }
@@ -93,8 +93,8 @@ public abstract class FeignLoanTestBase extends FeignIntegrationTest implements
return getAccounts().getExpenseAccountId(accountName); return getAccounts().getExpenseAccountId(accountName);
} }
protected Long createClient(String firstName, String lastName) { protected Long createClient() {
return clientHelper.createClient(firstName, lastName); return clientHelper.createClient();
} }
protected Long createLoanProduct(PostLoanProductsRequest request) { protected Long createLoanProduct(PostLoanProductsRequest request) {
@@ -36,15 +36,15 @@ public class FeignClientHelper {
this.fineractClient = fineractClient; this.fineractClient = fineractClient;
} }
public Long createClient(String firstName, String lastName) { public Long createClient() {
String externalId = Utils.randomStringGenerator("EXT_", 7); String externalId = Utils.randomStringGenerator("EXT_", 7);
String activationDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant()); String activationDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant());
PostClientsRequest request = new PostClientsRequest()// PostClientsRequest request = new PostClientsRequest()//
.officeId(1L)// .officeId(1L)//
.legalFormId(1L)// .legalFormId(1L)//
.firstname(firstName)// .firstname(Utils.randomFirstNameGenerator())//
.lastname(lastName)// .lastname(Utils.randomLastNameGenerator())//
.externalId(externalId)// .externalId(externalId)//
.active(true)// .active(true)//
.activationDate(activationDate)// .activationDate(activationDate)//
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.time.LocalDate; import java.time.LocalDate;
import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdStatus;
import org.apache.fineract.client.models.PostLoanProductsRequest; import org.apache.fineract.client.models.PostLoanProductsRequest;
import org.apache.fineract.integrationtests.client.feign.FeignLoanTestBase; import org.apache.fineract.integrationtests.client.feign.FeignLoanTestBase;
import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.integrationtests.common.Utils;
@@ -32,7 +33,7 @@ public class FeignLoanCreationTest extends FeignLoanTestBase {
@Test @Test
void testCreateAndDisburseLoan_OnePeriodNoInterest() { void testCreateAndDisburseLoan_OnePeriodNoInterest() {
Long clientId = createClient("John", "Doe"); Long clientId = createClient();
assertNotNull(clientId); assertNotNull(clientId);
PostLoanProductsRequest productRequest = onePeriod30DaysNoInterest(); PostLoanProductsRequest productRequest = onePeriod30DaysNoInterest();
@@ -45,7 +46,7 @@ public class FeignLoanCreationTest extends FeignLoanTestBase {
GetLoansLoanIdResponse loan = getLoanDetails(loanId); GetLoansLoanIdResponse loan = getLoanDetails(loanId);
assertNotNull(loan); assertNotNull(loan);
verifyLoanStatus(loan, status -> status.getActive()); verifyLoanStatus(loan, GetLoansLoanIdStatus::getActive);
LocalDate expectedRepaymentDate = Utils.getLocalDateOfTenant().plusMonths(1); LocalDate expectedRepaymentDate = Utils.getLocalDateOfTenant().plusMonths(1);
validateRepaymentPeriod(loan, 1, expectedRepaymentDate, 1000.0, 0.0, 1000.0); validateRepaymentPeriod(loan, 1, expectedRepaymentDate, 1000.0, 0.0, 1000.0);
@@ -56,7 +57,7 @@ public class FeignLoanCreationTest extends FeignLoanTestBase {
@Test @Test
void testLoanRepayment_FullRepayment() { void testLoanRepayment_FullRepayment() {
Long clientId = createClient("Jane", "Smith"); Long clientId = createClient();
Long productId = createLoanProduct(onePeriod30DaysNoInterest()); Long productId = createLoanProduct(onePeriod30DaysNoInterest());
String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant()); String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant());
Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 1); Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 1);
@@ -65,7 +66,7 @@ public class FeignLoanCreationTest extends FeignLoanTestBase {
assertNotNull(repaymentId); assertNotNull(repaymentId);
GetLoansLoanIdResponse loan = getLoanDetails(loanId); GetLoansLoanIdResponse loan = getLoanDetails(loanId);
verifyLoanStatus(loan, status -> status.getClosedObligationsMet()); verifyLoanStatus(loan, GetLoansLoanIdStatus::getClosedObligationsMet);
assertEquals(0.0, Utils.getDoubleValue(loan.getSummary().getTotalOutstanding())); assertEquals(0.0, Utils.getDoubleValue(loan.getSummary().getTotalOutstanding()));
assertEquals(1000.0, Utils.getDoubleValue(loan.getSummary().getTotalRepayment())); assertEquals(1000.0, Utils.getDoubleValue(loan.getSummary().getTotalRepayment()));
@@ -73,45 +74,45 @@ public class FeignLoanCreationTest extends FeignLoanTestBase {
@Test @Test
void testLoanUndoApproval() { void testLoanUndoApproval() {
Long clientId = createClient("Bob", "Johnson"); Long clientId = createClient();
Long productId = createLoanProduct(onePeriod30DaysNoInterest()); Long productId = createLoanProduct(onePeriod30DaysNoInterest());
String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant()); String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant());
Long loanId = createApprovedLoan(clientId, productId, todayDate, 1000.0, 1); Long loanId = createApprovedLoan(clientId, productId, todayDate, 1000.0, 1);
GetLoansLoanIdResponse loanBeforeUndo = getLoanDetails(loanId); GetLoansLoanIdResponse loanBeforeUndo = getLoanDetails(loanId);
verifyLoanStatus(loanBeforeUndo, status -> status.getWaitingForDisbursal()); verifyLoanStatus(loanBeforeUndo, GetLoansLoanIdStatus::getWaitingForDisbursal);
undoApproval(loanId); undoApproval(loanId);
GetLoansLoanIdResponse loanAfterUndo = getLoanDetails(loanId); GetLoansLoanIdResponse loanAfterUndo = getLoanDetails(loanId);
verifyLoanStatus(loanAfterUndo, status -> status.getPendingApproval()); verifyLoanStatus(loanAfterUndo, GetLoansLoanIdStatus::getPendingApproval);
} }
@Test @Test
void testLoanUndoDisbursement() { void testLoanUndoDisbursement() {
Long clientId = createClient("Alice", "Williams"); Long clientId = createClient();
Long productId = createLoanProduct(onePeriod30DaysNoInterest()); Long productId = createLoanProduct(onePeriod30DaysNoInterest());
String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant()); String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant());
Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 1); Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 1);
GetLoansLoanIdResponse loanBeforeUndo = getLoanDetails(loanId); GetLoansLoanIdResponse loanBeforeUndo = getLoanDetails(loanId);
verifyLoanStatus(loanBeforeUndo, status -> status.getActive()); verifyLoanStatus(loanBeforeUndo, GetLoansLoanIdStatus::getActive);
undoDisbursement(loanId); undoDisbursement(loanId);
GetLoansLoanIdResponse loanAfterUndo = getLoanDetails(loanId); GetLoansLoanIdResponse loanAfterUndo = getLoanDetails(loanId);
verifyLoanStatus(loanAfterUndo, status -> status.getWaitingForDisbursal()); verifyLoanStatus(loanAfterUndo, GetLoansLoanIdStatus::getWaitingForDisbursal);
} }
@Test @Test
void testFourInstallmentLoan_CumulativeInterest() { void testFourInstallmentLoan_CumulativeInterest() {
Long clientId = createClient("Charlie", "Brown"); Long clientId = createClient();
Long productId = createLoanProduct(fourInstallmentsCumulative()); Long productId = createLoanProduct(fourInstallmentsCumulative());
String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant()); String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant());
Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 4); Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 4);
GetLoansLoanIdResponse loan = getLoanDetails(loanId); GetLoansLoanIdResponse loan = getLoanDetails(loanId);
verifyLoanStatus(loan, status -> status.getActive()); verifyLoanStatus(loan, GetLoansLoanIdStatus::getActive);
assertNotNull(loan.getRepaymentSchedule()); assertNotNull(loan.getRepaymentSchedule());
assertNotNull(loan.getRepaymentSchedule().getPeriods()); assertNotNull(loan.getRepaymentSchedule().getPeriods());
@@ -120,7 +121,7 @@ public class FeignLoanCreationTest extends FeignLoanTestBase {
@Test @Test
void testPartialRepayment() { void testPartialRepayment() {
Long clientId = createClient("David", "Miller"); Long clientId = createClient();
Long productId = createLoanProduct(onePeriod30DaysNoInterest()); Long productId = createLoanProduct(onePeriod30DaysNoInterest());
String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant()); String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant());
Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 1); Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 1);
@@ -129,7 +130,7 @@ public class FeignLoanCreationTest extends FeignLoanTestBase {
assertNotNull(repaymentId); assertNotNull(repaymentId);
GetLoansLoanIdResponse loan = getLoanDetails(loanId); GetLoansLoanIdResponse loan = getLoanDetails(loanId);
verifyLoanStatus(loan, status -> status.getActive()); verifyLoanStatus(loan, GetLoansLoanIdStatus::getActive);
assertEquals(500.0, Utils.getDoubleValue(loan.getSummary().getTotalOutstanding())); assertEquals(500.0, Utils.getDoubleValue(loan.getSummary().getTotalOutstanding()));
assertEquals(500.0, Utils.getDoubleValue(loan.getSummary().getTotalRepayment())); assertEquals(500.0, Utils.getDoubleValue(loan.getSummary().getTotalRepayment()));
@@ -137,7 +138,7 @@ public class FeignLoanCreationTest extends FeignLoanTestBase {
@Test @Test
void testUndoRepayment() { void testUndoRepayment() {
Long clientId = createClient("Eva", "Davis"); Long clientId = createClient();
Long productId = createLoanProduct(onePeriod30DaysNoInterest()); Long productId = createLoanProduct(onePeriod30DaysNoInterest());
String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant()); String todayDate = Utils.dateFormatter.format(Utils.getLocalDateOfTenant());
Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 1); Long loanId = createApproveAndDisburseLoan(clientId, productId, todayDate, 1000.0, 1);
@@ -146,12 +147,12 @@ public class FeignLoanCreationTest extends FeignLoanTestBase {
assertNotNull(repaymentId); assertNotNull(repaymentId);
GetLoansLoanIdResponse loanAfterRepayment = getLoanDetails(loanId); GetLoansLoanIdResponse loanAfterRepayment = getLoanDetails(loanId);
verifyLoanStatus(loanAfterRepayment, status -> status.getClosedObligationsMet()); verifyLoanStatus(loanAfterRepayment, GetLoansLoanIdStatus::getClosedObligationsMet);
undoRepayment(loanId, repaymentId, todayDate); undoRepayment(loanId, repaymentId, todayDate);
GetLoansLoanIdResponse loanAfterUndo = getLoanDetails(loanId); GetLoansLoanIdResponse loanAfterUndo = getLoanDetails(loanId);
verifyLoanStatus(loanAfterUndo, status -> status.getActive()); verifyLoanStatus(loanAfterUndo, GetLoansLoanIdStatus::getActive);
LocalDate expectedRepaymentDate = Utils.getLocalDateOfTenant().plusMonths(1); LocalDate expectedRepaymentDate = Utils.getLocalDateOfTenant().plusMonths(1);
validateRepaymentPeriod(loanAfterUndo, 1, expectedRepaymentDate, 1000.0, 0.0, 1000.0); validateRepaymentPeriod(loanAfterUndo, 1, expectedRepaymentDate, 1000.0, 0.0, 1000.0);
@@ -259,7 +259,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId(); final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId();
final Long originatorId = originatorHelper.createOriginator(originatorExternalId); final Long originatorId = originatorHelper.createOriginator(originatorExternalId);
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanId = loanHelper.createSubmittedLoan(clientId); final Long loanId = loanHelper.createSubmittedLoan(clientId);
originatorHelper.attachOriginatorToLoan(loanId, originatorId); originatorHelper.attachOriginatorToLoan(loanId, originatorId);
@@ -273,7 +273,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId(); final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId();
final Long originatorId = originatorHelper.createOriginator(originatorExternalId); final Long originatorId = originatorHelper.createOriginator(originatorExternalId);
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanId = loanHelper.createSubmittedLoan(clientId); final Long loanId = loanHelper.createSubmittedLoan(clientId);
originatorHelper.attachOriginatorToLoan(loanId, originatorId); originatorHelper.attachOriginatorToLoan(loanId, originatorId);
@@ -287,7 +287,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId(); final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId();
final Long originatorId = originatorHelper.createOriginator(originatorExternalId, "Inactive Test", "INACTIVE"); final Long originatorId = originatorHelper.createOriginator(originatorExternalId, "Inactive Test", "INACTIVE");
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanId = loanHelper.createSubmittedLoan(clientId); final Long loanId = loanHelper.createSubmittedLoan(clientId);
final CallFailedRuntimeException exception = originatorHelper.attachOriginatorToLoanExpectingError(loanId, originatorId); final CallFailedRuntimeException exception = originatorHelper.attachOriginatorToLoanExpectingError(loanId, originatorId);
@@ -301,7 +301,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId(); final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId();
final Long originatorId = originatorHelper.createOriginator(originatorExternalId); final Long originatorId = originatorHelper.createOriginator(originatorExternalId);
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanId = loanHelper.createSubmittedLoan(clientId); final Long loanId = loanHelper.createSubmittedLoan(clientId);
originatorHelper.attachOriginatorToLoan(loanId, originatorId); originatorHelper.attachOriginatorToLoan(loanId, originatorId);
@@ -318,7 +318,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId(); final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId();
final Long originatorId = originatorHelper.createOriginator(originatorExternalId); final Long originatorId = originatorHelper.createOriginator(originatorExternalId);
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanId = loanHelper.createSubmittedLoan(clientId); final Long loanId = loanHelper.createSubmittedLoan(clientId);
final CallFailedRuntimeException exception = originatorHelper.detachOriginatorFromLoanExpectingError(loanId, originatorId); final CallFailedRuntimeException exception = originatorHelper.detachOriginatorFromLoanExpectingError(loanId, originatorId);
@@ -332,7 +332,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId(); final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId();
final Long originatorId = originatorHelper.createOriginator(originatorExternalId); final Long originatorId = originatorHelper.createOriginator(originatorExternalId);
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanProductId = loanHelper.createSimpleLoanProduct(); final Long loanProductId = loanHelper.createSimpleLoanProduct();
final String todayDate = org.apache.fineract.integrationtests.common.Utils.dateFormatter final String todayDate = org.apache.fineract.integrationtests.common.Utils.dateFormatter
.format(org.apache.fineract.integrationtests.common.Utils.getLocalDateOfTenant()); .format(org.apache.fineract.integrationtests.common.Utils.getLocalDateOfTenant());
@@ -349,7 +349,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId(); final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId();
final Long originatorId = originatorHelper.createOriginator(originatorExternalId); final Long originatorId = originatorHelper.createOriginator(originatorExternalId);
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanId = loanHelper.createSubmittedLoan(clientId); final Long loanId = loanHelper.createSubmittedLoan(clientId);
originatorHelper.attachOriginatorToLoan(loanId, originatorId); originatorHelper.attachOriginatorToLoan(loanId, originatorId);
@@ -370,7 +370,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId(); final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId();
final Long originatorId = originatorHelper.createOriginator(originatorExternalId); final Long originatorId = originatorHelper.createOriginator(originatorExternalId);
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanId = loanHelper.createSubmittedLoan(clientId); final Long loanId = loanHelper.createSubmittedLoan(clientId);
originatorHelper.attachOriginatorToLoan(loanId, originatorId); originatorHelper.attachOriginatorToLoan(loanId, originatorId);
@@ -387,7 +387,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
@Test @Test
public void testRetrieveLoanWithNoOriginatorsReturnsEmptyList() { public void testRetrieveLoanWithNoOriginatorsReturnsEmptyList() {
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanId = loanHelper.createSubmittedLoan(clientId); final Long loanId = loanHelper.createSubmittedLoan(clientId);
final var loanDetails = loanHelper.getLoanDetailsWithAssociations(loanId, "originators"); final var loanDetails = loanHelper.getLoanDetailsWithAssociations(loanId, "originators");
@@ -401,7 +401,7 @@ public class FeignLoanOriginatorApiTest extends FeignIntegrationTest {
final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId(); final String originatorExternalId = FeignLoanOriginatorHelper.generateUniqueExternalId();
final Long originatorId = originatorHelper.createOriginator(originatorExternalId); final Long originatorId = originatorHelper.createOriginator(originatorExternalId);
final Long clientId = clientHelper.createClient("Test", "Client"); final Long clientId = clientHelper.createClient();
final Long loanId = loanHelper.createSubmittedLoan(clientId); final Long loanId = loanHelper.createSubmittedLoan(clientId);
originatorHelper.attachOriginatorToLoan(loanId, originatorId); originatorHelper.attachOriginatorToLoan(loanId, originatorId);
@@ -39,7 +39,7 @@ public class FeignLoanTestBaseSmokeTest extends FeignLoanTestBase {
@Test @Test
void testCreateClient() { void testCreateClient() {
Long clientId = createClient("Test", "User"); Long clientId = createClient();
assertNotNull(clientId); assertNotNull(clientId);
} }
} }
@@ -450,8 +450,8 @@ public class ClientHelper {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
map.put("officeId", officeId); map.put("officeId", officeId);
map.put("legalFormId", legalFormId); map.put("legalFormId", legalFormId);
map.put("firstname", Utils.randomStringGenerator("Client_FirstName_", 5)); map.put("firstname", Utils.randomFirstNameGenerator());
map.put("lastname", Utils.randomStringGenerator("Client_LastName_", 4)); map.put("lastname", Utils.randomLastNameGenerator());
if (externalId != null) { if (externalId != null) {
map.put("externalId", externalId); map.put("externalId", externalId);
} }
@@ -1209,10 +1209,9 @@ public class ClientHelper {
} }
public static PostClientsRequest defaultClientCreationRequest() { public static PostClientsRequest defaultClientCreationRequest() {
return new PostClientsRequest().officeId(1L).legalFormId(LEGALFORM_ID_PERSON) return new PostClientsRequest().officeId(1L).legalFormId(LEGALFORM_ID_PERSON).firstname(Utils.randomFirstNameGenerator())
.firstname(Utils.randomStringGenerator("Client_FirstName_", 5)).lastname(Utils.randomStringGenerator("Client_LastName_", 5)) .lastname(Utils.randomLastNameGenerator()).externalId(UUID.randomUUID().toString()).dateFormat(Utils.DATE_FORMAT)
.externalId(UUID.randomUUID().toString()).dateFormat(Utils.DATE_FORMAT).locale("en").active(true) .locale("en").active(true).activationDate(DEFAULT_DATE);
.activationDate(DEFAULT_DATE);
} }
public LoanAccountLockResponseDTO retrieveLockedAccounts(int page, int limit) { public LoanAccountLockResponseDTO retrieveLockedAccounts(int page, int limit) {
@@ -102,6 +102,24 @@ public final class Utils {
public static final String SOURCE_SET_NUMBERS_AND_LETTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static final String SOURCE_SET_NUMBERS_AND_LETTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String SOURCE_SET_NUMBERS = "1234567890"; public static final String SOURCE_SET_NUMBERS = "1234567890";
private static final List<String> firstNames = List.of("Adam", "Alex", "Andrew", "Anthony", "Arthur", "Benjamin", "Brian", "Brandon",
"Bruce", "Caleb", "Charles", "Christian", "Christopher", "Daniel", "David", "Dennis", "Dominic", "Edward", "Ethan", "Felix",
"Frank", "Gabriel", "George", "Gregory", "Harry", "Henry", "Isaac", "Jack", "Jacob", "James", "Jason", "John", "Jonathan",
"Joseph", "Joshua", "Julian", "Kevin", "Kyle", "Leo", "Liam", "Logan", "Lucas", "Luke", "Marcus", "Mark", "Martin", "Matthew",
"Michael", "Nathan", "Nicholas", "Noah", "Oliver", "Oscar", "Patrick", "Paul", "Peter", "Philip", "Raymond", "Richard",
"Robert", "Ryan", "Samuel", "Scott", "Sean", "Simon", "Stephen", "Steven", "Thomas", "Timothy", "Victor", "William", "Zachary",
"Aaron", "Adrian", "Alan", "Albert", "Allen", "Antonio", "Austin", "Blake", "Cameron", "Carlos", "Colin", "Dylan", "Eric",
"Harrison", "Ian", "Jeremy", "Jordan", "Kevin", "Louis", "Mitchell", "Neil", "Roger", "Trevor");
private static final List<String> lastNames = List.of("Anderson", "Armstrong", "Baker", "Barnes", "Bell", "Bennett", "Brooks", "Brown",
"Bryant", "Butler", "Campbell", "Carter", "Clark", "Collins", "Cook", "Cooper", "Cox", "Davis", "Diaz", "Edwards", "Evans",
"Fisher", "Foster", "Garcia", "Gomez", "Gonzalez", "Gray", "Green", "Hall", "Harris", "Hernandez", "Hill", "Howard", "Hughes",
"Jackson", "James", "Jenkins", "Johnson", "Jones", "Kelly", "Kim", "King", "Lee", "Lewis", "Lopez", "Martin", "Martinez",
"Miller", "Mitchell", "Moore", "Morgan", "Morris", "Murphy", "Nelson", "Nguyen", "Parker", "Perez", "Peterson", "Phillips",
"Powell", "Price", "Ramirez", "Reed", "Richardson", "Rivera", "Roberts", "Robinson", "Rodriguez", "Rogers", "Ross", "Russell",
"Sanchez", "Scott", "Smith", "Stewart", "Taylor", "Thomas", "Thompson", "Torres", "Turner", "Walker", "Ward", "Watson", "White",
"Williams", "Wilson", "Wood", "Wright", "Young", "Zhang");
private Utils() {} private Utils() {}
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
@@ -576,4 +594,12 @@ public final class Utils {
public static Double getDoubleValue(BigDecimal amount) { public static Double getDoubleValue(BigDecimal amount) {
return amount == null ? null : amount.setScale(2, RoundingMode.HALF_UP).doubleValue(); return amount == null ? null : amount.setScale(2, RoundingMode.HALF_UP).doubleValue();
} }
public static String randomFirstNameGenerator() {
return firstNames.get(r.nextInt(firstNames.size()));
}
public static String randomLastNameGenerator() {
return lastNames.get(r.nextInt(lastNames.size()));
}
} }
@@ -220,9 +220,9 @@ public final class UserHelper {
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec); GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
String simpleRoleId = createSimpleRole(requestSpec, responseSpec); String simpleRoleId = createSimpleRole(requestSpec, responseSpec);
PostUsersRequest createUserRequest = new PostUsersRequest().username(SIMPLE_USER_NAME) PostUsersRequest createUserRequest = new PostUsersRequest().username(SIMPLE_USER_NAME)
.firstname(Utils.randomStringGenerator("NotificationFN", 4)).lastname(Utils.randomStringGenerator("NotificationLN", 4)) .firstname(Utils.randomFirstNameGenerator()).lastname(Utils.randomLastNameGenerator()).email("whatever@mifos.org")
.email("whatever@mifos.org").password(password).repeatPassword(password).sendPasswordToEmail(false) .password(password).repeatPassword(password).sendPasswordToEmail(false).roles(List.of(Long.valueOf(simpleRoleId)))
.roles(List.of(Long.valueOf(simpleRoleId))).officeId(headOffice.getId()); .officeId(headOffice.getId());
PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest); PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest);
Assertions.assertNotNull(userCreationResponse.getResourceId()); Assertions.assertNotNull(userCreationResponse.getResourceId());
@@ -243,9 +243,9 @@ public final class UserHelper {
String uniqueUsername = Utils.uniqueRandomStringGenerator("TestUser", 4); String uniqueUsername = Utils.uniqueRandomStringGenerator("TestUser", 4);
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec); GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
return new PostUsersRequest().username(uniqueUsername).firstname("Test").lastname("User").email("testuser@example.com") return new PostUsersRequest().username(uniqueUsername).firstname(Utils.randomFirstNameGenerator())
.password(password).repeatPassword(password).sendPasswordToEmail(false).officeId(headOffice.getId()) .lastname(Utils.randomLastNameGenerator()).email("testuser@example.com").password(password).repeatPassword(password)
.roles(List.of(roleId.longValue())); .sendPasswordToEmail(false).officeId(headOffice.getId()).roles(List.of(roleId.longValue()));
} }
// TODO: Rewrite to use fineract-client instead! // TODO: Rewrite to use fineract-client instead!