use of gov.loc.repository.bagit.domain.Version in project bagit-java by LibraryOfCongress.
the class PathUtilsTest method testGetBagitDirUsingVersion.
@Test
public void testGetBagitDirUsingVersion() throws IOException {
Path input = Paths.get("foo");
Path expectedPath = input.resolve(".bagit");
Path actualPath = PathUtils.getBagitDir(new Version(2, 0), input);
assertEquals(expectedPath, actualPath);
expectedPath = input;
actualPath = PathUtils.getBagitDir(new Version(0, 97), input);
assertEquals(expectedPath, actualPath);
}
use of gov.loc.repository.bagit.domain.Version in project bagit-java by LibraryOfCongress.
the class PayloadVerifier method verifyPayload.
/**
* Verify that all the files in the payload directory are listed in the manifest and
* all files listed in the manifests exist.
*
* @param bag the bag to check to check
* @param ignoreHiddenFiles to ignore hidden files unless they are specifically listed in a manifest
* @throws IOException if there is a problem reading a file
* @throws MaliciousPathException the path in the manifest was specifically crafted to cause harm
* @throws UnsupportedAlgorithmException if the algorithm used for the manifest is unsupported
* @throws InvalidBagitFileFormatException if any of the manifests don't conform to the bagit specification
* @throws FileNotInPayloadDirectoryException if a file is listed in a manifest but doesn't exist in the payload directory
* @throws InterruptedException if a thread is interrupted while doing work
*/
public void verifyPayload(final Bag bag, final boolean ignoreHiddenFiles) throws IOException, MaliciousPathException, UnsupportedAlgorithmException, InvalidBagitFileFormatException, FileNotInPayloadDirectoryException, InterruptedException {
final Set<Path> allFilesListedInManifests = getAllFilesListedInManifests(bag);
checkAllFilesListedInManifestExist(allFilesListedInManifests);
if (bag.getVersion().isOlder(new Version(1, 0))) {
checkAllFilesInPayloadDirAreListedInAtLeastOneAManifest(allFilesListedInManifests, PathUtils.getDataDir(bag), ignoreHiddenFiles);
} else {
CheckAllFilesInPayloadDirAreListedInAllManifests(bag.getPayLoadManifests(), PathUtils.getDataDir(bag), ignoreHiddenFiles);
}
}
use of gov.loc.repository.bagit.domain.Version in project bagit-java by LibraryOfCongress.
the class VersionCheckerTest method testCheckOldVersion.
@Test
public void testCheckOldVersion() {
Set<BagitWarning> warnings = new HashSet<>();
VersionChecker.checkVersion(new Version(0, 95), warnings, Collections.emptyList());
assertTrue(warnings.contains(BagitWarning.OLD_BAGIT_VERSION));
}
use of gov.loc.repository.bagit.domain.Version 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.Version 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