@Test public void shouldCreateValidJsonLFileOutput() throws ContentAddressableStorageServerException, ProcessingException, IOException, InvalidParseOperationException { HandlerIO handler = mock(HandlerIO.class); WorkerParameters workerParameters = mock(WorkerParameters.class); JsonNode auditQuery = JsonHandler .getFromInputStream(getClass().getResourceAsStream("/AuditObjectWorkflow/unitsQuery.json")); when(handler.getJsonFromWorkspace("query.json")).thenReturn(toJsonNode(auditQuery)); Map<String, File> files = new HashMap<>(); doAnswer((args) -> { File file = temporaryFolder.newFile(); files.put(args.getArgument(0), file); return file; }).when(handler).getNewLocalFile(anyString()); ItemStatus itemStatus = auditPreparePlugin.execute(workerParameters, handler); StatusCode globalStatus = itemStatus.getGlobalStatus(); assertThat(globalStatus).isEqualTo(StatusCode.OK); List<String> lines = IOUtils.readLines(new FileInputStream(files.get(AuditPreparePlugin.OBJECT_GROUPS_TO_AUDIT_JSONL)), "UTF-8"); assertThat(lines.size()).isEqualTo(5); JsonLineModel firstLine = JsonHandler.getFromString(lines.get(0), JsonLineModel.class); assertThat(firstLine.getId()).isEqualTo("aebaaaaaaahgotryaauzialjp5zkhgyaaaaq"); assertThat(firstLine.getParams()).isNotNull(); AuditObjectGroup firstDetailLine = JsonHandler.getFromJsonNode(firstLine.getParams(), AuditObjectGroup.class); assertThat(firstDetailLine.getObjects()).isNotEmpty(); assertThat(firstDetailLine.getObjects().size()).isEqualTo(1); assertThat(firstDetailLine.getObjects().get(0).getQualifier()).isEqualTo("BinaryMaster"); assertThat(firstDetailLine.getObjects().get(0).getId()).isEqualTo("aeaaaaaaaahgotryaauzialjp5zkhgiaaaaq"); assertThat(firstDetailLine.getObjects().get(0).getOpi()).isEqualTo("aeeaaaaaachfa7z2aamwwaljp5zj3kqaaaaq"); assertThat(firstDetailLine.getObjects().get(0).getAlgorithm()).isEqualTo("SHA-512"); assertThat(firstDetailLine.getObjects().get(0).getMessageDigest()).isEqualTo("86c0bc701ef6b5dd21b080bc5bb2af38097baa6237275da83a52f092c9eae3e4e4b0247391620bd732fe824d18bd3bb6c37e62ec73a8cf3585c6a799399861b1"); JsonLineModel thirdLine = JsonHandler.getFromString(lines.get(2), JsonLineModel.class); assertThat(thirdLine.getId()).isEqualTo("aebaaaaaaahgotryaauzialjp6aa32aaaaaq"); assertThat(thirdLine.getParams()).isNotNull(); AuditObjectGroup thirdDetailLine = JsonHandler.getFromJsonNode(thirdLine.getParams(), AuditObjectGroup.class); assertThat(thirdDetailLine.getObjects()).isNotEmpty(); assertThat(thirdDetailLine.getObjects().size()).isEqualTo(2); assertThat(thirdDetailLine.getObjects().get(0).getQualifier()).isEqualTo("PhysicalMaster"); assertThat(thirdDetailLine.getObjects().get(1).getQualifier()).isEqualTo("BinaryMaster"); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery query = generateAuditQuery(handler); computePreparation(query, handler, metaDataClient); return buildItemStatus(AUDIT_PREPARATION, StatusCode.OK, createObjectNode()); } catch (InvalidParseOperationException | IOException | ProcessingException e) { LOGGER.error(String.format("Audit action failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(AUDIT_PREPARATION, FATAL, error); } }
AuditPreparePlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery query = generateAuditQuery(handler); computePreparation(query, handler, metaDataClient); return buildItemStatus(AUDIT_PREPARATION, StatusCode.OK, createObjectNode()); } catch (InvalidParseOperationException | IOException | ProcessingException e) { LOGGER.error(String.format("Audit action failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(AUDIT_PREPARATION, FATAL, error); } } }
AuditPreparePlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery query = generateAuditQuery(handler); computePreparation(query, handler, metaDataClient); return buildItemStatus(AUDIT_PREPARATION, StatusCode.OK, createObjectNode()); } catch (InvalidParseOperationException | IOException | ProcessingException e) { LOGGER.error(String.format("Audit action failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(AUDIT_PREPARATION, FATAL, error); } } AuditPreparePlugin(); @VisibleForTesting  AuditPreparePlugin(MetaDataClientFactory metaDataClientFactory); }
AuditPreparePlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery query = generateAuditQuery(handler); computePreparation(query, handler, metaDataClient); return buildItemStatus(AUDIT_PREPARATION, StatusCode.OK, createObjectNode()); } catch (InvalidParseOperationException | IOException | ProcessingException e) { LOGGER.error(String.format("Audit action failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(AUDIT_PREPARATION, FATAL, error); } } AuditPreparePlugin(); @VisibleForTesting  AuditPreparePlugin(MetaDataClientFactory metaDataClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
AuditPreparePlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) { try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery query = generateAuditQuery(handler); computePreparation(query, handler, metaDataClient); return buildItemStatus(AUDIT_PREPARATION, StatusCode.OK, createObjectNode()); } catch (InvalidParseOperationException | IOException | ProcessingException e) { LOGGER.error(String.format("Audit action failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(AUDIT_PREPARATION, FATAL, error); } } AuditPreparePlugin(); @VisibleForTesting  AuditPreparePlugin(MetaDataClientFactory metaDataClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }