public void testVerifyIngests() throws Exception {
PGETaskInstance pgeTask = createTestInstance();
// Test case failure.
AutoDetectProductCrawler pc = createMock(AutoDetectProductCrawler.class);
IngestStatus failedIngestStatus = new IngestStatus() {
@Override
public String getMessage() {
return "Ingest Failure";
}
@Override
public File getProduct() {
return new File("/tmp/dir1");
}
@Override
public Result getResult() {
return Result.FAILURE;
}
};
expect(pc.getIngestStatus()).andReturn(
Lists.newArrayList(failedIngestStatus));
replay(pc);
try {
pgeTask.verifyIngests(pc);
fail("Should have thrown");
} catch (Exception e) { /* expect throw */ }
verify(pc);
// Test case warn failure of precondition, but success overall.
pc = createMock(AutoDetectProductCrawler.class);
IngestStatus precondsFailIngestStatus = new IngestStatus() {
@Override
public String getMessage() {
return "Preconditions failed";
}
@Override
public File getProduct() {
return new File("/tmp/dir1");
}
@Override
public Result getResult() {
return Result.PRECONDS_FAILED;
}
};
expect(pc.getIngestStatus()).andReturn(
Lists.newArrayList(precondsFailIngestStatus));
replay(pc);
pgeTask.logger = createMock(Logger.class);
pgeTask.logger.info("Verifying ingests successful...");
pgeTask.logger.warning(
"Product was not ingested [file='/tmp/dir1',result='PRECONDS_FAILED',msg='Preconditions failed']");
pgeTask.logger.info("Ingests were successful");
replay(pgeTask.logger);
pgeTask.verifyIngests(pc);
verify(pc);
verify(pgeTask.logger);
// Test case success.
pc = createMock(AutoDetectProductCrawler.class);
IngestStatus successIngestStatus = new IngestStatus() {
@Override
public String getMessage() {
return "Ingest Success";
}
@Override