Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/org/labkey/test/tests/component/GridPanelViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public class GridPanelViewTest extends GridPanelBaseTest
private static final String COL_STRING2 = "Str2";
private static final String COL_INT = "Int";
private static final String COL_BOOL = "Bool";
public static final List<String> TEXT_MULTI_CHOICE_LIST = randomTextChoice(10);
// Excluded semicolon due to GitHub Issue 1096
public static final List<String> TEXT_MULTI_CHOICE_LIST = randomTextChoice(10, ";");
public static final String COL_MULTITEXTCHOICE = "Multi Choice";

private static final boolean MULTI_CHOICE_ENABLED = WebTestHelper.getDatabaseType() == DatabaseType.PostgreSQL;
Expand Down
39 changes: 24 additions & 15 deletions src/org/labkey/test/util/TestDataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
Expand Down Expand Up @@ -178,7 +177,7 @@ else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.String))
else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.TextChoice))
{
FieldDefinition.TextChoiceValidator validator =
(FieldDefinition.TextChoiceValidator) fieldDefinition.getValidators().get(0);
(FieldDefinition.TextChoiceValidator) fieldDefinition.getValidators().getFirst();
List<String> textChoices = validator.getValues();
int textChoiceIndex = i % textChoices.size();
if (forGridInsert)
Expand Down Expand Up @@ -432,10 +431,7 @@ private Map<String, Object> generateRow()
final Map<String, Object> newRow = new CaseInsensitiveHashMap<>();
for (String columnName : _columns.keySet())
{
if (!_dataSuppliers.containsKey(columnName))
{
_dataSuppliers.put(columnName, getDefaultDataSupplier(_columns.get(columnName)));
}
_dataSuppliers.computeIfAbsent(columnName, k -> getDefaultDataSupplier(_columns.get(k)));

if (_autoGeneratedFields.contains(columnName))
{
Expand Down Expand Up @@ -504,12 +500,18 @@ public static String randomString(int size)
return randomString(size, null);
}

public static List<String> randomTextChoice(int size)
public static List<String> randomTextChoice(int size, @Nullable String exclusion)
{
Set<String> textChoices = new LinkedHashSet<>();
int attempts = 0;
final int maxTries = Math.max(MAX_RANDOM_TRIES, size * 2);
while (textChoices.size() < size)
{
String generated = randomString(randomInt(1, 25), ";").trim();
if (++attempts >= maxTries)
{
throw new IllegalStateException("Failed to generate " + size + " unique text choices after " + maxTries + " attempts");
}
String generated = randomString(randomInt(1, 25), exclusion).trim();
if (!generated.isEmpty())
{
textChoices.add(generated);
Expand All @@ -518,6 +520,11 @@ public static List<String> randomTextChoice(int size)
return List.copyOf(textChoices);
}

public static List<String> randomTextChoice(int size)
{
return randomTextChoice(size, null);
}

public static String randomString(int size, @Nullable String exclusion)
{
return randomString(size, exclusion, CHARSET_STRING);
Expand All @@ -532,13 +539,13 @@ public static String randomString(int size, @Nullable String exclusion, @Nullabl
StringBuilder val = new StringBuilder();
for (int i=0; i<size; i++)
{
int randIndex = (int)(charSetFrom.length() * Math.random());
int randIndex = ThreadLocalRandom.current().nextInt(charSetFrom.length());
char c = charSetFrom.charAt(randIndex);
if (c == REPEAT_PLACEHOLDER)
{
randIndex = (int)(charSetFrom.length() * Math.random());
randIndex = ThreadLocalRandom.current().nextInt(charSetFrom.length());
c = charSetFrom.charAt(randIndex);
int repeatCount = randomInt(2, 50); // repeat between 2 and 50 times
int repeatCount = randomInt(2, 5); // repeat between 2 and 5 times
val.append(StringUtils.repeat(c, repeatCount));
}
else if (c == ALL_CHARS_PLACEHOLDER)
Expand All @@ -548,7 +555,8 @@ else if (c == WIDE_PLACEHOLDER)
else
val.append(c);
}
return val.toString();
// Collapse consecutive spaces into one to match what the UI displays.
return val.toString().replaceAll(" {2,}", " ");
}

public static String randomMultiLineString(int size)
Expand Down Expand Up @@ -684,7 +692,8 @@ public static String randomFieldName(@NotNull String part, @Nullable Integer num
}

TestLogger.log("Generated random field name for domainKind " + _domainKind + ": " + randomFieldName);
return randomFieldName.name();
// Consistent with randomDomainName: UI collapses multiple whitespace chars to a single space
return randomFieldName.name().replaceAll("\\s+", " ");
}

private static boolean isDomainAndFieldNameInvalid(DomainKind domainKind, @Nullable RandomName domainName, @Nullable RandomName fieldName)
Expand Down Expand Up @@ -994,7 +1003,7 @@ public ImportDataResponse importRows(Connection cn, List<Map<String, Object>> ro

public static <T> List<T> shuffleSelect(List<T> allFields)
{
int randomSize = new Random().nextInt(allFields.size()) + 1;
int randomSize = ThreadLocalRandom.current().nextInt(allFields.size()) + 1;
return shuffleSelect(allFields, randomSize);
}

Expand Down Expand Up @@ -1027,7 +1036,7 @@ public static <T> List<T> randomSelect(List<T> allOptions, int selectCount)
List<T> selected = new ArrayList<>();
for (int i = 0; i < selectCount; i++)
{
selected.add(allOptions.get(randomInt(0, allOptions.size())));
selected.add(allOptions.get(randomInt(0, allOptions.size() - 1)));
}
return selected;
}
Expand Down
Loading