Siba/test/org/dclermonte/siba/model/SibaManagerTest.java

97 lines
2.7 KiB
Java
Raw Normal View History

package org.dclermonte.siba.model;
2016-05-15 16:56:10 +02:00
import java.io.File;
import java.io.IOException;
2016-08-26 23:05:24 +02:00
import java.security.NoSuchAlgorithmException;
import org.apache.commons.compress.archivers.ArchiveException;
2016-05-16 23:40:07 +02:00
import org.apache.commons.io.FileUtils;
2016-05-19 18:40:00 +02:00
import org.dclermonte.siba.SibaException;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
*
* @author cpm
*/
public class SibaManagerTest
{
2016-08-26 23:05:24 +02:00
/**
*
*/
@Test
public void aFooTest()
{
Assert.assertTrue(true);
}
2016-08-26 23:05:24 +02:00
/**
*
* @throws IOException
2016-08-31 21:41:40 +02:00
* IOException
2016-08-26 23:05:24 +02:00
* @throws ArchiveException
2016-08-31 21:41:40 +02:00
* ArchiveException
* @throws SibaException
* specific sibaException
2016-08-26 23:05:24 +02:00
*/
@Test(expectedExceptions = SibaException.class)
public void backupTest01() throws ArchiveException, IOException, SibaException
{
SibaManager.backup(null, null);
}
2016-05-15 16:56:10 +02:00
2016-08-26 23:05:24 +02:00
/**
2016-08-31 21:41:40 +02:00
* Test the archive generated
2016-08-26 23:05:24 +02:00
*
* @throws ArchiveException
2016-08-31 21:41:40 +02:00
* ArchiveException
2016-08-26 23:05:24 +02:00
* @throws IOException
2016-08-31 21:41:40 +02:00
* IOException
* @throws SibaException
* specific sibaException
2016-08-26 23:05:24 +02:00
*/
@Test
public void backupTest02() throws ArchiveException, IOException, SibaException
{
File source = new File("test/org/dclermonte/siba/data/simplestuff");
2016-08-31 21:41:40 +02:00
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");
2016-08-31 21:41:40 +02:00
2016-08-26 23:05:24 +02:00
Boolean fileEquals = FileUtils.contentEquals(reference, target);
2016-08-31 21:41:40 +02:00
File targetMD5 = new File(target.getAbsolutePath() + ".md5");
target.delete();
targetMD5.delete();
2016-08-26 23:05:24 +02:00
// Test.
Assert.assertTrue(fileEquals);
}
2016-05-15 16:56:10 +02:00
2016-08-31 21:41:40 +02:00
/**
* Test the md5 calculation
*
* @throws ArchiveException
* Archive Exception
* @throws IOException
* IOException
* @throws SibaException
* specific sibaException
* @throws NoSuchAlgorithmException
* NosuchAlgorithmException
*/
2016-08-26 23:05:24 +02:00
@Test
public void backupTest03() throws ArchiveException, IOException, SibaException, NoSuchAlgorithmException
{
2016-08-31 21:41:40 +02:00
File source = new File("test/org/dclermonte/siba/data/reference/simplestuff-2016-08-30T22h44mn21s.tgz");
String md5Calculate = SibaUtils.md5(source);
File reference = new File("test/org/dclermonte/siba/data/reference/simplestuff-2016-08-30T22h44mn21s.tgz.md5");
2016-08-26 23:05:24 +02:00
String md5Reference = SibaUtils.loadMD5Sum(reference);
2016-08-31 21:41:40 +02:00
2016-08-26 23:05:24 +02:00
// Test.
Assert.assertEquals(md5Calculate, md5Reference);
2016-08-31 21:41:40 +02:00
2016-08-26 23:05:24 +02:00
}
}