Skip to content

Commit

Permalink
refs LibraryOfCongress#124 renamed to make it more clear that we veri…
Browse files Browse the repository at this point in the history
…fy all manifests, not just payload manifest
  • Loading branch information
jscancella authored and Richard van Heest committed Feb 20, 2019
1 parent e6ce9a7 commit eff1c35
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class BagVerifier implements AutoCloseable{
private static final Logger logger = LoggerFactory.getLogger(BagVerifier.class);
private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle");

private final PayloadVerifier manifestVerifier;
private final ManifestVerifier manifestVerifier;
private final ExecutorService executor;

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ public BagVerifier(final ExecutorService executor){
* @param executor the thread pool to use when doing work
*/
public BagVerifier(final ExecutorService executor, final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping){
manifestVerifier = new PayloadVerifier(nameMapping, executor);
manifestVerifier = new ManifestVerifier(nameMapping, executor);
this.executor = executor;
}

Expand Down Expand Up @@ -209,14 +209,14 @@ public void isComplete(final Bag bag, final boolean ignoreHiddenFiles) throws

MandatoryVerifier.checkIfAtLeastOnePayloadManifestsExist(bag.getRootDir(), bag.getVersion());

manifestVerifier.verifyPayload(bag, ignoreHiddenFiles);
manifestVerifier.verifyManifests(bag, ignoreHiddenFiles);
}

public ExecutorService getExecutor() {
return executor;
}

public PayloadVerifier getManifestVerifier() {
public ManifestVerifier getManifestVerifier() {
return manifestVerifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
/**
* Responsible for all things related to the manifest during verification.
*/
public class PayloadVerifier implements AutoCloseable{
private static final Logger logger = LoggerFactory.getLogger(PayloadVerifier.class);
public class ManifestVerifier implements AutoCloseable{
private static final Logger logger = LoggerFactory.getLogger(ManifestVerifier.class);
private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle");

private transient final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping;
Expand All @@ -42,7 +42,7 @@ public class PayloadVerifier implements AutoCloseable{
* Create a PayloadVerifier using a cached thread pool and the
* {@link StandardBagitAlgorithmNameToSupportedAlgorithmMapping} mapping
*/
public PayloadVerifier(){
public ManifestVerifier(){
this(new StandardBagitAlgorithmNameToSupportedAlgorithmMapping(), Executors.newCachedThreadPool());
}

Expand All @@ -51,7 +51,7 @@ public PayloadVerifier(){
*
* @param nameMapping the mapping between BagIt algorithm name and the java supported algorithm
*/
public PayloadVerifier(final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping) {
public ManifestVerifier(final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping) {
this(nameMapping, Executors.newCachedThreadPool());
}

Expand All @@ -61,7 +61,7 @@ public PayloadVerifier(final BagitAlgorithmNameToSupportedAlgorithmMapping nameM
*
* @param executor the thread pool to use when doing work
*/
public PayloadVerifier(final ExecutorService executor) {
public ManifestVerifier(final ExecutorService executor) {
this(new StandardBagitAlgorithmNameToSupportedAlgorithmMapping(), executor);
}

Expand All @@ -71,7 +71,7 @@ public PayloadVerifier(final ExecutorService executor) {
* @param nameMapping the mapping between BagIt algorithm name and the java supported algorithm
* @param executor the thread pool to use when doing work
*/
public PayloadVerifier(final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping, final ExecutorService executor) {
public ManifestVerifier(final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping, final ExecutorService executor) {
this.nameMapping = nameMapping;
this.executor = executor;
}
Expand All @@ -83,19 +83,20 @@ public void close() throws SecurityException{
}

/**
* Verify that all the files in the payload directory are listed in the manifest and
* all files listed in the manifests exist.
* Verify that all the files in the payload directory are listed in the payload manifest and
* all files listed in all manifests exist.
*
* @param bag the bag to check to check
* @param ignoreHiddenFiles to ignore hidden files unless they are specifically listed in a manifest
*
* @throws IOException if there is a problem reading a file
* @throws MaliciousPathException the path in the manifest was specifically crafted to cause harm
* @throws UnsupportedAlgorithmException if the algorithm used for the manifest is unsupported
* @throws InvalidBagitFileFormatException if any of the manifests don't conform to the bagit specification
* @throws FileNotInPayloadDirectoryException if a file is listed in a manifest but doesn't exist in the payload directory
* @throws InterruptedException if a thread is interrupted while doing work
*/
public void verifyPayload(final Bag bag, final boolean ignoreHiddenFiles)
public void verifyManifests(final Bag bag, final boolean ignoreHiddenFiles)
throws IOException, MaliciousPathException, UnsupportedAlgorithmException,
InvalidBagitFileFormatException, FileNotInPayloadDirectoryException, InterruptedException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ public class PayloadVerifierTest {
private Path rootDir = Paths.get(new File("src/test/resources/bags/v0_97/bag").toURI());
private BagReader reader = new BagReader();

private PayloadVerifier sut;
private ManifestVerifier sut;

@BeforeEach
public void setup(){
sut = new PayloadVerifier(new StandardBagitAlgorithmNameToSupportedAlgorithmMapping());
sut = new ManifestVerifier(new StandardBagitAlgorithmNameToSupportedAlgorithmMapping());
}

@Test
public void testOtherConstructors() throws Exception {
rootDir = Paths.get(new File("src/test/resources/bags/v0_96/bag-with-tagfiles-in-payload-manifest").toURI());
Bag bag = reader.read(rootDir);

sut = new PayloadVerifier();
sut.verifyPayload(bag, true);
sut = new ManifestVerifier();
sut.verifyManifests(bag, true);

sut = new PayloadVerifier(Executors.newCachedThreadPool());
sut.verifyPayload(bag, true);
sut = new ManifestVerifier(Executors.newCachedThreadPool());
sut.verifyManifests(bag, true);
}

@Test
Expand All @@ -45,7 +45,7 @@ public void testErrorWhenManifestListFileThatDoesntExist() throws Exception{
Bag bag = reader.read(rootDir);

Assertions.assertThrows(FileNotInPayloadDirectoryException.class,
() -> { sut.verifyPayload(bag, true); });
() -> { sut.verifyManifests(bag, true); });
}

@Test
Expand All @@ -54,22 +54,22 @@ public void testErrorWhenFileIsntInManifest() throws Exception{
Bag bag = reader.read(rootDir);

Assertions.assertThrows(FileNotInManifestException.class,
() -> { sut.verifyPayload(bag, true); });
() -> { sut.verifyManifests(bag, true); });
}

@Test
public void testBagWithTagFilesInPayloadIsValid() throws Exception{
rootDir = Paths.get(new File("src/test/resources/bags/v0_96/bag-with-tagfiles-in-payload-manifest").toURI());
Bag bag = reader.read(rootDir);

sut.verifyPayload(bag, true);
sut.verifyManifests(bag, true);
}

@Test
public void testNotALlFilesListedInAllManifestsThrowsException() throws Exception{
Path bagDir = Paths.get(new File("src/test/resources/notAllFilesListedInAllManifestsBag").toURI());
Bag bag = reader.read(bagDir);
Assertions.assertThrows(FileNotInManifestException.class,
() -> { sut.verifyPayload(bag, true); });
() -> { sut.verifyManifests(bag, true); });
}
}

0 comments on commit eff1c35

Please sign in to comment.