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")));
}
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));
}
}
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));
}
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);
}
}
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);
}
}
Aggregations