use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadVersion2_0Bag.
@Test
public void testReadVersion2_0Bag() throws Exception {
Path rootBag = Paths.get(getClass().getClassLoader().getResource("bags/v2_0/bag").toURI());
Path[] payloadFiles = new Path[] { rootBag.resolve("dir1/test3.txt"), rootBag.resolve("dir2/dir3/test5.txt"), rootBag.resolve("dir2/test4.txt"), rootBag.resolve("test1.txt"), rootBag.resolve("test2.txt") };
Bag returnedBag = sut.read(rootBag);
assertNotNull(returnedBag);
assertEquals(new Version(2, 0), returnedBag.getVersion());
Manifest payloadManifest = (Manifest) returnedBag.getPayLoadManifests().toArray()[0];
for (Path payloadFile : payloadFiles) {
assertTrue("payload manifest should contain " + payloadFile, payloadManifest.getFileToChecksumMap().containsKey(payloadFile));
}
}
use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadBagWithDotSlash.
@Test
public void testReadBagWithDotSlash() throws Exception {
Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_96/bag-with-leading-dot-slash-in-manifest").toURI());
Bag bag = sut.read(rootDir);
assertNotNull(bag);
for (Manifest payloadManifest : bag.getPayLoadManifests()) {
for (Path file : payloadManifest.getFileToChecksumMap().keySet()) {
assertTrue(file + " should exist but it doesn't!", Files.exists(file));
}
}
}
use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadBagWithSpaceAsManifestDelimiter.
@Test
public void testReadBagWithSpaceAsManifestDelimiter() throws Exception {
Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_96/bag-with-space").toURI());
Bag bag = sut.read(rootDir);
assertNotNull(bag);
for (Manifest payloadManifest : bag.getPayLoadManifests()) {
for (Path file : payloadManifest.getFileToChecksumMap().keySet()) {
assertTrue(file + " should exist but it doesn't!", Files.exists(file));
}
}
}
use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class BagVerifierTest method testVerificationExceptionIsThrownForNoSuchAlgorithmException.
@Test(expected = VerificationException.class)
public void testVerificationExceptionIsThrownForNoSuchAlgorithmException() throws Exception {
Path unreadableFile = Paths.get(folder.newFile().toURI());
Manifest manifest = new Manifest(new SupportedAlgorithm() {
@Override
public String getMessageDigestName() {
return "FOO";
}
@Override
public String getBagitName() {
return "foo";
}
});
manifest.getFileToChecksumMap().put(unreadableFile, "foo");
sut.checkHashes(manifest);
}
use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class PayloadVerifier method getAllFilesListedInManifests.
/*
* get all the files listed in all the manifests
*/
private Set<Path> getAllFilesListedInManifests(final Bag bag) throws IOException, MaliciousPathException, UnsupportedAlgorithmException, InvalidBagitFileFormatException {
logger.debug(messages.getString("all_files_in_manifests"));
final Set<Path> filesListedInManifests = new HashSet<>();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(PathUtils.getBagitDir(bag.getVersion(), bag.getRootDir()))) {
for (final Path path : directoryStream) {
final String filename = PathUtils.getFilename(path);
if (filename.startsWith("tagmanifest-") || filename.startsWith("manifest-")) {
logger.debug(messages.getString("get_listing_in_manifest"), path);
final Manifest manifest = ManifestReader.readManifest(nameMapping, path, bag.getRootDir(), bag.getFileEncoding());
filesListedInManifests.addAll(manifest.getFileToChecksumMap().keySet());
}
}
}
return filesListedInManifests;
}
Aggregations