@Test @RunWithCustomExecutor public void should_return_item_status_FATAL_when_something_wrong() throws Exception { String probativeEntryIdInDistributionFile = "BATMAN_GOT_ID"; PreservationRequest request = new PreservationRequest(); ProbativeReportEntry object = ProbativeReportEntry .koFrom(LocalDateUtil.getFormattedDateForMongo(LocalDateUtil.now()), Collections.singletonList("unitId"), "groupId", "objectId", "usageVersion"); TestHandlerIO handler = new TestHandlerIO(); handler.transferFileToWorkspace("request", pojoToFile(request), false, false); handler.setInputStreamFromWorkspace( writeDistributionFile(new JsonLineModel(probativeEntryIdInDistributionFile, 0, null))); handler.transferFileToWorkspace(probativeEntryIdInDistributionFile, pojoToFile(object), false, false); handler.setNewLocalFile(tempFolder.newFile(GUIDFactory.newGUID().getId())); String containerName = handler.getContainerName(); WorkerParameters build = workerParameterBuilder() .withContainerName(containerName) .build(); when(backupService.storeIntoOffers(anyString(), anyString(), any(), any(), anyString())) .thenThrow(new IllegalStateException()); ItemStatus itemStatus = probativeCreateReport.execute(build, handler); assertThat(itemStatus.getGlobalStatus()).isEqualTo(FATAL); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } }
ProbativeCreateReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } } }
ProbativeCreateReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } } @VisibleForTesting  ProbativeCreateReport(BackupService backupService);  ProbativeCreateReport(); }
ProbativeCreateReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } } @VisibleForTesting  ProbativeCreateReport(BackupService backupService);  ProbativeCreateReport(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
ProbativeCreateReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } } @VisibleForTesting  ProbativeCreateReport(BackupService backupService);  ProbativeCreateReport(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }