use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.
the class BagProfileCheckerTest method testFetchFileNotAllowedException.
@Test(expected = FetchFileNotAllowedException.class)
public void testFetchFileNotAllowedException() throws Exception {
Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/failFetchBag").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 testRequiredPayloadManifestNotPresentException.
@Test(expected = RequiredManifestNotPresentException.class)
public void testRequiredPayloadManifestNotPresentException() throws Exception {
Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/missingRequiredPayloadManifestBag").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 testMetadataValueIsNotRepeatableException.
@Test(expected = MetatdataValueIsNotRepeatableException.class)
public void testMetadataValueIsNotRepeatableException() throws Exception {
Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/repeatedMetadataBag").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 BagCreatorTest method testCreateDotBagit.
@Test
public void testCreateDotBagit() throws IOException, NoSuchAlgorithmException {
createTestStructure();
Path rootFolderPath = Paths.get(folder.getRoot().toURI());
Path dotbagitDir = rootFolderPath.resolve(".bagit");
Path expectedManifestFile = dotbagitDir.resolve("manifest-md5.txt");
Path expectedTagManifestFile = dotbagitDir.resolve("tagmanifest-md5.txt");
Path expectedBagitFile = dotbagitDir.resolve("bagit.txt");
Bag bag = BagCreator.createDotBagit(rootFolderPath, Arrays.asList(StandardSupportedAlgorithms.MD5), false);
assertEquals(new Version(2, 0), bag.getVersion());
assertTrue(Files.exists(expectedBagitFile));
assertTrue(Files.size(expectedBagitFile) > 0);
assertTrue(Files.exists(expectedManifestFile));
assertTrue(Files.size(expectedManifestFile) > 0);
assertTrue(Files.exists(expectedTagManifestFile));
assertTrue(Files.size(expectedTagManifestFile) > 0);
}
use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.
the class BagCreatorTest method testBagInPlace.
@Test
public void testBagInPlace() throws IOException, NoSuchAlgorithmException {
TestStructure structure = createTestStructure();
Bag bag = BagCreator.bagInPlace(Paths.get(folder.getRoot().toURI()), Arrays.asList(StandardSupportedAlgorithms.MD5), false);
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());
// make sure the hidden folder was not included in the data directory
File hiddenFolder = new File(bag.getRootDir().resolve("data").toFile(), ".hiddenFolder");
assertFalse(hiddenFolder.exists());
for (Manifest manifest : bag.getPayLoadManifests()) {
for (Path expectedPayloadFile : manifest.getFileToChecksumMap().keySet()) {
assertTrue(structure.regularPayloadFiles.contains(expectedPayloadFile));
}
}
}
Aggregations