Search in sources :

Example 1 with Bag

use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.

the class BagitSuiteComplanceTest method testValidBags.

@Test
public void testValidBags() throws Exception {
    Bag bag;
    for (final Path bagDir : visitor.getValidTestCases()) {
        bag = reader.read(bagDir);
        verifier.isValid(bag, true);
    }
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) Test(org.junit.Test)

Example 2 with Bag

use of gov.loc.repository.bagit.domain.Bag 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);
}
Also used : Path(java.nio.file.Path) MissingPayloadManifestException(gov.loc.repository.bagit.exceptions.MissingPayloadManifestException) MaliciousPathException(gov.loc.repository.bagit.exceptions.MaliciousPathException) CorruptChecksumException(gov.loc.repository.bagit.exceptions.CorruptChecksumException) Bag(gov.loc.repository.bagit.domain.Bag) IOException(java.io.IOException) FileNotInPayloadDirectoryException(gov.loc.repository.bagit.exceptions.FileNotInPayloadDirectoryException) CorruptChecksumException(gov.loc.repository.bagit.exceptions.CorruptChecksumException) UnparsableVersionException(gov.loc.repository.bagit.exceptions.UnparsableVersionException) MaliciousPathException(gov.loc.repository.bagit.exceptions.MaliciousPathException) MissingBagitFileException(gov.loc.repository.bagit.exceptions.MissingBagitFileException) UnsupportedAlgorithmException(gov.loc.repository.bagit.exceptions.UnsupportedAlgorithmException) IOException(java.io.IOException) MissingPayloadManifestException(gov.loc.repository.bagit.exceptions.MissingPayloadManifestException) MissingPayloadDirectoryException(gov.loc.repository.bagit.exceptions.MissingPayloadDirectoryException) VerificationException(gov.loc.repository.bagit.exceptions.VerificationException) FileNotInPayloadDirectoryException(gov.loc.repository.bagit.exceptions.FileNotInPayloadDirectoryException) InvalidBagitFileFormatException(gov.loc.repository.bagit.exceptions.InvalidBagitFileFormatException) MissingBagitFileException(gov.loc.repository.bagit.exceptions.MissingBagitFileException) AtomicLong(java.util.concurrent.atomic.AtomicLong) MissingPayloadDirectoryException(gov.loc.repository.bagit.exceptions.MissingPayloadDirectoryException) UnparsableVersionException(gov.loc.repository.bagit.exceptions.UnparsableVersionException) UnsupportedAlgorithmException(gov.loc.repository.bagit.exceptions.UnsupportedAlgorithmException) InvalidBagitFileFormatException(gov.loc.repository.bagit.exceptions.InvalidBagitFileFormatException) VerificationException(gov.loc.repository.bagit.exceptions.VerificationException) BeforeClass(org.junit.BeforeClass) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 3 with Bag

use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.

the class ReaderWriterVerifierIntegrationTest method testReaderWriterVersion95.

@Test
public void testReaderWriterVersion95() throws Exception {
    BagReader reader = new BagReader();
    Path rootDir = Paths.get(this.getClass().getClassLoader().getResource("bags/v0_95/bag").toURI());
    Bag bag = reader.read(rootDir);
    Path outputDir = Paths.get(folder.newFolder().toURI());
    BagWriter.write(bag, outputDir);
    testBagsEqual(rootDir, outputDir);
    try (BagVerifier verifier = new BagVerifier()) {
        verifier.isValid(reader.read(outputDir), true);
    }
}
Also used : Path(java.nio.file.Path) BagVerifier(gov.loc.repository.bagit.verify.BagVerifier) BagReader(gov.loc.repository.bagit.reader.BagReader) Bag(gov.loc.repository.bagit.domain.Bag) Test(org.junit.Test)

Example 4 with Bag

use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.

the class BagReaderTest method testReadBagWithEncodedNames.

@Test
public void testReadBagWithEncodedNames() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_96/bag-with-encoded-names").toURI());
    Bag bag = sut.read(rootDir);
    assertNotNull(bag);
    for (Manifest payloadManifest : bag.getPayLoadManifests()) {
        for (Path file : payloadManifest.getFileToChecksumMap().keySet()) {
            assertTrue(file + " should exist but it doesn't!", Files.exists(file));
        }
    }
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) Manifest(gov.loc.repository.bagit.domain.Manifest) Test(org.junit.Test)

Example 5 with Bag

use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.

the class BagReaderTest method testReadVersion0_93.

@Test
public void testReadVersion0_93() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_93/bag").toURI());
    Bag bag = sut.read(rootDir);
    assertEquals(new Version(0, 93), bag.getVersion());
    for (SimpleImmutableEntry<String, String> keyValue : bag.getMetadata().getAll()) {
        if ("Payload-Oxum".equals(keyValue.getKey())) {
            assertEquals("25.5", keyValue.getValue());
        }
    }
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) Bag(gov.loc.repository.bagit.domain.Bag) Test(org.junit.Test)

Aggregations

Bag (gov.loc.repository.bagit.domain.Bag)71 Test (org.junit.Test)67 Path (java.nio.file.Path)55 File (java.io.File)38 PrivateConstructorTest (gov.loc.repository.bagit.PrivateConstructorTest)28 Version (gov.loc.repository.bagit.domain.Version)11 InputStream (java.io.InputStream)10 Manifest (gov.loc.repository.bagit.domain.Manifest)9 BagReader (gov.loc.repository.bagit.reader.BagReader)9 BagVerifier (gov.loc.repository.bagit.verify.BagVerifier)6 Metadata (gov.loc.repository.bagit.domain.Metadata)2 CorruptChecksumException (gov.loc.repository.bagit.exceptions.CorruptChecksumException)2 FileNotInPayloadDirectoryException (gov.loc.repository.bagit.exceptions.FileNotInPayloadDirectoryException)2 InvalidBagitFileFormatException (gov.loc.repository.bagit.exceptions.InvalidBagitFileFormatException)2 MaliciousPathException (gov.loc.repository.bagit.exceptions.MaliciousPathException)2 MissingBagitFileException (gov.loc.repository.bagit.exceptions.MissingBagitFileException)2 MissingPayloadDirectoryException (gov.loc.repository.bagit.exceptions.MissingPayloadDirectoryException)2 MissingPayloadManifestException (gov.loc.repository.bagit.exceptions.MissingPayloadManifestException)2 UnparsableVersionException (gov.loc.repository.bagit.exceptions.UnparsableVersionException)2 UnsupportedAlgorithmException (gov.loc.repository.bagit.exceptions.UnsupportedAlgorithmException)2