Search in sources :

Example 26 with Manifest

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

the class PayloadWriterTest method testWritePayloadFiles.

@Test
public void testWritePayloadFiles() throws IOException, URISyntaxException {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_97/bag").toURI());
    Path testFile = Paths.get(getClass().getClassLoader().getResource("bags/v0_97/bag/data/dir1/test3.txt").toURI());
    Manifest manifest = new Manifest(StandardSupportedAlgorithms.MD5);
    manifest.getFileToChecksumMap().put(testFile, "someHashValue");
    Set<Manifest> payloadManifests = new HashSet<>();
    payloadManifests.add(manifest);
    File outputDir = folder.newFolder();
    File copiedFile = new File(outputDir, "data/dir1/test3.txt");
    assertFalse(copiedFile.exists() || copiedFile.getParentFile().exists());
    PayloadWriter.writePayloadFiles(payloadManifests, new ArrayList<>(), Paths.get(outputDir.toURI()), rootDir);
    assertTrue(copiedFile.exists() && copiedFile.getParentFile().exists());
}
Also used : Path(java.nio.file.Path) Manifest(gov.loc.repository.bagit.domain.Manifest) File(java.io.File) HashSet(java.util.HashSet) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 27 with Manifest

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

the class PayloadWriterTest method testWritePayloadFilesMinusFetchFiles.

@Test
public void testWritePayloadFilesMinusFetchFiles() throws IOException, URISyntaxException {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_97/bag").toURI());
    Path testFile = Paths.get(getClass().getClassLoader().getResource("bags/v0_97/bag/data/dir1/test3.txt").toURI());
    Manifest manifest = new Manifest(StandardSupportedAlgorithms.MD5);
    manifest.getFileToChecksumMap().put(testFile, "someHashValue");
    Set<Manifest> payloadManifests = new HashSet<>();
    payloadManifests.add(manifest);
    File outputDir = folder.newFolder();
    File copiedFile = new File(outputDir, "data/dir1/test3.txt");
    assertFalse(copiedFile.exists() || copiedFile.getParentFile().exists());
    PayloadWriter.writePayloadFiles(payloadManifests, Arrays.asList(new FetchItem(null, null, Paths.get("data/dir1/test3.txt"))), Paths.get(outputDir.toURI()), rootDir.resolve("data"));
    assertFalse(copiedFile.exists() && copiedFile.getParentFile().exists());
}
Also used : Path(java.nio.file.Path) FetchItem(gov.loc.repository.bagit.domain.FetchItem) Manifest(gov.loc.repository.bagit.domain.Manifest) File(java.io.File) HashSet(java.util.HashSet) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Aggregations

Manifest (gov.loc.repository.bagit.domain.Manifest)27 Path (java.nio.file.Path)21 Test (org.junit.Test)16 Bag (gov.loc.repository.bagit.domain.Bag)9 File (java.io.File)8 HashSet (java.util.HashSet)7 PrivateConstructorTest (gov.loc.repository.bagit.PrivateConstructorTest)5 Version (gov.loc.repository.bagit.domain.Version)4 MessageDigest (java.security.MessageDigest)4 SupportedAlgorithm (gov.loc.repository.bagit.hash.SupportedAlgorithm)2 HashMap (java.util.HashMap)2 FetchItem (gov.loc.repository.bagit.domain.FetchItem)1 RequiredManifestNotPresentException (gov.loc.repository.bagit.exceptions.conformance.RequiredManifestNotPresentException)1 StandardSupportedAlgorithms (gov.loc.repository.bagit.hash.StandardSupportedAlgorithms)1