improved test by using tmpdir

This commit is contained in:
Didier Clermonté 2016-08-31 21:41:40 +02:00
parent 86584648cc
commit a7ccec04ba
3 changed files with 32 additions and 9 deletions

Binary file not shown.

View File

@ -1,3 +0,0 @@
#!/bin/sh
java -jar Siba.jar $1 $2 $3 $4

View File

@ -28,8 +28,11 @@ public class SibaManagerTest
/** /**
* *
* @throws IOException * @throws IOException
* IOException
* @throws ArchiveException * @throws ArchiveException
* @throws SibaNullException * ArchiveException
* @throws SibaException
* specific sibaException
*/ */
@Test(expectedExceptions = SibaException.class) @Test(expectedExceptions = SibaException.class)
public void backupTest01() throws ArchiveException, IOException, SibaException public void backupTest01() throws ArchiveException, IOException, SibaException
@ -38,33 +41,56 @@ public class SibaManagerTest
} }
/** /**
* Test the archive generated
* *
* @throws ArchiveException * @throws ArchiveException
* ArchiveException
* @throws IOException * @throws IOException
* @throws SibaNullException * IOException
* @throws SibaException
* specific sibaException
*/ */
@Test @Test
public void backupTest02() throws ArchiveException, IOException, SibaException public void backupTest02() throws ArchiveException, IOException, SibaException
{ {
File source = new File("test/org/dclermonte/siba/data/simplestuff"); File source = new File("test/org/dclermonte/siba/data/simplestuff");
File target = SibaManager.backup(source, new File("test/org/dclermonte/siba/data/result"));
File target = SibaManager.backup(source, new File(System.getProperty("java.io.tmpdir")));
File reference = new File("test/org/dclermonte/siba/data/reference/simplestuff-2016-08-30T22h44mn21s.tgz"); File reference = new File("test/org/dclermonte/siba/data/reference/simplestuff-2016-08-30T22h44mn21s.tgz");
Boolean fileEquals = FileUtils.contentEquals(reference, target); Boolean fileEquals = FileUtils.contentEquals(reference, target);
File targetMD5 = new File(target.getAbsolutePath() + ".md5");
target.delete();
targetMD5.delete();
// Test. // Test.
Assert.assertTrue(fileEquals); Assert.assertTrue(fileEquals);
} }
/**
* Test the md5 calculation
*
* @throws ArchiveException
* Archive Exception
* @throws IOException
* IOException
* @throws SibaException
* specific sibaException
* @throws NoSuchAlgorithmException
* NosuchAlgorithmException
*/
@Test @Test
public void backupTest03() throws ArchiveException, IOException, SibaException, NoSuchAlgorithmException public void backupTest03() throws ArchiveException, IOException, SibaException, NoSuchAlgorithmException
{ {
File source = new File("test/org/dclermonte/siba/data/simplestuff"); File source = new File("test/org/dclermonte/siba/data/reference/simplestuff-2016-08-30T22h44mn21s.tgz");
File target = SibaManager.backup(source, new File("test/org/dclermonte/siba/data/result"));
String md5Calculate = SibaUtils.md5(target); String md5Calculate = SibaUtils.md5(source);
File reference = new File("test/org/dclermonte/siba/data/reference/simplestuff-2016-08-30T22h44mn21s.tgz.md5"); File reference = new File("test/org/dclermonte/siba/data/reference/simplestuff-2016-08-30T22h44mn21s.tgz.md5");
String md5Reference = SibaUtils.loadMD5Sum(reference); String md5Reference = SibaUtils.loadMD5Sum(reference);
// Test. // Test.
Assert.assertEquals(md5Calculate, md5Reference); Assert.assertEquals(md5Calculate, md5Reference);
} }
} }