PGETaskInstance implements WorkflowTaskInstance { protected void verifyIngests(ProductCrawler crawler) throws PGEException { julLogger.info("Verifying ingests successful..."); boolean ingestsSuccess = true; String exceptionMsg = ""; for (IngestStatus status : crawler.getIngestStatus()) { if (status.getResult().equals(IngestStatus.Result.FAILURE)) { exceptionMsg += (exceptionMsg.equals("") ? "" : " : ") + "Failed to ingest product [file='" + status.getProduct().getAbsolutePath() + "',result='" + status.getResult() + "',msg='" + status.getMessage() + "']"; ingestsSuccess = false; } else if (!status.getResult().equals(IngestStatus.Result.SUCCESS)) { julLogger.warning(String.format("Product was not ingested [file='%s',result='%s',msg='%s']", status.getProduct().getAbsolutePath(), status.getResult(),status.getMessage())); } } if (!ingestsSuccess) { julLogger.severe("Ingest wasn't successful: " + exceptionMsg); throw new PGEException(exceptionMsg); } else { julLogger.info("Ingests were successful"); } } protected  PGETaskInstance(); @Override void run(Metadata metadata, WorkflowTaskConfiguration config); String getWorkflowInstId(); void setWorkflowInstId(String workflowInstId); void setWmClient(WorkflowManagerClient wmClient); @Override void finalize();  }
@Test public void testVerifyIngests() throws Exception { PGETaskInstance pgeTask = createTestInstance(); 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) { } verify(pc); 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.julLogger = createMock(Logger.class); pgeTask.julLogger.info("Verifying ingests successful..."); pgeTask.julLogger.warning( "Product was not ingested [file='/tmp/dir1',result='PRECONDS_FAILED',msg='Preconditions failed']"); pgeTask.julLogger.info("Ingests were successful"); replay(pgeTask.julLogger); pgeTask.verifyIngests(pc); verify(pc); verify(pgeTask.julLogger); pc = createMock(AutoDetectProductCrawler.class); IngestStatus successIngestStatus = new IngestStatus() { @Override public String getMessage() { return "Ingest Success"; } @Override public File getProduct() { return new File("/tmp/dir1"); } @Override public Result getResult() { return Result.SUCCESS; } }; expect(pc.getIngestStatus()).andReturn( Lists.newArrayList(successIngestStatus)); replay(pc); pgeTask.julLogger = createMock(Logger.class); pgeTask.julLogger.info("Verifying ingests successful..."); pgeTask.julLogger.info("Ingests were successful"); replay(pgeTask.julLogger); pgeTask.verifyIngests(pc); verify(pc); verify(pgeTask.julLogger); }