diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/storage/filesystem/DirectoryTest.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/storage/filesystem/DirectoryTest.java index 13e9f8c2622e067c3a72f7373f6f671ff048b5c7..43ba575c4f1f5f6376e502f92c40e724b443d066 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/storage/filesystem/DirectoryTest.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/storage/filesystem/DirectoryTest.java @@ -33,10 +33,49 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.utilities.FileUtilities; /** + * Test cases for corresponding {@link Directory} class. + * * @author Franz-Josef Elmer */ public class DirectoryTest extends StorageTestCase { + + private final void testInternalAddFile(final boolean move) + { + File dir = new File(TEST_DIR, "dir"); + dir.mkdirs(); + FileUtilities.writeToFile(new File(dir, "p1"), "property 1"); + File subDir = new File(dir, "subdir"); + subDir.mkdir(); + FileUtilities.writeToFile(new File(subDir, "p2"), "property 2"); + File dest = new File(TEST_DIR, "destination"); + dest.mkdir(); + Directory directory = new Directory(dest); + INode copiedDir = directory.addFile(dir, move); + assertEquals("dir", copiedDir.getName()); + assertTrue(copiedDir instanceof IDirectory); + File copiedRealDir = new File(dest, "dir"); + assertTrue(copiedRealDir.isDirectory()); + IDirectory cd = (IDirectory) copiedDir; + INode node = cd.tryToGetNode("p1"); + assertNotNull(node); + assertTrue(node instanceof IFile); + assertEquals("property 1\n", ((IFile) node).getStringContent()); + assertEquals("property 1\n", FileUtilities.loadToString(new File(copiedRealDir, "p1"))); + node = cd.tryToGetNode("subdir"); + assertEquals("subdir", node.getName()); + assertNotNull(node); + assertTrue(node instanceof IDirectory); + node = ((IDirectory) node).tryToGetNode("p2"); + File copiedRealSubDir = new File(copiedRealDir, "subdir"); + assertTrue(copiedRealSubDir.isDirectory()); + assertEquals("p2", node.getName()); + assertTrue(node instanceof IFile); + assertEquals("property 2\n", ((IFile) node).getStringContent()); + assertEquals("property 2\n", FileUtilities.loadToString(new File(copiedRealSubDir, "p2"))); + assertEquals(move == false, new File(TEST_DIR, "dir").exists()); + } + @Test public void testGetName() { @@ -116,40 +155,14 @@ public class DirectoryTest extends StorageTestCase } @Test - public void testAddFile() + public void testAddFileWithCopy() { - File dir = new File(TEST_DIR, "dir"); - dir.mkdirs(); - FileUtilities.writeToFile(new File(dir, "p1"), "property 1"); - File subDir = new File(dir, "subdir"); - subDir.mkdir(); - FileUtilities.writeToFile(new File(subDir, "p2"), "property 2"); - File dest = new File(TEST_DIR, "destination"); - dest.mkdir(); - Directory directory = new Directory(dest); - - INode copiedDir = directory.addFile(dir, false); + testInternalAddFile(false); + } - assertEquals("dir", copiedDir.getName()); - assertTrue(copiedDir instanceof IDirectory); - File copiedRealDir = new File(dest, "dir"); - assertTrue(copiedRealDir.isDirectory()); - IDirectory cd = (IDirectory) copiedDir; - INode node = cd.tryToGetNode("p1"); - assertNotNull(node); - assertTrue(node instanceof IFile); - assertEquals("property 1\n", ((IFile) node).getStringContent()); - assertEquals("property 1\n", FileUtilities.loadToString(new File(copiedRealDir, "p1"))); - node = cd.tryToGetNode("subdir"); - assertEquals("subdir", node.getName()); - assertNotNull(node); - assertTrue(node instanceof IDirectory); - node = ((IDirectory) node).tryToGetNode("p2"); - File copiedRealSubDir = new File(copiedRealDir, "subdir"); - assertTrue(copiedRealSubDir.isDirectory()); - assertEquals("p2", node.getName()); - assertTrue(node instanceof IFile); - assertEquals("property 2\n", ((IFile) node).getStringContent()); - assertEquals("property 2\n", FileUtilities.loadToString(new File(copiedRealSubDir, "p2"))); + @Test + public void testAddFileWithMove() + { + testInternalAddFile(true); } } diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ProcessRunnerTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ProcessRunnerTest.java index 8f6fb89a9348ed62450529119493db71a22162e2..34aea6a4e45d6f82870fbdbda328bbaa44428109 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ProcessRunnerTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ProcessRunnerTest.java @@ -16,6 +16,8 @@ package ch.systemsx.cisd.common.utilities; +import static org.testng.AssertJUnit.fail; + import org.jmock.Expectations; import org.jmock.Mockery; import org.testng.annotations.AfterMethod; @@ -93,4 +95,41 @@ public class ProcessRunnerTest new ProcessRunner(process); context.assertIsSatisfied(); } + + @Test + public final void testRunWithNegativeValues() + { + context.checking(new Expectations() + { + { + one(process).getMillisToSleepOnFailure(); + will(returnValue(-1L)); + + one(process).getMaxRetryOnFailure(); + will(returnValue(-1)); + } + }); + try + { + new ProcessRunner(process); + fail("Negative value for millis to sleep on failure not allowed"); + } catch (AssertionError ex) + { + // Nothing to do here + } + context.checking(new Expectations() + { + { + one(process).getMillisToSleepOnFailure(); + will(returnValue(0L)); + + one(process).getMaxRetryOnFailure(); + will(returnValue(-100)); + + one(process).run(); + } + }); + new ProcessRunner(process); + context.assertIsSatisfied(); + } }