Skip to content

Commit

Permalink
Add selenium tests for Issue 51056
Browse files Browse the repository at this point in the history
  • Loading branch information
XingY committed Oct 7, 2024
1 parent 75aba22 commit 5716687
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 72 deletions.
Binary file modified data/samples/ParentSamples.xlsx
Binary file not shown.
8 changes: 4 additions & 4 deletions src/org/labkey/test/tests/SampleTypeLimitsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void doSetup()
.withColumns(List.of(
TestDataGenerator.simpleFieldDef("name", FieldDefinition.ColumnType.String),
TestDataGenerator.simpleFieldDef("label", FieldDefinition.ColumnType.String)));
dgen.addDataSupplier("label", () -> dgen.randomString(10))
dgen.addDataSupplier("label", () -> TestDataGenerator.randomString(10))
.withGeneratedRows(10000);
dgen.createDomain(createDefaultConnection(), SAMPLE_TYPE_DOMAIN_KIND);
SaveRowsResponse saveRowsResponse = dgen.insertRows(createDefaultConnection(), dgen.getRows());
Expand Down Expand Up @@ -235,7 +235,7 @@ public void testInsertLargeLineageGraph() throws IOException, CommandException
));

dgen.createDomain(createDefaultConnection(), SAMPLE_TYPE_DOMAIN_KIND);
Map indexRow = Map.of("name", "seed", "data", dgen.randomInt(3, 2000), "testIndex", 0); // create the first seed in the lineage
Map indexRow = Map.of("name", "seed", "data", TestDataGenerator.randomInt(3, 2000), "testIndex", 0); // create the first seed in the lineage
SaveRowsResponse seedInsert = dgen.insertRows(createDefaultConnection(), List.of(indexRow));
SelectRowsResponse seedSelect = dgen.getRowsFromServer(createDefaultConnection(),
List.of("lsid", "name", "parent", "data", "testIndex"));
Expand All @@ -247,8 +247,8 @@ public void testInsertLargeLineageGraph() throws IOException, CommandException
int intendedGenerationDepth = 99;
for (int i = 0; i < intendedGenerationDepth; i++)
{
String name = dgen.randomString(30);
Map row = Map.of("name", name, "data", dgen.randomInt(3, 1395), "testIndex", testIndex , "MaterialInputs/bigLineage", previousName);
String name = TestDataGenerator.randomString(30);
Map row = Map.of("name", name, "data", TestDataGenerator.randomInt(3, 1395), "testIndex", testIndex , "MaterialInputs/bigLineage", previousName);
dgen.addCustomRow(row);
previousName = name;
testIndex++;
Expand Down
18 changes: 9 additions & 9 deletions src/org/labkey/test/tests/SampleTypeLineageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ public void testLineageWithImplicitParentColumn() throws IOException, CommandExc
TestDataGenerator.simpleFieldDef("stringData", FieldDefinition.ColumnType.String)
));
dgen.createDomain(createDefaultConnection(), SAMPLE_TYPE_DOMAIN_KIND);
dgen.addRow(List.of("A", 12, dgen.randomString(15)));
dgen.addRow(List.of("B", 13, dgen.randomString(15)));
dgen.addRow(List.of("C", 15, dgen.randomString(15)));
dgen.addCustomRow(Map.of("name", "D", "data", 12, "stringData", dgen.randomString(15), "MaterialInputs/implicitParentage", "B"));
dgen.addCustomRow(Map.of("name", "E", "data", 14, "stringData", dgen.randomString(15), "MaterialInputs/implicitParentage", "B"));
dgen.addCustomRow(Map.of("name", "F", "data", 12, "stringData", dgen.randomString(15), "MaterialInputs/implicitParentage", "A,B"));
dgen.addCustomRow(Map.of("name", "G", "data", 12, "stringData", dgen.randomString(15), "MaterialInputs/implicitParentage", "C"));
dgen.addCustomRow(Map.of("name", "H", "data", 14, "stringData", dgen.randomString(15), "MaterialInputs/implicitParentage", "A,B,C"));
dgen.addCustomRow(Map.of("name", "I", "data", 12, "stringData", dgen.randomString(15), "MaterialInputs/implicitParentage", "B,G"));
dgen.addRow(List.of("A", 12, TestDataGenerator.randomString(15)));
dgen.addRow(List.of("B", 13, TestDataGenerator.randomString(15)));
dgen.addRow(List.of("C", 15, TestDataGenerator.randomString(15)));
dgen.addCustomRow(Map.of("name", "D", "data", 12, "stringData", TestDataGenerator.randomString(15), "MaterialInputs/implicitParentage", "B"));
dgen.addCustomRow(Map.of("name", "E", "data", 14, "stringData", TestDataGenerator.randomString(15), "MaterialInputs/implicitParentage", "B"));
dgen.addCustomRow(Map.of("name", "F", "data", 12, "stringData", TestDataGenerator.randomString(15), "MaterialInputs/implicitParentage", "A,B"));
dgen.addCustomRow(Map.of("name", "G", "data", 12, "stringData", TestDataGenerator.randomString(15), "MaterialInputs/implicitParentage", "C"));
dgen.addCustomRow(Map.of("name", "H", "data", 14, "stringData", TestDataGenerator.randomString(15), "MaterialInputs/implicitParentage", "A,B,C"));
dgen.addCustomRow(Map.of("name", "I", "data", 12, "stringData", TestDataGenerator.randomString(15), "MaterialInputs/implicitParentage", "B,G"));

SaveRowsResponse saveRowsResponse = dgen.insertRows(createDefaultConnection(), dgen.getRows());

Expand Down
93 changes: 40 additions & 53 deletions src/org/labkey/test/tests/SampleTypeNameExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class SampleTypeNameExpressionTest extends BaseWebDriverTest
private static final String PARENT_SAMPLE_04 = "#parent04";
private static final String PARENT_SAMPLE_05 = "\"parent05";
private static final String PARENT_SAMPLE_06 = "parent,06";
private static final String PARENT_SAMPLE_07 = "\"parent07";

private static final File PARENT_EXCEL = TestFileUtils.getSampleData("samples/ParentSamples.xlsx");

Expand All @@ -96,6 +97,16 @@ public static void setupProject() throws IOException, CommandException
test.doSetup();
}

private void addDataRow(TestDataGenerator dataGenerator, String name, int intVal)
{
Map<String, Object> sampleData = Map.of(
"name", name,
"Int", intVal,
"Str", "Parent Sample " + ((char) (intVal + 95)),
"Date", intVal + "/14/2020");
dataGenerator.addCustomRow(sampleData);
}

private void doSetup() throws IOException, CommandException
{
_containerHelper.createProject(getProjectName(), null);
Expand All @@ -116,47 +127,13 @@ private void doSetup() throws IOException, CommandException
log(String.format("Give the parent sample type '%1$s' three samples named '%2$s', '%3$s' and '%4$s'.",
PARENT_SAMPLE_TYPE, PARENT_SAMPLE_01, PARENT_SAMPLE_02, PARENT_SAMPLE_03));

Map<String, Object> sampleData = Map.of(
"name", PARENT_SAMPLE_01,
"Int", 1,
"Str", "Parent Sample A",
"Date", "7/14/2020");
dataGenerator.addCustomRow(sampleData);

sampleData = Map.of(
"name", PARENT_SAMPLE_02,
"Int", 2,
"Str", "Parent Sample B",
"Date", "11/21/2019");
dataGenerator.addCustomRow(sampleData);

sampleData = Map.of(
"name", PARENT_SAMPLE_03,
"Int", 3,
"Str", "Parent Sample C",
"Date", "12/25/2015");
dataGenerator.addCustomRow(sampleData);

sampleData = Map.of(
"name", PARENT_SAMPLE_04,
"Int", 4,
"Str", "Parent Sample D",
"Date", "12/25/2019");
dataGenerator.addCustomRow(sampleData);

sampleData = Map.of(
"name", PARENT_SAMPLE_05,
"Int", 5,
"Str", "Parent Sample E",
"Date", "12/28/2023");
dataGenerator.addCustomRow(sampleData);

sampleData = Map.of(
"name", PARENT_SAMPLE_06,
"Int", 6,
"Str", "Parent Sample F",
"Date", "12/31/2023");
dataGenerator.addCustomRow(sampleData);
addDataRow(dataGenerator, PARENT_SAMPLE_01, 1);
addDataRow(dataGenerator, PARENT_SAMPLE_02, 2);
addDataRow(dataGenerator, PARENT_SAMPLE_03, 3);
addDataRow(dataGenerator, PARENT_SAMPLE_04, 4);
addDataRow(dataGenerator, PARENT_SAMPLE_05, 5);
addDataRow(dataGenerator, PARENT_SAMPLE_06, 6);
addDataRow(dataGenerator, PARENT_SAMPLE_07, 7);

dataGenerator.insertRows();

Expand Down Expand Up @@ -230,14 +207,17 @@ public void testDeriveFromCommentLikeParents()

DataRegionTable materialTable = new DataRegionTable("Material", this);
List<String> names = materialTable.getColumnDataAsText("Name");
Collections.reverse(names);

log("generated sample names:");
names.forEach(this::log);

assertEquals(2, names.size());

assertEquals(PARENT_SAMPLE_01 + "-child", names.get(1));
assertEquals("[" + PARENT_SAMPLE_01 + ", " + PARENT_SAMPLE_02 + ", " + PARENT_SAMPLE_03 + "]-child", names.get(0));
List<String> expectedNames = new ArrayList<>();
expectedNames.add(PARENT_SAMPLE_01 + "-child");
expectedNames.add("[" + PARENT_SAMPLE_01 + ", " + PARENT_SAMPLE_02 + ", " + PARENT_SAMPLE_03 + "]-child");
assertEquals("Sample names are not as expected", expectedNames, names);

log("Verify import tsv should successfully create derivatives from parent starting with #, as long as this is not the 1st field in the row");
data = "Description\tMaterialInputs/" + PARENT_SAMPLE_TYPE + "\n";
Expand All @@ -247,13 +227,16 @@ public void testDeriveFromCommentLikeParents()
sampleHelper.bulkImport(data);

names = materialTable.getColumnDataAsText("Name");
Collections.reverse(names);

log("generated sample names:");
names.forEach(this::log);

assertEquals(4, names.size());

assertEquals("[" + PARENT_SAMPLE_03 + ", " + PARENT_SAMPLE_02 + "]-child", names.get(0));
assertEquals(PARENT_SAMPLE_03 + "-child", names.get(1));
expectedNames.add(PARENT_SAMPLE_03 + "-child");
expectedNames.add("[" + PARENT_SAMPLE_03 + ", " + PARENT_SAMPLE_02 + "]-child");
assertEquals("Sample names are not as expected", expectedNames, names);

log("Check that lineage is created as expected.");
clickAndWait(Locator.linkWithText(PARENT_SAMPLE_03 + "-child"));
Expand All @@ -265,23 +248,27 @@ public void testDeriveFromCommentLikeParents()
sampleHelper.bulkImport(PARENT_EXCEL);

names = materialTable.getColumnDataAsText("Name");
Collections.reverse(names);
log("generated sample names:");
names.forEach(this::log);

assertEquals(9, names.size());
assertEquals(PARENT_SAMPLE_06 + "-child", names.get(0));
assertEquals(PARENT_SAMPLE_05 + "-child", names.get(1));
assertEquals("[" + PARENT_SAMPLE_01 + ", " + PARENT_SAMPLE_04 + "]-child", names.get(2));
assertEquals("[" + PARENT_SAMPLE_04 + ", " + PARENT_SAMPLE_03 + "]-child", names.get(3));
assertEquals(PARENT_SAMPLE_04 + "-child", names.get(4));
assertEquals(10, names.size());
expectedNames.add(PARENT_SAMPLE_04 + "-child");
expectedNames.add("[" + PARENT_SAMPLE_04 + ", " + PARENT_SAMPLE_03 + "]-child");
expectedNames.add("[" + PARENT_SAMPLE_01 + ", " + PARENT_SAMPLE_04 + "]-child");
expectedNames.add(PARENT_SAMPLE_05 + "-child");
expectedNames.add(PARENT_SAMPLE_06 + "-child");
expectedNames.add("[" + PARENT_SAMPLE_07 + ", " + PARENT_SAMPLE_05 + "]-child");
assertEquals("Sample names are not as expected", expectedNames, names);

log("Verify importing tsv to create sample with # should work, as long as this is not the 1st field in the row");
data = "Description\tName\n";
data += "should succeed\t#RootSample1\n";
sampleHelper.bulkImport(data);
names = materialTable.getColumnDataAsText("Name");
assertEquals(10, names.size());
assertEquals("#RootSample1", names.get(0));
Collections.reverse(names);
assertEquals(11, names.size());
expectedNames.add("#RootSample1");

log("Verify importing tsv to create sample should ignore lines starting with #");
data = "Name\tDescription\n";
Expand Down
2 changes: 1 addition & 1 deletion src/org/labkey/test/tests/component/GridPanelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void createSmallSampleType() throws IOException, CommandException

sampleSetDataGenerator.addCustomRow(
Map.of(FILTER_NAME_COL, String.format("%s%d", SMALL_SAMPLE_PREFIX, rowCount),
FILTER_INT_COL, sampleSetDataGenerator.randomInt(1, INT_MAX),
FILTER_INT_COL, TestDataGenerator.randomInt(1, INT_MAX),
FILTER_STRING_COL, stringSets.get(setIndex++),
FILTER_DATE_COL, sampleSetDataGenerator.randomDateString(DateUtils.addWeeks(new Date(), -25), new Date()),
FILTER_BOOL_COL, sampleSetDataGenerator.randomBoolean())
Expand Down
47 changes: 42 additions & 5 deletions src/org/labkey/test/util/TestDataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
public class TestDataGenerator
{
// chose a Character random from this String
private static final String ALPHANUMERIC_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvxyz";
private static final String CHARSET_STRING = "ABCD01234vxyz~!@#$%^&*()-+=_{}[]|:;\"',.<>";

private final Map<String, PropertyDescriptor> _columns = new CaseInsensitiveLinkedHashMap<>();
private final Map<String, Supplier<Object>> _dataSuppliers = new CaseInsensitiveHashMap<>();
Expand Down Expand Up @@ -289,18 +289,30 @@ private Supplier<Object> getDefaultDataSupplier(String columnType)
}
}

public String randomString(int size)
public static String randomString(int size)
{
return randomString(size, null);
}

public static String randomString(int size, String exclusion)
{
StringBuilder val = new StringBuilder();
for (int i=0; i<size; i++)
{
int randIndex = (int)(ALPHANUMERIC_STRING.length() * Math.random());
val.append(ALPHANUMERIC_STRING.charAt(randIndex));
char selected;
do
{
int randIndex = (int)(CHARSET_STRING.length() * Math.random());
selected = CHARSET_STRING.charAt(randIndex);
}
while (exclusion != null && exclusion.contains(selected + ""));

val.append(selected);
}
return val.toString();
}

public int randomInt(int min, int max)
public static int randomInt(int min, int max)
{
if (min >= max)
throw new IllegalArgumentException("min must be less than max");
Expand Down Expand Up @@ -521,6 +533,31 @@ public SaveRowsResponse insertRows(Connection cn, List<Map<String, Object>> rows
return getQueryHelper(cn).insertRows(rows);
}

public static <T> List<T> shuffleSelect(List<T> allFields, int selectCount)
{
return shuffleSelect(allFields, selectCount, false);
}

public static <T> List<T> shuffleSelect(List<T> allFields, int selectCount, boolean canRepeat)
{
if (!canRepeat)
{
List<T> shuffled = new ArrayList<>(allFields);
Collections.shuffle(shuffled);
return shuffled.subList(0, selectCount - 1);
}
else
{
List<T> selected = new ArrayList<>();
for (int i = 0; i < selectCount; i++)
{
selected.add(allFields.get(randomInt(0, allFields.size())));
}
return selected;
}

}

/**
* @deprecated Use {@link QueryApiHelper}
*/
Expand Down

0 comments on commit 5716687

Please sign in to comment.