use of gov.loc.repository.bagit.exceptions.VerificationException 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.VerificationException in project bagit-java by LibraryOfCongress.
the class BagVerifier method checkHashes.
/*
* Check the supplied checksum hashes against the generated checksum hashes
*/
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
void checkHashes(final Manifest manifest) throws CorruptChecksumException, InterruptedException, VerificationException {
final CountDownLatch latch = new CountDownLatch(manifest.getFileToChecksumMap().size());
// TODO maybe return all of these at some point...
final Collection<Exception> exceptions = Collections.synchronizedCollection(new ArrayList<>());
for (final Entry<Path, String> entry : manifest.getFileToChecksumMap().entrySet()) {
executor.execute(new CheckManifestHashesTask(entry, manifest.getAlgorithm().getMessageDigestName(), latch, exceptions));
}
latch.await();
if (!exceptions.isEmpty()) {
final Exception e = exceptions.iterator().next();
if (e instanceof CorruptChecksumException) {
logger.debug(messages.getString("checksums_not_matching_error"), exceptions.size());
throw (CorruptChecksumException) e;
}
throw new VerificationException(e);
}
}
use of gov.loc.repository.bagit.exceptions.VerificationException 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