-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathPayloadVerifierTest.java
More file actions
75 lines (58 loc) · 2.61 KB
/
PayloadVerifierTest.java
File metadata and controls
75 lines (58 loc) · 2.61 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package gov.loc.repository.bagit.verify;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.Executors;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import gov.loc.repository.bagit.domain.Bag;
import gov.loc.repository.bagit.exceptions.FileNotInManifestException;
import gov.loc.repository.bagit.exceptions.FileNotInPayloadDirectoryException;
import gov.loc.repository.bagit.hash.StandardBagitAlgorithmNameToSupportedAlgorithmMapping;
import gov.loc.repository.bagit.reader.BagReader;
public class PayloadVerifierTest {
private Path rootDir = Paths.get(new File("src/test/resources/bags/v0_97/bag").toURI());
private BagReader reader = new BagReader();
private ManifestVerifier sut;
@BeforeEach
public void setup(){
sut = new ManifestVerifier(new StandardBagitAlgorithmNameToSupportedAlgorithmMapping());
}
@Test
public void testOtherConstructors() throws Exception {
rootDir = Paths.get(new File("src/test/resources/bags/v0_96/bag-with-tagfiles-in-payload-manifest").toURI());
Bag bag = reader.read(rootDir);
sut = new ManifestVerifier();
sut.verifyManifests(bag, true);
sut = new ManifestVerifier(Executors.newCachedThreadPool());
sut.verifyManifests(bag, true);
}
@Test
public void testErrorWhenManifestListFileThatDoesntExist() throws Exception{
rootDir = Paths.get(new File("src/test/resources/filesInManifestDontExist").toURI());
Bag bag = reader.read(rootDir);
Assertions.assertThrows(FileNotInPayloadDirectoryException.class,
() -> { sut.verifyManifests(bag, true); });
}
@Test
public void testErrorWhenFileIsntInManifest() throws Exception{
rootDir = Paths.get(new File("src/test/resources/filesInPayloadDirAreNotInManifest").toURI());
Bag bag = reader.read(rootDir);
Assertions.assertThrows(FileNotInManifestException.class,
() -> { sut.verifyManifests(bag, true); });
}
@Test
public void testBagWithTagFilesInPayloadIsValid() throws Exception{
rootDir = Paths.get(new File("src/test/resources/bags/v0_96/bag-with-tagfiles-in-payload-manifest").toURI());
Bag bag = reader.read(rootDir);
sut.verifyManifests(bag, true);
}
@Test
public void testNotALlFilesListedInAllManifestsThrowsException() throws Exception{
Path bagDir = Paths.get(new File("src/test/resources/notAllFilesListedInAllManifestsBag").toURI());
Bag bag = reader.read(bagDir);
Assertions.assertThrows(FileNotInManifestException.class,
() -> { sut.verifyManifests(bag, true); });
}
}