Search in sources :

Example 51 with Bag

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

the class BagWriterTest method testGetCorrectRelativeOuputPath.

@Test
public void testGetCorrectRelativeOuputPath() throws Exception {
    Path root = Paths.get(folder.newFolder().toURI());
    Bag bag = BagCreator.bagInPlace(root, Arrays.asList(StandardSupportedAlgorithms.MD5), false);
    Path testFile = root.resolve("data").resolve("fooFile.txt");
    Files.createFile(testFile);
    Manifest manifest = (Manifest) bag.getPayLoadManifests().toArray()[0];
    manifest.getFileToChecksumMap().put(testFile, "CHECKSUM");
    bag.getPayLoadManifests().add(manifest);
    Path newRoot = Paths.get(folder.newFolder().toURI());
    BagWriter.write(bag, newRoot);
    assertTrue(Files.exists(newRoot.resolve("data").resolve("fooFile.txt")));
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) Manifest(gov.loc.repository.bagit.domain.Manifest) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 52 with Bag

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

the class BagWriterTest method testWriteVersion97.

@Test
public void testWriteVersion97() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_97/bag").toURI());
    Bag bag = reader.read(rootDir);
    File bagitDir = folder.newFolder();
    Path bagitDirPath = Paths.get(bagitDir.toURI());
    List<Path> expectedPaths = Arrays.asList(bagitDirPath.resolve("tagmanifest-md5.txt"), bagitDirPath.resolve("manifest-md5.txt"), bagitDirPath.resolve("bagit.txt"), bagitDirPath.resolve("bag-info.txt"), bagitDirPath.resolve("data"), bagitDirPath.resolve("data").resolve("test1.txt"), bagitDirPath.resolve("data").resolve("test2.txt"), bagitDirPath.resolve("data").resolve("dir1"), bagitDirPath.resolve("data").resolve("dir2"), bagitDirPath.resolve("data").resolve("dir1").resolve("test3.txt"), bagitDirPath.resolve("data").resolve("dir2").resolve("test4.txt"), bagitDirPath.resolve("data").resolve("dir2").resolve("dir3"), bagitDirPath.resolve("data").resolve("dir2").resolve("dir3").resolve("test5.txt"), bagitDirPath.resolve("addl_tags"), bagitDirPath.resolve("addl_tags").resolve("tag1.txt"));
    BagWriter.write(bag, bagitDirPath);
    for (Path expectedPath : expectedPaths) {
        assertTrue("Expected " + expectedPath + " to exist!", Files.exists(expectedPath));
    }
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 53 with Bag

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

the class BagWriterTest method testWriteEmptyBagStillCreatesDataDir.

@Test
public void testWriteEmptyBagStillCreatesDataDir() throws Exception {
    Bag bag = new Bag();
    bag.setRootDir(Paths.get(folder.newFolder().toURI()));
    Path dataDir = bag.getRootDir().resolve("data");
    BagWriter.write(bag, bag.getRootDir());
    assertTrue(Files.exists(dataDir));
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 54 with Bag

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

the class BagProfileCheckerTest method testRequiredMetadataFieldNotPresentException.

@Test(expected = RequiredMetadataFieldNotPresentException.class)
public void testRequiredMetadataFieldNotPresentException() throws Exception {
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/emailFieldMissingBag").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 55 with Bag

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

the class BagProfileCheckerTest method testRequiredTagFileNotPresentException.

@Test(expected = RequiredTagFileNotPresentException.class)
public void testRequiredTagFileNotPresentException() throws Exception {
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/missingRequiredTagFileBag").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)

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