Search in sources :

Example 31 with Bag

use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.

the class BagReaderTest method testReadVersion0_95.

@Test
public void testReadVersion0_95() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_95/bag").toURI());
    Bag bag = sut.read(rootDir);
    assertEquals(new Version(0, 95), bag.getVersion());
    for (SimpleImmutableEntry<String, String> keyValue : bag.getMetadata().getAll()) {
        if ("Package-Size".equals(keyValue.getKey())) {
            assertEquals("260 GB", keyValue.getValue());
        }
    }
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) Bag(gov.loc.repository.bagit.domain.Bag) Test(org.junit.Test)

Example 32 with Bag

use of gov.loc.repository.bagit.domain.Bag 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 33 with Bag

use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.

the class BagReaderTest method testReadBagWithinABag.

@Test
public void testReadBagWithinABag() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_96/bag-in-a-bag").toURI());
    Bag bag = sut.read(rootDir);
    assertNotNull(bag);
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) Test(org.junit.Test)

Example 34 with Bag

use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.

the class BagVerifierTest method testErrorWhenUnspportedAlgorithmException.

@Test(expected = UnsupportedAlgorithmException.class)
public void testErrorWhenUnspportedAlgorithmException() throws Exception {
    Path sha3BagDir = Paths.get(getClass().getClassLoader().getResource("sha3Bag").toURI());
    BagReader extendedReader = new BagReader();
    Bag bag = extendedReader.read(sha3BagDir);
    sut.isValid(bag, true);
}
Also used : Path(java.nio.file.Path) BagReader(gov.loc.repository.bagit.reader.BagReader) Bag(gov.loc.repository.bagit.domain.Bag) Test(org.junit.Test)

Example 35 with Bag

use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.

the class BagVerifierTest method testManifestsWithLeadingDotSlash.

/*
   * Technically valid but highly discouraged
   */
@Test
public void testManifestsWithLeadingDotSlash() throws Exception {
    Path bagPath = Paths.get(new File("src/test/resources/bag-with-leading-dot-slash-in-manifest").toURI());
    Bag bag = reader.read(bagPath);
    sut.isValid(bag, true);
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) Test(org.junit.Test)

Aggregations

Bag (gov.loc.repository.bagit.domain.Bag)71 Test (org.junit.Test)67 Path (java.nio.file.Path)55 File (java.io.File)38 PrivateConstructorTest (gov.loc.repository.bagit.PrivateConstructorTest)28 Version (gov.loc.repository.bagit.domain.Version)11 InputStream (java.io.InputStream)10 Manifest (gov.loc.repository.bagit.domain.Manifest)9 BagReader (gov.loc.repository.bagit.reader.BagReader)9 BagVerifier (gov.loc.repository.bagit.verify.BagVerifier)6 Metadata (gov.loc.repository.bagit.domain.Metadata)2 CorruptChecksumException (gov.loc.repository.bagit.exceptions.CorruptChecksumException)2 FileNotInPayloadDirectoryException (gov.loc.repository.bagit.exceptions.FileNotInPayloadDirectoryException)2 InvalidBagitFileFormatException (gov.loc.repository.bagit.exceptions.InvalidBagitFileFormatException)2 MaliciousPathException (gov.loc.repository.bagit.exceptions.MaliciousPathException)2 MissingBagitFileException (gov.loc.repository.bagit.exceptions.MissingBagitFileException)2 MissingPayloadDirectoryException (gov.loc.repository.bagit.exceptions.MissingPayloadDirectoryException)2 MissingPayloadManifestException (gov.loc.repository.bagit.exceptions.MissingPayloadManifestException)2 UnparsableVersionException (gov.loc.repository.bagit.exceptions.UnparsableVersionException)2 UnsupportedAlgorithmException (gov.loc.repository.bagit.exceptions.UnsupportedAlgorithmException)2