From 3e237e65d34e89b970a21d68d1341452996bdb3e Mon Sep 17 00:00:00 2001 From: labkey-tchad Date: Thu, 14 Aug 2025 09:10:29 -0700 Subject: [PATCH 1/4] Fix failures introduced by recent test changes --- .../filecontent/FileContentUploadTest.java | 2 +- .../labkey/test/util/TestDataGenerator.java | 72 ++++++++++--------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java b/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java index 09c50d4fa3..50b7249a04 100644 --- a/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java +++ b/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java @@ -356,7 +356,7 @@ public void testCalculateFileRootSize() throws Exception Integer initialFileRootSize = getFileRootSize(); - switchToMainWindow(); + closeExtraWindows(); goToProjectHome(); File testFile = TestFileUtils.getSampleData("fileTypes/tsv_sample.tsv"); diff --git a/src/org/labkey/test/util/TestDataGenerator.java b/src/org/labkey/test/util/TestDataGenerator.java index 1128cce0bc..ef613bb5ae 100644 --- a/src/org/labkey/test/util/TestDataGenerator.java +++ b/src/org/labkey/test/util/TestDataGenerator.java @@ -56,6 +56,7 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; +import java.util.function.Function; import java.util.function.Supplier; import java.util.regex.Pattern; @@ -428,46 +429,51 @@ private Map generateRow() private Supplier getDefaultDataSupplier(PropertyDescriptor propertyDescriptor) { Map allProperties = Objects.requireNonNullElse(propertyDescriptor.getAllProperties(), Collections.emptyMap()); - String columnType = (String) allProperties.get("conceptURI"); - if (columnType == null) columnType = propertyDescriptor.getRangeURI(); + Function getType = s -> s.substring(s.indexOf('#') + 1).toLowerCase(); + String conceptUriName = getType.apply((String) allProperties.get("conceptURI")); + String rangeUriName = getType.apply(propertyDescriptor.getRangeURI()); - switch (columnType.substring(columnType.indexOf('#') + 1).toLowerCase()) + switch (conceptUriName) { - case "string": - return () -> randomString(20, _excludedChars, _alphaNumericStr ? ALPHANUMERIC_STRING : CHARSET_STRING); - case "int": - return () -> randomInt(0, 20); - case "float": - return () -> randomFloat(0, 20); - case "double": - return () -> randomDouble(0, 20); - case "boolean": - return this::randomBoolean; - case "date": - case "datetime": - return () -> randomDateString(DateUtils.addWeeks(new Date(), -39), new Date()); - case "time": - return () -> - randomInt(0, 23) + ":" + // hour - StringUtils.leftPad(String.valueOf(randomInt(0, 59)), 2, "0") + ":" + // minute - StringUtils.leftPad(String.valueOf(randomInt(0, 59)), 2, "0") + "." + // second - StringUtils.leftPad(String.valueOf(randomInt(0, 999)), 3, "0"); // millisecond case "textchoice": List textChoices = ((FieldDefinition) propertyDescriptor) - .getValidators().stream() - .map(v -> { - if (v instanceof FieldDefinition.TextChoiceValidator tcv && !tcv.getValues().isEmpty()) - return tcv.getValues(); - else - return null; - }) - .filter(Objects::nonNull) - .findFirst() - .orElseThrow(() -> new IllegalStateException("No choices defined for textChoice field : " + propertyDescriptor.getName())); + .getValidators().stream() + .map(v -> { + if (v instanceof FieldDefinition.TextChoiceValidator tcv && !tcv.getValues().isEmpty()) + return tcv.getValues(); + else + return null; + }) + .filter(Objects::nonNull) + .findFirst() + .orElseThrow(() -> new IllegalStateException("No choices defined for textChoice field : " + propertyDescriptor.getName())); return () -> randomChoice(textChoices); default: - throw new IllegalArgumentException("ColumnType " + columnType + " isn't implemented yet"); + switch (rangeUriName) + { + case "string": + return () -> randomString(20, _excludedChars, _alphaNumericStr ? ALPHANUMERIC_STRING : CHARSET_STRING); + case "int": + return () -> randomInt(0, 20); + case "float": + return () -> randomFloat(0, 20); + case "double": + return () -> randomDouble(0, 20); + case "boolean": + return this::randomBoolean; + case "date": + case "datetime": + return () -> randomDateString(DateUtils.addWeeks(new Date(), -39), new Date()); + case "time": + return () -> + randomInt(0, 23) + ":" + // hour + StringUtils.leftPad(String.valueOf(randomInt(0, 59)), 2, "0") + ":" + // minute + StringUtils.leftPad(String.valueOf(randomInt(0, 59)), 2, "0") + "." + // second + StringUtils.leftPad(String.valueOf(randomInt(0, 999)), 3, "0"); // millisecond + default: + throw new IllegalArgumentException("ColumnType " + conceptUriName + " isn't implemented yet"); + } } } From 33cb9dd67a815e6d009ec62cd1980e62d1a9fad1 Mon Sep 17 00:00:00 2001 From: labkey-tchad Date: Thu, 14 Aug 2025 09:53:33 -0700 Subject: [PATCH 2/4] Make doAndWaitForWindow work correctly --- src/org/labkey/test/WebDriverWrapper.java | 29 +++++++++++-------- .../filecontent/FileContentUploadTest.java | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/org/labkey/test/WebDriverWrapper.java b/src/org/labkey/test/WebDriverWrapper.java index ec09a9d74c..7a2f817cb0 100644 --- a/src/org/labkey/test/WebDriverWrapper.java +++ b/src/org/labkey/test/WebDriverWrapper.java @@ -148,6 +148,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; @@ -2118,25 +2119,29 @@ public long doAndMaybeWaitForPageToLoad(int msWait, Supplier action) public long doAndWaitForWindow(Runnable action, String windowName) { + String initialWindow = getDriver().getWindowHandle(); + AtomicBoolean targetWindowExists = new AtomicBoolean(false); + try + { + getDriver().switchTo().window(windowName); + targetWindowExists.set(true); + } + catch (NoSuchWindowException e) + { + targetWindowExists.set(false); + } + + // Call doAndMaybeWaitForPageToLoad with target window in focus (if present) + // Then it will correctly detect the page load in that window return doAndMaybeWaitForPageToLoad(10_000, () -> { - String initialWindow = getDriver().getWindowHandle(); - boolean targetWindowExists; - try - { - getDriver().switchTo().window(windowName); + if (targetWindowExists.get()) getDriver().switchTo().window(initialWindow); - targetWindowExists = true; - } - catch (NoSuchWindowException e) - { - targetWindowExists = false; - } action.run(); new WebDriverWait(getDriver(), Duration.ofSeconds(5)).until(windowIsPresent(windowName)); - return targetWindowExists; + return targetWindowExists.get(); }); } diff --git a/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java b/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java index 50b7249a04..09c50d4fa3 100644 --- a/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java +++ b/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java @@ -356,7 +356,7 @@ public void testCalculateFileRootSize() throws Exception Integer initialFileRootSize = getFileRootSize(); - closeExtraWindows(); + switchToMainWindow(); goToProjectHome(); File testFile = TestFileUtils.getSampleData("fileTypes/tsv_sample.tsv"); From f0f50d736ea52e5dc71ecf30b6725fc7562cc3b2 Mon Sep 17 00:00:00 2001 From: labkey-tchad Date: Thu, 14 Aug 2025 10:47:39 -0700 Subject: [PATCH 3/4] Fix NPE --- src/org/labkey/test/util/TestDataGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/labkey/test/util/TestDataGenerator.java b/src/org/labkey/test/util/TestDataGenerator.java index ef613bb5ae..709663937f 100644 --- a/src/org/labkey/test/util/TestDataGenerator.java +++ b/src/org/labkey/test/util/TestDataGenerator.java @@ -429,7 +429,7 @@ private Map generateRow() private Supplier getDefaultDataSupplier(PropertyDescriptor propertyDescriptor) { Map allProperties = Objects.requireNonNullElse(propertyDescriptor.getAllProperties(), Collections.emptyMap()); - Function getType = s -> s.substring(s.indexOf('#') + 1).toLowerCase(); + Function getType = s -> s == null ? null : s.substring(s.indexOf('#') + 1).toLowerCase(); String conceptUriName = getType.apply((String) allProperties.get("conceptURI")); String rangeUriName = getType.apply(propertyDescriptor.getRangeURI()); From 60fa94be6d93e68879dbe52bb50f9ec07a8deaec Mon Sep 17 00:00:00 2001 From: labkey-tchad Date: Thu, 14 Aug 2025 14:17:22 -0700 Subject: [PATCH 4/4] Fix a different NPE --- src/org/labkey/test/util/TestDataGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/labkey/test/util/TestDataGenerator.java b/src/org/labkey/test/util/TestDataGenerator.java index 709663937f..b1cf92193b 100644 --- a/src/org/labkey/test/util/TestDataGenerator.java +++ b/src/org/labkey/test/util/TestDataGenerator.java @@ -429,7 +429,7 @@ private Map generateRow() private Supplier getDefaultDataSupplier(PropertyDescriptor propertyDescriptor) { Map allProperties = Objects.requireNonNullElse(propertyDescriptor.getAllProperties(), Collections.emptyMap()); - Function getType = s -> s == null ? null : s.substring(s.indexOf('#') + 1).toLowerCase(); + Function getType = s -> s == null ? "" : s.substring(s.indexOf('#') + 1).toLowerCase().trim(); String conceptUriName = getType.apply((String) allProperties.get("conceptURI")); String rangeUriName = getType.apply(propertyDescriptor.getRangeURI());