use of gov.loc.repository.bagit.domain.Version 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.Version in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadVersion0_95.
@Test
public void testReadVersion0_95() throws Exception {
Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_95/bag").toURI());
Bag bag = sut.read(rootDir);
assertEquals(new Version(0, 95), bag.getVersion());
for (SimpleImmutableEntry<String, String> keyValue : bag.getMetadata().getAll()) {
if ("Package-Size".equals(keyValue.getKey())) {
assertEquals("260 GB", keyValue.getValue());
}
}
}
use of gov.loc.repository.bagit.domain.Version in project bagit-java by LibraryOfCongress.
the class MetadataWriterTest method testWriteBagitInfoFile.
@Test
public void testWriteBagitInfoFile() throws IOException {
File rootDir = folder.newFolder();
File bagInfo = new File(rootDir, "bag-info.txt");
File packageInfo = new File(rootDir, "package-info.txt");
Metadata metadata = new Metadata();
metadata.add("key1", "value1");
metadata.add("key2", "value2");
metadata.add("key3", "value3");
assertFalse(bagInfo.exists());
assertFalse(packageInfo.exists());
MetadataWriter.writeBagMetadata(metadata, new Version(0, 96), Paths.get(rootDir.toURI()), StandardCharsets.UTF_8);
assertTrue(bagInfo.exists());
MetadataWriter.writeBagMetadata(metadata, new Version(0, 95), Paths.get(rootDir.toURI()), StandardCharsets.UTF_8);
assertTrue(packageInfo.exists());
}
use of gov.loc.repository.bagit.domain.Version in project bagit-java by LibraryOfCongress.
the class MandatoryVerifier method checkBagitFileExists.
/**
* make sure the bagit.txt file exists
*
* @param rootDir the root directory of the bag
* @param version the version of the bag
* @throws MissingBagitFileException if the bag does not contain the bagit.txt file as required by the bagit specification
*/
public static void checkBagitFileExists(final Path rootDir, final Version version) throws MissingBagitFileException {
logger.info("Checking if bagit.txt file exists");
Path bagitFile = rootDir.resolve("bagit.txt");
// @Incubating
if (version.isSameOrNewer(new Version(2, 0))) {
// is it a .bagit version?
bagitFile = rootDir.resolve(DOT_BAGIT_DIR_NAME + File.separator + "bagit.txt");
}
if (!Files.exists(bagitFile)) {
final String formattedMessage = messages.getString("file_should_exist_error");
throw new MissingBagitFileException(MessageFormatter.format(formattedMessage, bagitFile).getMessage());
}
}
use of gov.loc.repository.bagit.domain.Version in project bagit-java by LibraryOfCongress.
the class PathUtilsTest method testGetDataDirUsingVersion.
@Test
public void testGetDataDirUsingVersion() throws IOException {
Path input = Paths.get("foo");
Path expectedPath = input;
Path actualPath = PathUtils.getDataDir(new Version(2, 0), input);
assertEquals(expectedPath, actualPath);
expectedPath = input.resolve("data");
actualPath = PathUtils.getDataDir(new Version(0, 97), input);
assertEquals(expectedPath, actualPath);
}
Aggregations