Search in sources :

Example 16 with Version

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);
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 17 with Version

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);
    }
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version)

Example 18 with Version

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));
}
Also used : Version(gov.loc.repository.bagit.domain.Version) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with 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);
}
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)

Example 20 with Version

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));
        }
    }
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) Bag(gov.loc.repository.bagit.domain.Bag) Manifest(gov.loc.repository.bagit.domain.Manifest) File(java.io.File) Test(org.junit.Test)

Aggregations

Version (gov.loc.repository.bagit.domain.Version)24 Path (java.nio.file.Path)19 Test (org.junit.Test)17 Bag (gov.loc.repository.bagit.domain.Bag)11 PrivateConstructorTest (gov.loc.repository.bagit.PrivateConstructorTest)7 File (java.io.File)6 Manifest (gov.loc.repository.bagit.domain.Manifest)4 Charset (java.nio.charset.Charset)4 HashSet (java.util.HashSet)3 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2 Metadata (gov.loc.repository.bagit.domain.Metadata)1 InvalidBagitFileFormatException (gov.loc.repository.bagit.exceptions.InvalidBagitFileFormatException)1 MissingBagitFileException (gov.loc.repository.bagit.exceptions.MissingBagitFileException)1