-
Notifications
You must be signed in to change notification settings - Fork 3
/
RoCrateWriterSpec12Test.java
57 lines (47 loc) · 2.38 KB
/
RoCrateWriterSpec12Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package edu.kit.datamanager.ro_crate.writer;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import edu.kit.datamanager.ro_crate.Crate;
import edu.kit.datamanager.ro_crate.HelpFunctions;
import edu.kit.datamanager.ro_crate.reader.FolderReader;
import edu.kit.datamanager.ro_crate.reader.RoCrateReader;
class RoCrateWriterSpec12Test {
@Test
void writeDoesNotModifyTest(@TempDir Path tempDir) throws IOException, URISyntaxException {
// read crate (not the actual part of this test)
String internalOriginalCratePath = "crates/spec-1.2-DRAFT/minimal-with-conformsTo-Array";
URL internalOriginalCrateURL = this.getClass().getResource("/" + internalOriginalCratePath);
assertNotNull(internalOriginalCrateURL);
Crate crate = new RoCrateReader(new FolderReader()).readCrate(internalOriginalCrateURL.getPath());
Path targetDir = tempDir.resolve("spec12writeUnmodified");
{
// save to disk
RoCrateWriter folderRoCrateWriter = new RoCrateWriter(new FolderWriter());
folderRoCrateWriter.save(crate, targetDir.toFile().getPath());
}
// compare directories
Path srcDir = Paths.get(internalOriginalCrateURL.toURI());
assertTrue(HelpFunctions.compareTwoDir(targetDir.toFile(), srcDir.toFile()));
// compare original metadata file with crate class
HelpFunctions.compareCrateJsonToFileInResources(
crate,
"/" + internalOriginalCratePath + "/ro-crate-metadata.json");
// compare exported metadata file with original metadata file
HelpFunctions.compareCrateJsonToFileInResources(
// created metadata file
targetDir.resolve("ro-crate-metadata.json").toFile(),
// original metadata file
new File(srcDir.resolve("ro-crate-metadata.json").toString()));
// Compare loaded crate object with crate object made of export
Crate crate2 = new RoCrateReader(new FolderReader()).readCrate(targetDir.toString());
HelpFunctions.compareTwoCrateJson(crate, crate2);
}
}