use of gov.loc.repository.bagit.domain.Metadata in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadUTF_16_Encoding.
@Test
public void testReadUTF_16_Encoding() 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/UTF-16-encoded-tag-files").toURI());
List<FetchItem> expectedFetchItems = new ArrayList<>();
expectedFetchItems.add(new FetchItem(new URL("http://localhost/foo/data/dir1/test3.txt"), -1l, bagPath.resolve("data/dir1/test3.txt")));
Bag bag = sut.read(bagPath);
assertNotNull(bag);
assertEquals(StandardCharsets.UTF_16, bag.getFileEncoding());
assertEquals(expectedMetaData, bag.getMetadata());
assertEquals(expectedFetchItems, bag.getItemsToFetch());
}
use of gov.loc.repository.bagit.domain.Metadata 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.Metadata 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());
}
Aggregations