Search in sources :

Example 6 with Bag

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

the class BagReaderTest method testReadVersion0_97Bag.

@Test
public void testReadVersion0_97Bag() throws Exception {
    Path rootBag = Paths.get(new File("src/test/resources/bags/v0_97/bag").toURI());
    Path[] payloadFiles = new Path[] { rootBag.resolve("data/dir1/test3.txt"), rootBag.resolve("data/dir2/dir3/test5.txt"), rootBag.resolve("data/dir2/test4.txt"), rootBag.resolve("data/test1.txt"), rootBag.resolve("data/test2.txt") };
    Bag returnedBag = sut.read(rootBag);
    assertNotNull(returnedBag);
    assertEquals(new Version(0, 97), returnedBag.getVersion());
    Manifest payloadManifest = (Manifest) returnedBag.getPayLoadManifests().toArray()[0];
    for (Path payloadFile : payloadFiles) {
        assertTrue(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) File(java.io.File) Test(org.junit.Test)

Example 7 with Bag

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

the class BagReaderTest method testReadBagWithEscapableCharacter.

@Test
public void testReadBagWithEscapableCharacter() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_96/bag-with-escapable-characters").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 8 with Bag

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

the class BagReaderTest method testReadVersion0_94.

@Test
public void testReadVersion0_94() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_94/bag").toURI());
    Bag bag = sut.read(rootDir);
    assertEquals(new Version(0, 94), bag.getVersion());
    for (SimpleImmutableEntry<String, String> keyValue : bag.getMetadata().getAll()) {
        if ("Payload-Oxum".equals(keyValue.getKey())) {
            assertEquals("25.5", 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 9 with Bag

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

the class BagReaderTest method testReadUTF_16_Encoding.

@Test
public void testReadUTF_16_Encoding() throws Exception {
    Metadata expectedMetaData = new Metadata();
    expectedMetaData.add("Bag-Software-Agent", "bagit.py <http://github.com/libraryofcongress/bagit-python>");
    expectedMetaData.add("Bagging-Date", "2016-02-26");
    expectedMetaData.add("Contact-Email", "cadams@loc.gov");
    expectedMetaData.add("Contact-Name", "Chris Adams");
    expectedMetaData.add("Payload-Oxum", "58.2");
    Path bagPath = Paths.get(new File("src/test/resources/UTF-16-encoded-tag-files").toURI());
    List<FetchItem> expectedFetchItems = new ArrayList<>();
    expectedFetchItems.add(new FetchItem(new URL("http://localhost/foo/data/dir1/test3.txt"), -1l, bagPath.resolve("data/dir1/test3.txt")));
    Bag bag = sut.read(bagPath);
    assertNotNull(bag);
    assertEquals(StandardCharsets.UTF_16, bag.getFileEncoding());
    assertEquals(expectedMetaData, bag.getMetadata());
    assertEquals(expectedFetchItems, bag.getItemsToFetch());
}
Also used : Path(java.nio.file.Path) FetchItem(gov.loc.repository.bagit.domain.FetchItem) Metadata(gov.loc.repository.bagit.domain.Metadata) ArrayList(java.util.ArrayList) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 10 with Bag

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

the class ManifestReaderTest method testReadAllManifests.

@Test
public void testReadAllManifests() throws Exception {
    Path rootBag = Paths.get(getClass().getClassLoader().getResource("bags/v0_97/bag").toURI());
    Bag bag = new Bag();
    bag.setRootDir(rootBag);
    ManifestReader.readAllManifests(new StandardBagitAlgorithmNameToSupportedAlgorithmMapping(), rootBag, bag);
    assertEquals(1, bag.getPayLoadManifests().size());
    assertEquals(1, bag.getTagManifests().size());
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) StandardBagitAlgorithmNameToSupportedAlgorithmMapping(gov.loc.repository.bagit.hash.StandardBagitAlgorithmNameToSupportedAlgorithmMapping) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) 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