Search in sources :

Example 1 with Metadata

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());
}
Also used : Path(java.nio.file.Path) FetchItem(gov.loc.repository.bagit.domain.FetchItem) Metadata(gov.loc.repository.bagit.domain.Metadata) ArrayList(java.util.ArrayList) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 2 with Metadata

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());
}
Also used : Path(java.nio.file.Path) Metadata(gov.loc.repository.bagit.domain.Metadata) Bag(gov.loc.repository.bagit.domain.Bag) File(java.io.File) Test(org.junit.Test)

Example 3 with Metadata

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());
}
Also used : Version(gov.loc.repository.bagit.domain.Version) Metadata(gov.loc.repository.bagit.domain.Metadata) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Aggregations

Metadata (gov.loc.repository.bagit.domain.Metadata)3 File (java.io.File)3 Test (org.junit.Test)3 Bag (gov.loc.repository.bagit.domain.Bag)2 Path (java.nio.file.Path)2 PrivateConstructorTest (gov.loc.repository.bagit.PrivateConstructorTest)1 FetchItem (gov.loc.repository.bagit.domain.FetchItem)1 Version (gov.loc.repository.bagit.domain.Version)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1