use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.
the class BagProfileCheckerTest method testBagConformsToProfile.
@Test
public void testBagConformsToProfile() throws Exception {
Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/profileConformantBag").toPath();
Bag bag = reader.read(bagRootPath);
try (InputStream inputStream = Files.newInputStream(profileJson, StandardOpenOption.READ)) {
BagProfileChecker.bagConformsToProfile(inputStream, bag);
}
}
use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.
the class BagCreatorTest method testBagInPlaceIncludingHidden.
@Test
public void testBagInPlaceIncludingHidden() throws IOException, NoSuchAlgorithmException {
TestStructure structure = createTestStructure();
Bag bag = BagCreator.bagInPlace(Paths.get(folder.getRoot().toURI()), Arrays.asList(StandardSupportedAlgorithms.MD5), true);
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());
for (Manifest manifest : bag.getPayLoadManifests()) {
for (Path expectedPayloadFile : manifest.getFileToChecksumMap().keySet()) {
assertTrue(expectedPayloadFile + " doesn't exist but it should!", structure.regularPayloadFiles.contains(expectedPayloadFile) || structure.hiddenPayloadFiles.contains(expectedPayloadFile));
}
}
}
use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadISO_8859_1Encoding.
@Test
public void testReadISO_8859_1Encoding() throws Exception {
Metadata expectedMetaData = new Metadata();
expectedMetaData.add("Bag-Software-Agent", "bagit.py <http://github.com/libraryofcongress/bagit-python>");
expectedMetaData.add("Bagging-Date", "2016-02-26");
expectedMetaData.add("Contact-Email", "cadams@loc.gov");
expectedMetaData.add("Contact-Name", "Chris Adams");
expectedMetaData.add("Payload-Oxum", "58.2");
Path bagPath = Paths.get(new File("src/test/resources/ISO-8859-1-encodedBag").toURI());
Bag bag = sut.read(bagPath);
assertNotNull(bag);
assertEquals(StandardCharsets.ISO_8859_1, bag.getFileEncoding());
assertEquals(expectedMetaData, bag.getMetadata());
}
use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadVersion2_0Bag.
@Test
public void testReadVersion2_0Bag() throws Exception {
Path rootBag = Paths.get(getClass().getClassLoader().getResource("bags/v2_0/bag").toURI());
Path[] payloadFiles = new Path[] { rootBag.resolve("dir1/test3.txt"), rootBag.resolve("dir2/dir3/test5.txt"), rootBag.resolve("dir2/test4.txt"), rootBag.resolve("test1.txt"), rootBag.resolve("test2.txt") };
Bag returnedBag = sut.read(rootBag);
assertNotNull(returnedBag);
assertEquals(new Version(2, 0), returnedBag.getVersion());
Manifest payloadManifest = (Manifest) returnedBag.getPayLoadManifests().toArray()[0];
for (Path payloadFile : payloadFiles) {
assertTrue("payload manifest should contain " + payloadFile, payloadManifest.getFileToChecksumMap().containsKey(payloadFile));
}
}
use of gov.loc.repository.bagit.domain.Bag in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadBagWithDotSlash.
@Test
public void testReadBagWithDotSlash() throws Exception {
Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_96/bag-with-leading-dot-slash-in-manifest").toURI());
Bag bag = sut.read(rootDir);
assertNotNull(bag);
for (Manifest payloadManifest : bag.getPayLoadManifests()) {
for (Path file : payloadManifest.getFileToChecksumMap().keySet()) {
assertTrue(file + " should exist but it doesn't!", Files.exists(file));
}
}
}
Aggregations