Search in sources :

Example 1 with Version

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

the class BagReaderTest method testReadVersion0_93.

@Test
public void testReadVersion0_93() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_93/bag").toURI());
    Bag bag = sut.read(rootDir);
    assertEquals(new Version(0, 93), bag.getVersion());
    for (SimpleImmutableEntry<String, String> keyValue : bag.getMetadata().getAll()) {
        if ("Payload-Oxum".equals(keyValue.getKey())) {
            assertEquals("25.5", keyValue.getValue());
        }
    }
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) Bag(gov.loc.repository.bagit.domain.Bag) Test(org.junit.Test)

Example 2 with Version

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

the class BagReaderTest method testReadVersion0_97Bag.

@Test
public void testReadVersion0_97Bag() throws Exception {
    Path rootBag = Paths.get(new File("src/test/resources/bags/v0_97/bag").toURI());
    Path[] payloadFiles = new Path[] { rootBag.resolve("data/dir1/test3.txt"), rootBag.resolve("data/dir2/dir3/test5.txt"), rootBag.resolve("data/dir2/test4.txt"), rootBag.resolve("data/test1.txt"), rootBag.resolve("data/test2.txt") };
    Bag returnedBag = sut.read(rootBag);
    assertNotNull(returnedBag);
    assertEquals(new Version(0, 97), returnedBag.getVersion());
    Manifest payloadManifest = (Manifest) returnedBag.getPayLoadManifests().toArray()[0];
    for (Path payloadFile : payloadFiles) {
        assertTrue(payloadManifest.getFileToChecksumMap().containsKey(payloadFile));
    }
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) Bag(gov.loc.repository.bagit.domain.Bag) Manifest(gov.loc.repository.bagit.domain.Manifest) File(java.io.File) Test(org.junit.Test)

Example 3 with Version

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

the class BagReaderTest method testReadVersion0_94.

@Test
public void testReadVersion0_94() throws Exception {
    Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_94/bag").toURI());
    Bag bag = sut.read(rootDir);
    assertEquals(new Version(0, 94), bag.getVersion());
    for (SimpleImmutableEntry<String, String> keyValue : bag.getMetadata().getAll()) {
        if ("Payload-Oxum".equals(keyValue.getKey())) {
            assertEquals("25.5", keyValue.getValue());
        }
    }
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) Bag(gov.loc.repository.bagit.domain.Bag) Test(org.junit.Test)

Example 4 with Version

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

the class BagitFileWriterTest method testWriteBagitFile.

@Test
public void testWriteBagitFile() throws Exception {
    File rootDir = folder.newFolder();
    Path rootDirPath = Paths.get(rootDir.toURI());
    Path bagit = rootDirPath.resolve("bagit.txt");
    assertFalse(Files.exists(bagit));
    BagitFileWriter.writeBagitFile(new Version(0, 97), StandardCharsets.UTF_8, rootDirPath);
    assertTrue(Files.exists(bagit));
    // test truncating existing
    long originalModified = Files.getLastModifiedTime(bagit).toMillis();
    long size = Files.size(bagit);
    BagitFileWriter.writeBagitFile(new Version(0, 97), StandardCharsets.UTF_8, rootDirPath);
    assertTrue(Files.exists(bagit));
    assertTrue(Files.getLastModifiedTime(bagit) + " should be >= " + originalModified, Files.getLastModifiedTime(bagit).toMillis() >= originalModified);
    assertEquals(size, Files.size(bagit));
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Example 5 with Version

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

the class BagitTextFileReaderTest method testReadBagitFile.

@Test
public void testReadBagitFile() throws Exception {
    Path bagitFile = Paths.get(new File("src/test/resources/bagitFiles/bagit-0.97.txt").toURI());
    SimpleImmutableEntry<Version, Charset> actualBagitInfo = BagitTextFileReader.readBagitTextFile(bagitFile);
    assertEquals(new Version(0, 97), actualBagitInfo.getKey());
    assertEquals(StandardCharsets.UTF_8, actualBagitInfo.getValue());
}
Also used : Path(java.nio.file.Path) Version(gov.loc.repository.bagit.domain.Version) Charset(java.nio.charset.Charset) File(java.io.File) PrivateConstructorTest(gov.loc.repository.bagit.PrivateConstructorTest) Test(org.junit.Test)

Aggregations

Version (gov.loc.repository.bagit.domain.Version)24 Path (java.nio.file.Path)19 Test (org.junit.Test)17 Bag (gov.loc.repository.bagit.domain.Bag)11 PrivateConstructorTest (gov.loc.repository.bagit.PrivateConstructorTest)7 File (java.io.File)6 Manifest (gov.loc.repository.bagit.domain.Manifest)4 Charset (java.nio.charset.Charset)4 HashSet (java.util.HashSet)3 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2 Metadata (gov.loc.repository.bagit.domain.Metadata)1 InvalidBagitFileFormatException (gov.loc.repository.bagit.exceptions.InvalidBagitFileFormatException)1 MissingBagitFileException (gov.loc.repository.bagit.exceptions.MissingBagitFileException)1