Skip to content
Open
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
28 changes: 27 additions & 1 deletion src/org/labkey/test/TestFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.bouncycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder;
import org.bouncycastle.util.io.Streams;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.labkey.api.util.FileUtil;
import org.jetbrains.annotations.Nullable;
import org.openqa.selenium.NotFoundException;
Expand Down Expand Up @@ -445,14 +446,39 @@ public static void deleteDir(File dir)
}
}

/**
* Rename a directory.
* @param sourceDir the directory to rename
* @param newDirName the new name for the directory
* @return return the path to the renamed directory
*/
public static Path renameDir(Path sourceDir, String newDirName) throws IOException
{
LOG.info("Renaming {} to {}", sourceDir, newDirName);

// Check if the directory is outside the test enlistment.
checkFileLocation(sourceDir.toFile());

Assert.assertTrue("Directory does not exist: " + sourceDir, sourceDir.toFile().exists());

Path newDir = sourceDir.getParent() != null
? sourceDir.getParent().resolve(newDirName)
: Paths.get(newDirName);
Files.move(sourceDir, newDir);

LOG.info("Renamed {} to {}", sourceDir, newDir);

return newDir;
}

private static void checkFileLocation(File file)
{
try
{
if (!FileUtils.directoryContains(getLabKeyRoot(), file))
{
// TODO: Consider throwing IllegalArgumentException
LOG.info("DEBUG: Attempting to delete a file outside of test enlistment: " + getLabKeyRoot());
LOG.info("DEBUG: Attempting to delete / rename a file outside of test enlistment: " + getLabKeyRoot());
}
}
catch (IOException ignore) { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.labkey.test.tests.assay;

import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.api.util.FileUtil;
Expand All @@ -16,6 +18,7 @@
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;

/**
* Issue 54156: Regression test to ensure a reasonable error message is shown when an assay design references
Expand All @@ -29,7 +32,7 @@ public void testMissingParentDirectoryRegression() throws Exception
{
// Create a nested directory and an R transform script within it
String assayName = "missingParentDirAssay";
Path parentDir = Files.createTempDirectory("assay-transform-parent-");
Path parentDir = Files.createTempDirectory("assay-transform-missing-parent-");
Path nestedDir = FileUtil.createDirectories(parentDir.resolve("child"), false);
String scriptName = "transformMissingParent.R";
String transformContent = "library(Rlabkey);";
Expand All @@ -45,8 +48,17 @@ public void testMissingParentDirectoryRegression() throws Exception
assayDesignerPage.addTransformScript(transformFile);
assayDesignerPage.clickSave();

// Now delete the parent dir to ensure we handle it reasonably
TestFileUtils.deleteDir(parentDir.toFile());
// Rename the parent dir to ensure we handle it reasonably. Deleting directories on Windows is not always
// timely, renaming the directory will have the same effect.
String newName = "Not-Here-" + UUID.randomUUID();
Path renamedDir = TestFileUtils.renameDir(parentDir, newName);

Assert.assertFalse(String.format("Directory %s is still present.", parentDir),
FileUtils.isDirectory(parentDir.toFile()));

// Delete the renamed directory as a cleanup step. Since the directory has been renamed, the slow delete on Windows
// will not cause the test to fail.
TestFileUtils.deleteDir(renamedDir.toFile());

// Attempt to import data and verify a reasonable error message is shown
String importData = """
Expand Down Expand Up @@ -85,6 +97,7 @@ public void testMissingParentDirectoryRegression() throws Exception

// Verify we land on the run details page and can see the run name (no transform needed)
new AssayRunsPage(getDriver()).clickAssayIdLink("fixedAssayImport");

}

}
Loading