Skip to content

Commit

Permalink
Add TestDataGenerator.randomFieldName (#2261)
Browse files Browse the repository at this point in the history
- TestDataGenerator.randomFieldName for including combinations of special characters at start and end of field names
Co-authored-by: rosalinep <rosalinep@labkey.com>
  • Loading branch information
cnathe authored Feb 17, 2025
1 parent 532008f commit ff0e108
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/org/labkey/test/util/TestDataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import java.util.function.Supplier;
import java.util.regex.Pattern;

import static org.labkey.test.BaseWebDriverTest.ALL_ILLEGAL_QUERY_KEY_CHARACTERS;


/**
* Use this class to generate random test data for a given column schema
Expand Down Expand Up @@ -355,6 +357,19 @@ public static String randomDomainName(int size)
return domainName;
}

public static String randomFieldName(String part)
{
return randomFieldName(part, randomInt(0, 5), randomInt(0, 5));
}
public static String randomFieldName(String part, int numStartChars, int numEndChars)
{
// use the characters that we know are encoded in fieldKeys plus characters that we know clients are using
String chars = ALL_ILLEGAL_QUERY_KEY_CHARACTERS + " %()=+-[]_|*`'\":;<>?!@#^";
String randomFieldName = (randomString(numStartChars, null, chars) + part + randomString(numEndChars, null, chars)).trim();
TestLogger.log("Generated random field name: " + randomFieldName);
return randomFieldName;
}

public static int randomInt(int min, int max)
{
if (min >= max)
Expand Down

0 comments on commit ff0e108

Please sign in to comment.