use of gov.loc.repository.bagit.exceptions.MissingBagitFileException in project bagit-java by LibraryOfCongress.
the class BagitSuiteComplanceTest method testInvalidOperatingSystemSpecificBags.
@Test
public void testInvalidOperatingSystemSpecificBags() {
int errorCount = 0;
Bag bag;
List<Path> osSpecificInvalidPaths = visitor.getLinuxOnlyTestCases();
ConcurrentMap<Class<? extends Exception>, AtomicLong> map = new ConcurrentHashMap<>();
if (TestUtils.isExecutingOnWindows()) {
osSpecificInvalidPaths = visitor.getWindowsOnlyTestCases();
}
for (Path invalidBagDir : osSpecificInvalidPaths) {
try {
bag = reader.read(invalidBagDir);
verifier.isValid(bag, true);
} catch (InvalidBagitFileFormatException | IOException | UnparsableVersionException | MissingPayloadManifestException | MissingBagitFileException | MissingPayloadDirectoryException | FileNotInPayloadDirectoryException | InterruptedException | MaliciousPathException | CorruptChecksumException | VerificationException | UnsupportedAlgorithmException e) {
logger.info("Found invalid os specific bag with message: {}", e.getMessage());
map.putIfAbsent(e.getClass(), new AtomicLong(0));
map.get(e.getClass()).incrementAndGet();
errorCount++;
}
}
assertEquals("every test case should throw an error", osSpecificInvalidPaths.size(), errorCount);
logger.debug("Count of all errors found in os specific invalid cases: {}", map);
}
use of gov.loc.repository.bagit.exceptions.MissingBagitFileException in project bagit-java by LibraryOfCongress.
the class MandatoryVerifier method checkBagitFileExists.
/**
* make sure the bagit.txt file exists
*
* @param rootDir the root directory of the bag
* @param version the version of the bag
* @throws MissingBagitFileException if the bag does not contain the bagit.txt file as required by the bagit specification
*/
public static void checkBagitFileExists(final Path rootDir, final Version version) throws MissingBagitFileException {
logger.info("Checking if bagit.txt file exists");
Path bagitFile = rootDir.resolve("bagit.txt");
// @Incubating
if (version.isSameOrNewer(new Version(2, 0))) {
// is it a .bagit version?
bagitFile = rootDir.resolve(DOT_BAGIT_DIR_NAME + File.separator + "bagit.txt");
}
if (!Files.exists(bagitFile)) {
final String formattedMessage = messages.getString("file_should_exist_error");
throw new MissingBagitFileException(MessageFormatter.format(formattedMessage, bagitFile).getMessage());
}
}
use of gov.loc.repository.bagit.exceptions.MissingBagitFileException in project bagit-java by LibraryOfCongress.
the class BagitSuiteComplanceTest method testInvalidBags.
@Test
public void testInvalidBags() {
int errorCount = 0;
Bag bag;
ConcurrentMap<Class<? extends Exception>, AtomicLong> map = new ConcurrentHashMap<>();
for (Path invalidBagDir : visitor.getInvalidTestCases()) {
try {
bag = reader.read(invalidBagDir);
verifier.isValid(bag, true);
System.err.println(bag.getRootDir() + " should have failed but didn't!");
} catch (InvalidBagitFileFormatException | IOException | UnparsableVersionException | MissingPayloadManifestException | MissingBagitFileException | MissingPayloadDirectoryException | FileNotInPayloadDirectoryException | InterruptedException | MaliciousPathException | CorruptChecksumException | VerificationException | UnsupportedAlgorithmException e) {
logger.info("Found invalid os specific bag with message: {}", e.getMessage());
map.putIfAbsent(e.getClass(), new AtomicLong(0));
map.get(e.getClass()).incrementAndGet();
errorCount++;
}
}
assertEquals("every test case should throw an error", visitor.getInvalidTestCases().size(), errorCount);
logger.debug("Count of all errors found in generic invalid cases: {}", map);
}
Aggregations