Search in sources :

Example 21 with Bag

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

the class PathUtilsTest method testGetBagitDirUsingBag.

@Test
public void testGetBagitDirUsingBag() {
    Bag bag = new Bag(new Version(2, 0));
    bag.setRootDir(Paths.get("foo"));
    Path expectedPath = bag.getRootDir().resolve(".bagit");
    Path actualPath = PathUtils.getBagitDir(bag);
    assertEquals(expectedPath, actualPath);
    bag = new Bag(new Version(0, 97));
    bag.setRootDir(Paths.get("foo"));
    expectedPath = bag.getRootDir();
    actualPath = PathUtils.getBagitDir(bag);
    assertEquals(expectedPath, actualPath);
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) Bag(gov.loc.repository.bagit.domain.Bag) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 22 with Bag

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

the class BagLinterTest method testCheckAgainstProfile.

@Test
public void testCheckAgainstProfile() throws Exception {
    Path profileJson = new File("src/test/resources/bagitProfiles/exampleProfile.json").toPath();
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/profileConformantBag").toPath();
    BagReader reader = new BagReader();
    Bag bag = reader.read(bagRootPath);
    try (InputStream inputStream = Files.newInputStream(profileJson, StandardOpenOption.READ)) {
        BagLinter.checkAgainstProfile(inputStream, bag);
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) BagReader(gov.loc.repository.bagit.reader.BagReader) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 23 with Bag

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

the class BagProfileCheckerTest method testRequiredTagManifestNotPresentException.

@Test(expected = RequiredManifestNotPresentException.class)
public void testRequiredTagManifestNotPresentException() throws Exception {
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/missingRequiredTagManifestBag").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 24 with Bag

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

the class BagProfileCheckerTest method testBagitVersionIsNotAcceptableException.

@Test(expected = BagitVersionIsNotAcceptableException.class)
public void testBagitVersionIsNotAcceptableException() throws Exception {
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/wrongBagitVersionBag").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 25 with Bag

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

the class BagProfileCheckerTest method testMetatdataValueIsNotAcceptableException.

@Test(expected = MetatdataValueIsNotAcceptableException.class)
public void testMetatdataValueIsNotAcceptableException() throws Exception {
    Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/wrongValueForContactNameBag").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)

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