Search in sources :

Example 11 with Manifest

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));
    }
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) Bag(gov.loc.repository.bagit.domain.Bag) Manifest(gov.loc.repository.bagit.domain.Manifest) Test(org.junit.Test)

Example 12 with Manifest

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));
        }
    }
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) Manifest(gov.loc.repository.bagit.domain.Manifest) Test(org.junit.Test)

Example 13 with Manifest

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));
        }
    }
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) Manifest(gov.loc.repository.bagit.domain.Manifest) Test(org.junit.Test)

Example 14 with Manifest

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);
}
Also used : Path(java.nio.file.Path) Manifest(gov.loc.repository.bagit.domain.Manifest) SupportedAlgorithm(gov.loc.repository.bagit.hash.SupportedAlgorithm) Test(org.junit.Test)

Example 15 with 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;
}
Also used : Path(java.nio.file.Path) Manifest(gov.loc.repository.bagit.domain.Manifest) HashSet(java.util.HashSet)

Aggregations

Manifest (gov.loc.repository.bagit.domain.Manifest)27 Path (java.nio.file.Path)21 Test (org.junit.Test)16 Bag (gov.loc.repository.bagit.domain.Bag)9 File (java.io.File)8 HashSet (java.util.HashSet)7 PrivateConstructorTest (gov.loc.repository.bagit.PrivateConstructorTest)5 Version (gov.loc.repository.bagit.domain.Version)4 MessageDigest (java.security.MessageDigest)4 SupportedAlgorithm (gov.loc.repository.bagit.hash.SupportedAlgorithm)2 HashMap (java.util.HashMap)2 FetchItem (gov.loc.repository.bagit.domain.FetchItem)1 RequiredManifestNotPresentException (gov.loc.repository.bagit.exceptions.conformance.RequiredManifestNotPresentException)1 StandardSupportedAlgorithms (gov.loc.repository.bagit.hash.StandardSupportedAlgorithms)1