Search in sources :

Example 16 with Bag

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

the class QuickVerifierTest method testCanQuickVerify.

@Test
public void testCanQuickVerify() throws Exception {
    Bag bag = reader.read(rootDir);
    boolean canQuickVerify = QuickVerifier.canQuickVerify(bag);
    assertFalse("Since " + bag.getRootDir() + " DOES NOT contain the metadata Payload-Oxum then it should return false!", canQuickVerify);
    Path passingRootDir = Paths.get(new File("src/test/resources/bags/v0_94/bag").toURI());
    bag = reader.read(passingRootDir);
    canQuickVerify = QuickVerifier.canQuickVerify(bag);
    assertTrue("Since " + bag.getRootDir() + " DOES contain the metadata Payload-Oxum then it should return true!", canQuickVerify);
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 17 with Bag

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

the class BagWriterTest method testWriteVersion95.

@Test
public void testWriteVersion95() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_95/bag").toURI());
    Bag bag = reader.read(rootDir);
    File bagitDir = folder.newFolder();
    Path bagitDirPath = Paths.get(bagitDir.toURI());
    List<Path> expectedPaths = Arrays.asList(bagitDirPath.resolve("tagmanifest-md5.txt"), bagitDirPath.resolve("manifest-md5.txt"), bagitDirPath.resolve("bagit.txt"), bagitDirPath.resolve("package-info.txt"), bagitDirPath.resolve("data"), bagitDirPath.resolve("data").resolve("test1.txt"), bagitDirPath.resolve("data").resolve("test2.txt"), bagitDirPath.resolve("data").resolve("dir1"), bagitDirPath.resolve("data").resolve("dir2"), bagitDirPath.resolve("data").resolve("dir1").resolve("test3.txt"), bagitDirPath.resolve("data").resolve("dir2").resolve("test4.txt"), bagitDirPath.resolve("data").resolve("dir2").resolve("dir3"), bagitDirPath.resolve("data").resolve("dir2").resolve("dir3").resolve("test5.txt"));
    BagWriter.write(bag, bagitDirPath);
    for (Path expectedPath : expectedPaths) {
        assertTrue("Expected " + expectedPath + " to exist!", Files.exists(expectedPath));
    }
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 18 with Bag

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

the class BagWriterTest method testWriteVersion2_0.

@Test
public void testWriteVersion2_0() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v2_0/bag").toURI());
    Bag bag = reader.read(rootDir);
    File bagitDir = folder.newFolder();
    Path bagitDirPath = Paths.get(bagitDir.toURI());
    List<Path> expectedPaths = Arrays.asList(bagitDirPath.resolve(".bagit"), bagitDirPath.resolve(".bagit").resolve("manifest-md5.txt"), bagitDirPath.resolve(".bagit").resolve("bagit.txt"), bagitDirPath.resolve(".bagit").resolve("bag-info.txt"), bagitDirPath.resolve(".bagit").resolve("tagmanifest-md5.txt"), bagitDirPath.resolve("test1.txt"), bagitDirPath.resolve("test2.txt"), bagitDirPath.resolve("dir1"), bagitDirPath.resolve("dir2"), bagitDirPath.resolve("dir1").resolve("test3.txt"), bagitDirPath.resolve("dir2").resolve("test4.txt"), bagitDirPath.resolve("dir2").resolve("dir3"), bagitDirPath.resolve("dir2").resolve("dir3").resolve("test5.txt"));
    BagWriter.write(bag, bagitDirPath);
    for (Path expectedPath : expectedPaths) {
        assertTrue("Expected " + expectedPath + " to exist!", Files.exists(expectedPath));
    }
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 19 with Bag

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

the class BagWriterTest method testWriteHoley.

@Test
public void testWriteHoley() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_96/holey-bag").toURI());
    Bag bag = reader.read(rootDir);
    File bagitDir = folder.newFolder();
    BagWriter.write(bag, Paths.get(bagitDir.toURI()));
    assertTrue(bagitDir.exists());
    File fetchFile = new File(bagitDir, "fetch.txt");
    assertTrue(fetchFile.exists());
}
Also used : Path(java.nio.file.Path) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 20 with Bag

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

the class PathUtilsTest method testGetDataDirUsingBag.

@Test
public void testGetDataDirUsingBag() throws IOException {
    Bag bag = new Bag(new Version(2, 0));
    bag.setRootDir(Paths.get("foo"));
    Path expectedPath = bag.getRootDir();
    Path actualPath = PathUtils.getDataDir(bag);
    assertEquals(expectedPath, actualPath);
    bag = new Bag(new Version(0, 97));
    bag.setRootDir(Paths.get("foo"));
    expectedPath = bag.getRootDir().resolve("data");
    actualPath = PathUtils.getDataDir(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)

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