Skip to content
Snippets Groups Projects
Commit 7f132729 authored by ribeaudc's avatar ribeaudc
Browse files

change:

- improve unit tests

SVN: 2224
parent 67c5db7c
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
......@@ -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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment