Skip to content
Snippets Groups Projects
Commit 0aa79c85 authored by Jules Paget's avatar Jules Paget
Browse files

Finshed test of siard service and clean code

parent cd11d2a2
No related branches found
No related tags found
1 merge request!275Draft: JPA Siard tool
......@@ -72,9 +72,13 @@ public class SiardService extends Tools implements CommandLineRunner {
"Alain Mast, Swiss Federal Archives, Berne, Switzerland",
"Krystyna Ohnesorge, Swiss Federal Archives, Berne, Switzerland" })));
@Autowired
private SiardConfig siardConfig;
@Autowired
public SiardService(SiardConfig siardConfig) {
this.siardConfig = siardConfig;
}
@Override
public void run(String... args) throws Exception {
......
package ch.dlcm.test.tools;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.ObjectInputStream.GetField;
import java.nio.file.Path;
import java.nio.file.Paths;
import ch.admin.bar.siard2.*;
import ch.dlcm.siard.*;
import ch.dlcm.siard.config.SiardConfig;
import ch.unige.solidify.util.ZipTool;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.mockito.Mock;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.ResourceUtils;
@RunWith(SpringRunner.class)
public class SiardTest {
/* TODO change dataBaseManagementSystem and databaseLocation depending on what DBMS you want to test
(cf Siard User usage manual) */
private String dataBaseManagementSystem = "access";
// e.g dbserver.enterag.ch for DB/2
private Path databaseLocation = Paths.get("src","test","resources").resolve("databaseTest.accdb").toAbsolutePath();
// e.g 50000/testdb for DB/2
private String databaseUrl;
private String workingDir;
private String user;
private String password;
private File siardFile;
private File expectedSiardFile;
private SiardService siardService;
@Mock
protected SiardConfig siardConfig;
@Before
public void setup() {
databaseUrl = "dbtest.accdb";
workingDir = System.getProperty("java.io.tmpdir");
databaseUrl = "jdbc:"+ dataBaseManagementSystem+":"+databaseLocation;
user = "user";
password = "passphrase";
siardFile = new File("siardTest.zip");
siardFile = new File("newSiardFile.zip");
expectedSiardFile = Paths.get("src","test","resources").resolve("siard-file-test.zip").toFile();
siardService = new SiardService(siardConfig);
}
@MockBean
SiardService siardService;
@Test
public void siardFromDbTest() throws Exception {
//TODO an integration test ?
File result = siardService.exportDatabase(siardFile, databaseUrl, password, user);
File expected = ResourceUtils.getFile(this.getClass().getResource("siard-file-test.zip").getFile());
assertEquals("database wrongly exported", expected, result);
@After
public void purge() {
siardFile.delete();
}
@Test
public void zipToUploadValidationTest() throws Exception {
//TODO a unit test ? Must use Backend -> see with other
public void siardFromDbTest() throws Exception {
File result = this.siardService.exportDatabase(siardFile, databaseUrl, password, user);
ZipTool resultZipTool = new ZipTool(result.toURI());
ZipTool expectedZipTool = new ZipTool(expectedSiardFile.toURI());
assertTrue(resultZipTool.checkZip());
assertEquals(expectedZipTool.getEntryNumber(), resultZipTool.getEntryNumber());
// assertEquals("database wrongly exported", expectedZipTool, resultZipTool); // TODO find a new way of comparing zip archives
}
@Test
public void unzipSiardArchive() throws Exception {
//TODO a unit test
}
}
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