diff --git a/src/org/labkey/test/components/Component.java b/src/org/labkey/test/components/Component.java index 121cf23249..386ed6f99a 100644 --- a/src/org/labkey/test/components/Component.java +++ b/src/org/labkey/test/components/Component.java @@ -16,6 +16,7 @@ package org.labkey.test.components; import org.apache.commons.lang3.NotImplementedException; +import org.jetbrains.annotations.NotNull; import org.labkey.test.Locator; import org.labkey.test.selenium.RefindingWebElement; import org.labkey.test.util.TestLogger; @@ -27,6 +28,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.function.Function; @@ -43,13 +45,13 @@ public String toString() } @Override - public WebElement findElement(By by) + public @NotNull WebElement findElement(@NotNull By by) { return getComponentElement().findElement(by); } @Override - public List findElements(By by) + public @NotNull List findElements(@NotNull By by) { return getComponentElement().findElements(by); } @@ -69,8 +71,9 @@ protected EC elementCache() // Pass if element doesn't exist. Might be checking if component is visible. } - _elementCache = newElementCache(); + _elementCache = Objects.requireNonNull(newElementCache()); waitForReady(); + Objects.requireNonNull(_elementCache, "waitForReady() cleared the element cache"); } return _elementCache; } @@ -103,13 +106,13 @@ protected ElementCache() } @Override - public List findElements(By by) + public @NotNull List findElements(@NotNull By by) { return getComponentElement().findElements(by); } @Override - public WebElement findElement(By by) + public @NotNull WebElement findElement(@NotNull By by) { return getComponentElement().findElement(by); } diff --git a/src/org/labkey/test/tests/InlineImagesListTest.java b/src/org/labkey/test/tests/InlineImagesListTest.java index 05c82e15d2..056a9b6d85 100644 --- a/src/org/labkey/test/tests/InlineImagesListTest.java +++ b/src/org/labkey/test/tests/InlineImagesListTest.java @@ -28,6 +28,9 @@ import org.labkey.test.TestTimeoutException; import org.labkey.test.WebTestHelper; import org.labkey.test.categories.Daily; +import org.labkey.test.components.list.ManageListsGrid; +import org.labkey.test.pages.ImportDataPage; +import org.labkey.test.pages.list.BeginPage; import org.labkey.test.pages.list.EditListDefinitionPage; import org.labkey.test.params.FieldDefinition; import org.labkey.test.params.FieldDefinition.ColumnType; @@ -35,6 +38,7 @@ import org.labkey.test.util.DataRegionTable; import org.labkey.test.util.ExcelHelper; import org.labkey.test.util.TestDataGenerator; +import org.labkey.test.util.data.TestDataUtils; import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -44,6 +48,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -52,6 +57,9 @@ @BaseWebDriverTest.ClassTimeout(minutes = 5) public class InlineImagesListTest extends BaseWebDriverTest { + private final static String PROJECT_NAME = "Inline Images List Test Project"; + private final static String IMPORT_PROJECT_NAME = "Inline Images List Import Test Project"; + protected final static String LIST_NAME = TestDataGenerator.randomDomainName("InlineImagesList"); protected final static String LIST_KEY_NAME = TestDataGenerator.randomFieldName("Key"); protected final static ColumnType LIST_KEY_TYPE = ColumnType.Integer; @@ -99,7 +107,7 @@ public List getAssociatedModules() @Override protected String getProjectName() { - return "InlineImagesListTestProject"; + return PROJECT_NAME; } @Override @@ -111,7 +119,8 @@ protected BrowserType bestBrowser() @Override public void doCleanup(boolean afterTest) throws TestTimeoutException { - _containerHelper.deleteProject(getProjectName(), afterTest); + _containerHelper.deleteProject(PROJECT_NAME, afterTest); + _containerHelper.deleteProject(IMPORT_PROJECT_NAME, afterTest); } @Before @@ -327,5 +336,51 @@ public final void testList() throws Exception assertTrue("Height of row 2 not in expected range (" + ROW_HEIGHT_SMALL_LBOUND + " to " + ROW_HEIGHT_SMALL_UBOUND + "). Actual height: " + sheet.getRow(2).getHeight(), (sheet.getRow(2).getHeight() > ROW_HEIGHT_SMALL_LBOUND) && (sheet.getRow(2).getHeight() < ROW_HEIGHT_SMALL_UBOUND)); assertTrue("Height of row 3 not in expected range (" + ROW_HEIGHT_TEXT_LBOUND + " to " + ROW_HEIGHT_TEXT_UBOUND + "). Actual height: " + sheet.getRow(3).getHeight(), (sheet.getRow(3).getHeight() > ROW_HEIGHT_TEXT_LBOUND) && (sheet.getRow(3).getHeight() < ROW_HEIGHT_TEXT_UBOUND)); } + + log("Verify list archive export/import can round trip attachment successfully"); + ManageListsGrid listsGrid = BeginPage.beginAt(this, getProjectName()).getGrid(); + listsGrid.checkAllOnPage(); + File listArchive = listsGrid.exportSelectedLists(); + + _containerHelper.createProject(IMPORT_PROJECT_NAME); + + BeginPage.beginAt(this, IMPORT_PROJECT_NAME).importListArchive(listArchive); + _listHelper.goToList(LIST_NAME); + + // Validate that list is imported as expected with attachments + assertElementPresent("Did not find the expected number of icons for images for " + LRG_PNG_FILE.getName(), Locator.xpath("//img[contains(@title, '" + LRG_PNG_FILE.getName() + "')]"), 1); + assertElementPresent("Did not find the expected number of icons for images for " + JPG01_FILE.getName(), Locator.xpath("//img[contains(@title, '" + JPG01_FILE.getName() + "')]"), 1); + assertElementPresent("Did not find the expected number of icons for images for " + PDF_FILE.getName(), Locator.xpath("//img[contains(@src, 'pdf.gif')]"), 1); + assertElementPresent("Did not find the expected text for " + PDF_FILE.getName(), Locator.xpath("//a[contains(text(), '" + PDF_FILE.getName() + "')]"), 1); + + // Issue 53498: reject string attachment values for import + ImportDataPage listImportPage = _listHelper.clickImportData(); + importFilePathError(listImportPage, "5", "absent.txt"); + importFilePathError(listImportPage, "5", PDF_FILE.getName()); + listImportPage.setCopyPasteMerge(false, true); + importFilePathError(listImportPage, "1", "absent.txt"); + importFilePathError(listImportPage, "1", PDF_FILE.getName()); + listImportPage.setCopyPasteMerge(true, true); + importFilePathError(listImportPage, "1", "absent.txt"); + importFilePathError(listImportPage, "1", PDF_FILE.getName()); + importFilePathError(listImportPage, "5", PDF_FILE.getName()); + } + + private void importFilePathError(ImportDataPage listImportPage, String key, String attachmentValue) + { + String pasteData = TestDataUtils.tsvStringFromRowMaps(List.of(Map.of(LIST_KEY_NAME, key, LIST_ATTACHMENT01_NAME, attachmentValue)), + List.of(LIST_KEY_NAME, LIST_ATTACHMENT01_NAME), true); + log(pasteData); + listImportPage.setText(pasteData); + listImportPage.submitExpectingError(); + try + { + String expectedError = "Row 1: Can't upload '" + attachmentValue + "' to field " + LIST_ATTACHMENT01_NAME + " with type Attachment."; + checker().withScreenshot("import_error").verifyTrue("Invalid attachment error not as expected", isElementPresent(Locator.tagWithClass("div", "labkey-error").withText(expectedError))); + } + catch(NoSuchElementException nse) + { + checker().error("Invalid attachment error not present."); + } } } diff --git a/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java b/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java index e15f49c784..09c50d4fa3 100644 --- a/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java +++ b/src/org/labkey/test/tests/filecontent/FileContentUploadTest.java @@ -353,8 +353,11 @@ public void testCalculateFileRootSize() throws Exception { String calculateFileRootSizeTask = "Calculate file root sizes"; goToAdminConsole().clickSystemMaintenance().runMaintenanceTask(calculateFileRootSizeTask); + Integer initialFileRootSize = getFileRootSize(); + switchToMainWindow(); + goToProjectHome(); File testFile = TestFileUtils.getSampleData("fileTypes/tsv_sample.tsv"); @@ -363,6 +366,9 @@ public void testCalculateFileRootSize() throws Exception goToAdminConsole().clickSystemMaintenance().runMaintenanceTask(calculateFileRootSizeTask); Integer finalFileRootSize = getFileRootSize(); + + switchToMainWindow(); + if (!checker().wrapAssertion(() -> Assertions.assertThat(finalFileRootSize) .as("Crawled file root size").isGreaterThan(initialFileRootSize))) {