Skip to content
Snippets Groups Projects
Commit a56aa48b authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- added some tests

parent b14ed74d
No related branches found
No related tags found
No related merge requests found
Pipeline #3396 passed
package org.slub.rosetta.dps.repository.plugin.storage.nfs;
import com.exlibris.core.sdk.storage.containers.StoredEntityMetaData;
import com.exlibris.digitool.common.dnx.DnxDocument;
import com.exlibris.digitool.common.dnx.DnxDocumentFactory;
import com.exlibris.digitool.common.storage.Fixity;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link org.slub.rosetta.dps.repository.plugin.storage.nfs.SLUBStoragePlugin}.
......@@ -15,22 +31,98 @@ import static org.junit.Assert.assertEquals;
* @author andreas.romeyke@slub-dresden.de (Andreas Romeyke)
*/
@RunWith(JUnit4.class)
public class TestSLUBStoragePlugin {
@Test
public void getStreamDirectory() {
SLUBStoragePlugin mock = new SLUBStoragePlugin();
private static SLUBStoragePlugin mock;
private static Path testroot;
@Before
public void setUp() throws IOException {
testroot = Files.createTempDirectory("testslubstorage");
Files.createFile(Path.of(testroot.toAbsolutePath().toString() + "/foo"));
mock = new SLUBStoragePlugin();
HashMap<String, String> map = new HashMap<String,String> ();
map.put("DIR_ROOT", "./");
map.put("DIR_ROOT", testroot.toAbsolutePath().toString());
map.put("BLOCK_SIZE", "8192");
map.put("FILES_HANDLING_METHOD", "move");
mock.setParameters( map );
mock.init(map);
// TODO:
}
// @Test
// public void getDirRoot() {
//SLUBStoragePlugin mock = new SLUBStoragePlugin();
//assertEquals(mock.getDirRoot());
// }
@Test
public void getStreamDirectory() {
File calced_path = mock.getStreamDirectory("foo", "bar");
//System.out.println("getStreamDirectory:"+ calced_path.getName()+ "\n");
assertEquals("getStreamDirectory test", "bar", calced_path.getName());
}
@Test
public void checkFixity() {
List<Fixity> fixities = new ArrayList<>();
try {
var result = mock.checkFixity(fixities, "/tmp/foo");
assertTrue("checkFixity", result);
}
catch (Exception e) {
assertEquals("checkFixity", "foo", e);
}
}
@Test
public void getFullFilePath() {
assertEquals( "getFullFilePath", testroot.toAbsolutePath().toString()+"/2022", mock.getFullFilePath("/2022"));
}
@Test
public void retrieveEntity() {
try {
InputStream is = mock.retrieveEntity("/foo");
assertTrue("retrieveEntity", true);
} catch (Exception e) {
assertEquals("retrieveEntity", "", e);
}
}
@Test
public void retrieveEntitybyRange() {
try {
byte[] bytes = mock.retrieveEntityByRange("/foo", 0, 0);
assertTrue("retrieveEntitybyRange", true);
} catch (java.io.EOFException e) {
assertEquals("retrieveEntitybyRange", null, e.getMessage());
} catch (Exception e) {
assertEquals("retrieveEntitybyRange", "", e.getMessage());
}
}
@Test
public void storeEntity() throws IOException {
byte[] bytes = "teststring".getBytes(StandardCharsets.UTF_8);
InputStream is = new ByteArrayInputStream(bytes);
StoredEntityMetaData sem = new StoredEntityMetaData();
sem.setCurrentFilePath("/bar");
sem.setIePid(null);
File file = new File("resources/iemets.xml");
InputStream ioStream = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(ioStream);
char[] charArray = new char[(int)file.length()];
isr.read(charArray);
String iemets = new String(charArray);
try {
DnxDocument dnx = DnxDocumentFactory.getInstance().createDnxDocument(false);
dnx.setDocumentXml(iemets);
sem.setIeDnx(dnx);
sem.setEntityType(StoredEntityMetaData.EntityType.IE);
mock.storeEntity(is, sem);
}
catch (NoClassDefFoundError e) {
/* FIXME: Test irgendwie den org/springframework/context/ApplicationContext verpassen... */
assertEquals("storeEntity", "org/springframework/context/ApplicationContext", e.getMessage());
}
catch (Exception e) {
assertEquals("storeEntity", "", e.getMessage());
}
}
/*
@Test
public void getStreamRelativePath() throws Exception {
......@@ -59,4 +151,6 @@ public class TestSLUBStoragePlugin {
mock.getStreamRelativePath( storedEntityMetaData);
}
*/
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment