Search in sources :

Example 56 with Bag

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

the class BagProfileCheckerTest method testFetchFileNotAllowedException.

@Test(expected = FetchFileNotAllowedException.class)
public void testFetchFileNotAllowedException() throws Exception {
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/failFetchBag").toPath();
    Bag bag = reader.read(bagRootPath);
    try (InputStream inputStream = Files.newInputStream(profileJson, StandardOpenOption.READ)) {
        BagProfileChecker.bagConformsToProfile(inputStream, bag);
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 57 with Bag

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

the class BagProfileCheckerTest method testRequiredPayloadManifestNotPresentException.

@Test(expected = RequiredManifestNotPresentException.class)
public void testRequiredPayloadManifestNotPresentException() throws Exception {
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/missingRequiredPayloadManifestBag").toPath();
    Bag bag = reader.read(bagRootPath);
    try (InputStream inputStream = Files.newInputStream(profileJson, StandardOpenOption.READ)) {
        BagProfileChecker.bagConformsToProfile(inputStream, bag);
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 58 with Bag

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

the class BagProfileCheckerTest method testMetadataValueIsNotRepeatableException.

@Test(expected = MetatdataValueIsNotRepeatableException.class)
public void testMetadataValueIsNotRepeatableException() throws Exception {
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/repeatedMetadataBag").toPath();
    Bag bag = reader.read(bagRootPath);
    try (InputStream inputStream = Files.newInputStream(profileJson, StandardOpenOption.READ)) {
        BagProfileChecker.bagConformsToProfile(inputStream, bag);
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 59 with Bag

use of gov.loc.repository.bagit.domain.Bag 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 60 with Bag

use of gov.loc.repository.bagit.domain.Bag 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

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