Search in sources :

Example 26 with Bag

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

the class BagProfileCheckerTest method testBagConformsToProfile.

@Test
public void testBagConformsToProfile() throws Exception {
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/profileConformantBag").toPath();
    Bag bag = reader.read(bagRootPath);
    try (InputStream inputStream = Files.newInputStream(profileJson, StandardOpenOption.READ)) {
        BagProfileChecker.bagConformsToProfile(inputStream, bag);
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 27 with Bag

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

the class BagCreatorTest method testBagInPlaceIncludingHidden.

@Test
public void testBagInPlaceIncludingHidden() throws IOException, NoSuchAlgorithmException {
    TestStructure structure = createTestStructure();
    Bag bag = BagCreator.bagInPlace(Paths.get(folder.getRoot().toURI()), Arrays.asList(StandardSupportedAlgorithms.MD5), true);
    assertEquals(new Version(0, 97), bag.getVersion());
    File expectedManifest = new File(folder.getRoot(), "manifest-md5.txt");
    assertTrue(expectedManifest.exists());
    File expectedTagManifest = new File(folder.getRoot(), "tagmanifest-md5.txt");
    assertTrue(expectedTagManifest.exists());
    File bagitFile = new File(folder.getRoot(), "bagit.txt");
    assertTrue(bagitFile.exists());
    for (Manifest manifest : bag.getPayLoadManifests()) {
        for (Path expectedPayloadFile : manifest.getFileToChecksumMap().keySet()) {
            assertTrue(expectedPayloadFile + " doesn't exist but it should!", structure.regularPayloadFiles.contains(expectedPayloadFile) || structure.hiddenPayloadFiles.contains(expectedPayloadFile));
        }
    }
}
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 28 with Bag

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

the class BagReaderTest method testReadISO_8859_1Encoding.

@Test
public void testReadISO_8859_1Encoding() 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/ISO-8859-1-encodedBag").toURI());
    Bag bag = sut.read(bagPath);
    assertNotNull(bag);
    assertEquals(StandardCharsets.ISO_8859_1, bag.getFileEncoding());
    assertEquals(expectedMetaData, bag.getMetadata());
}
Also used : Path(java.nio.file.Path) Metadata(gov.loc.repository.bagit.domain.Metadata) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) Test(org.junit.Test)

Example 29 with Bag

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

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

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