FINERACT-2421: Generate better client names during testing
This commit is contained in:
committed by
Arnold Gálovics
parent
d61b5e65f9
commit
967e0ea306
+2
-2
@@ -34,8 +34,8 @@ public class ClientRequestFactory {
|
||||
return new PostClientsRequest()//
|
||||
.officeId(HEAD_OFFICE_ID)//
|
||||
.legalFormId(LEGAL_FORM_ID_PERSON)//
|
||||
.firstname(Utils.randomNameGenerator("Client_FirstName_", 5))//
|
||||
.lastname(Utils.randomNameGenerator("Client_LastName_", 5))//
|
||||
.firstname(Utils.randomFirstNameGenerator())//
|
||||
.lastname(Utils.randomLastNameGenerator())//
|
||||
.externalId(randomClientId("ID_", 7))//
|
||||
.dateFormat(DATE_FORMAT)//
|
||||
.locale(DEFAULT_LOCALE)//
|
||||
|
||||
+16
-16
@@ -129,7 +129,7 @@ public class LoanProductsRequestFactory {
|
||||
public static final String CHARGE_OFF_REASONS = "ChargeOffReasons";
|
||||
|
||||
public PostLoanProductsRequest defaultLoanProductsRequestLP1() {
|
||||
String name = Utils.randomNameGenerator(NAME_PREFIX, 10);
|
||||
String name = Utils.randomStringGenerator(NAME_PREFIX, 10);
|
||||
String shortName = generateShortNameSafely();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -239,7 +239,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
public PostLoanProductsRequest defaultLoanProductsRequestLP1InterestFlat() {
|
||||
String name = Utils.randomNameGenerator(NAME_PREFIX_INTEREST_FLAT, 10);
|
||||
String name = Utils.randomStringGenerator(NAME_PREFIX_INTEREST_FLAT, 10);
|
||||
String shortName = generateShortNameSafely();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -347,7 +347,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
public PostLoanProductsRequest defaultLoanProductsRequestLP1InterestDeclining() {
|
||||
String name = Utils.randomNameGenerator(NAME_PREFIX_INTEREST_DECLINING, 10);
|
||||
String name = Utils.randomStringGenerator(NAME_PREFIX_INTEREST_DECLINING, 10);
|
||||
String shortName = generateShortNameSafely();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -455,7 +455,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -568,7 +568,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -678,7 +678,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
List<LoanProductChargeToGLAccountMapper> penaltyToIncomeAccountMappings = new ArrayList<>();
|
||||
@@ -793,7 +793,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
public PostLoanProductsRequest defaultLoanProductsRequestLP2() {
|
||||
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2, 10);
|
||||
String name = Utils.randomStringGenerator(NAME_PREFIX_LP2, 10);
|
||||
String shortName = generateShortNameSafely();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -906,7 +906,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -1017,7 +1017,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
public PostLoanProductsRequest defaultLoanProductsRequestLP2Emi() {
|
||||
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2_EMI, 10);
|
||||
String name = Utils.randomStringGenerator(NAME_PREFIX_LP2_EMI, 10);
|
||||
String shortName = generateShortNameSafely();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -1127,7 +1127,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
public PostLoanProductsRequest defaultLoanProductsRequestLP2EmiWithChargeOff() {
|
||||
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2_EMI, 10);
|
||||
String name = Utils.randomStringGenerator(NAME_PREFIX_LP2_EMI, 10);
|
||||
String shortName = generateShortNameSafely();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -1257,7 +1257,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
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 List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -1379,7 +1379,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
public PostLoanProductsRequest defaultLoanProductsRequestLP2EmiCashAccounting() {
|
||||
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2_EMI, 10);
|
||||
String name = Utils.randomStringGenerator(NAME_PREFIX_LP2_EMI, 10);
|
||||
String shortName = generateShortNameSafely();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -1506,7 +1506,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
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 List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
final List<Integer> numberOfRepaymentVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -1655,7 +1655,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
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 List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
final List<Integer> numberOfRepaymentVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -1793,7 +1793,7 @@ public class LoanProductsRequestFactory {
|
||||
}
|
||||
|
||||
public PostLoanProductsRequest defaultLoanProductsRequestLP2EmiUSD() {
|
||||
String name = Utils.randomNameGenerator(NAME_PREFIX_LP2_EMI, 10);
|
||||
String name = Utils.randomStringGenerator(NAME_PREFIX_LP2_EMI, 10);
|
||||
String shortName = generateShortNameSafely();
|
||||
|
||||
List<Integer> principalVariationsForBorrowerCycle = new ArrayList<>();
|
||||
@@ -1901,7 +1901,7 @@ public class LoanProductsRequestFactory {
|
||||
int counter = 0;
|
||||
do {
|
||||
counter++;
|
||||
generatedShortName = Utils.randomNameGenerator("", 4);
|
||||
generatedShortName = Utils.randomStringGenerator("", 4);
|
||||
if (counter > 999) {
|
||||
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.time.Clock;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
public final class Utils {
|
||||
|
||||
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() {}
|
||||
|
||||
@@ -41,8 +59,12 @@ public final class Utils {
|
||||
return randomStringGenerator(prefix, len, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
public static String randomFirstNameGenerator() {
|
||||
return firstNames.get(random.nextInt(firstNames.size()));
|
||||
}
|
||||
|
||||
public static String randomLastNameGenerator() {
|
||||
return lastNames.get(random.nextInt(lastNames.size()));
|
||||
}
|
||||
|
||||
public static LocalDate now() {
|
||||
|
||||
+7
-7
@@ -115,7 +115,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
|
||||
// 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);
|
||||
if (transferExternalId == null) {
|
||||
transferExternalId = Utils.randomNameGenerator("TestTransferExtId_", 3);
|
||||
transferExternalId = Utils.randomStringGenerator("TestTransferExtId_", 10);
|
||||
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))) {
|
||||
String ownerExternalId;
|
||||
if (regenerateOwner) {
|
||||
ownerExternalId = Utils.randomNameGenerator(OWNER_EXTERNAL_ID_PREFIX, 3);
|
||||
ownerExternalId = Utils.randomStringGenerator(OWNER_EXTERNAL_ID_PREFIX, 10);
|
||||
} else {
|
||||
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
|
||||
String transferExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED);
|
||||
if (transferExternalId == null) {
|
||||
transferExternalId = Utils.randomNameGenerator("TestTransferExtId_", 3);
|
||||
transferExternalId = Utils.randomStringGenerator("TestTransferExtId_", 10);
|
||||
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,
|
||||
response.getResourceExternalId());
|
||||
} 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))//
|
||||
.ownerExternalId(ownerExternalId)//
|
||||
@@ -494,7 +494,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
|
||||
.dateFormat(DATE_FORMAT_ASSET_EXT)//
|
||||
.locale(DEFAULT_LOCALE);//
|
||||
} 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))//
|
||||
.ownerExternalId(ownerExternalId)//
|
||||
@@ -788,7 +788,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
|
||||
String transferExternalId = testContext()
|
||||
.get(TestContextKey.ASSET_EXTERNALIZATION_TRANSFER_EXTERNAL_ID_USER_GENERATED + "_" + type);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -923,7 +923,7 @@ public class AssetExternalizationStepDef extends AbstractStepDef {
|
||||
public void createAssetExternalizationRequestByLoanIdUserGeneratedExtIdForceTransferIdNoTestOwner(String type, DataTable table)
|
||||
throws IOException {
|
||||
// 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);
|
||||
|
||||
createAssetExternalizationRequestByLoanId(table, transferExternalId, false);
|
||||
|
||||
+4
-4
@@ -47,7 +47,7 @@ public class UserStepDef extends AbstractStepDef {
|
||||
@When("Admin creates new user with {string} username, {string} role name and given permissions:")
|
||||
public void createUserWithUsernameAndRoles(String username, String roleName, List<String> permissions) {
|
||||
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));
|
||||
Long roleId = createNewRole.getResourceId();
|
||||
Map<String, Boolean> permissionMap = new HashMap<>();
|
||||
@@ -56,12 +56,12 @@ public class UserStepDef extends AbstractStepDef {
|
||||
.permissions(permissionMap);
|
||||
ok(() -> fineractClient.roles().updateRolePermissions(roleId, putRolesRoleIdPermissionsRequest));
|
||||
|
||||
String generatedUsername = Utils.randomNameGenerator(username, 8);
|
||||
String generatedUsername = Utils.randomStringGenerator(username, 8);
|
||||
PostUsersRequest postUsersRequest = new PostUsersRequest() //
|
||||
.username(generatedUsername) //
|
||||
.email(EMAIL) //
|
||||
.firstname(username) //
|
||||
.lastname(username) //
|
||||
.firstname(Utils.randomFirstNameGenerator()) //
|
||||
.lastname(Utils.randomLastNameGenerator()) //
|
||||
.sendPasswordToEmail(Boolean.FALSE) //
|
||||
.officeId(1L) //
|
||||
.password(PWD_USER_WITH_ROLE) //
|
||||
|
||||
+1
-1
@@ -3161,7 +3161,7 @@ public class LoanStepDef extends AbstractStepDef {
|
||||
PostLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
long loanId = loanResponse.getLoanId();
|
||||
|
||||
String reversalExternalId = Utils.randomNameGenerator("reversalExtId_", 3);
|
||||
String reversalExternalId = Utils.randomStringGenerator("reversalExtId_", 10);
|
||||
PostLoansLoanIdTransactionsRequest chargeOffUndoRequest = LoanRequestFactory.defaultUndoChargeOffRequest()
|
||||
.reversalExternalId(reversalExternalId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user