@Test public void should_generate_distribution_file_with_requested_ids() throws Exception { InputStream query = PropertiesUtils.getResourceAsStream("computeInheritedRules/query.json"); File distributionFile = temporaryFolder.newFile(); WorkerParameters workerParameters = mock(WorkerParameters.class); JsonNode unitResponse = JsonHandler.getFromInputStream(PropertiesUtils.getResourceAsStream("computeInheritedRules/unit.json")); when(metaDataClient.selectUnits(any())).thenReturn(unitResponse); HandlerIO handlerIO = mock(HandlerIO.class); when(handlerIO.getJsonFromWorkspace(anyString())).thenReturn(JsonHandler.getFromInputStream(query)); when(handlerIO.getNewLocalFile(anyString())).thenReturn(distributionFile); File resultFile = temporaryFolder.newFile(); doAnswer(invocation -> { File distributionFileCaptured = invocation.getArgument(1); try(FileOutputStream fileOutputStream = new FileOutputStream(resultFile)){ Files.copy(distributionFileCaptured.toPath(), fileOutputStream); } return null; }).when(handlerIO) .transferFileToWorkspace(ArgumentMatchers.eq(UNITS_JSONL_FILE), any(), ArgumentMatchers.eq(true), ArgumentMatchers.eq(false)); ItemStatus itemStatus = computeInheritedRulesPreparationPlugin.execute(workerParameters, handlerIO); StatusCode globalStatus = itemStatus.getGlobalStatus(); assertThat(globalStatus).isEqualTo(StatusCode.OK); JsonLineGenericIterator<JsonLineModel> lines = new JsonLineGenericIterator<>(new FileInputStream(resultFile), jsonLineModelTypeReference); List<String> unitIds = lines.stream().map(JsonLineModel::getId).collect(Collectors.toList()); assertThat(unitIds.size()).isEqualTo(4); assertThat(unitIds).contains("id_unit_1", "id_unit_2", "id_unit_3", "id_unit_4"); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { JsonNode dslQuery = handler.getJsonFromWorkspace("query.json"); try { process(handler, dslQuery); } catch (ComputedInheritedRulesException e) { LOGGER.error(String.format("ComputeInheritedRules preparation failed with status [%s]", e.getStatusCode()), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, e.getStatusCode(), error); } return buildItemStatus(PLUGIN_NAME, StatusCode.OK, null); }
ComputeInheritedRulesPreparationPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { JsonNode dslQuery = handler.getJsonFromWorkspace("query.json"); try { process(handler, dslQuery); } catch (ComputedInheritedRulesException e) { LOGGER.error(String.format("ComputeInheritedRules preparation failed with status [%s]", e.getStatusCode()), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, e.getStatusCode(), error); } return buildItemStatus(PLUGIN_NAME, StatusCode.OK, null); } }
ComputeInheritedRulesPreparationPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { JsonNode dslQuery = handler.getJsonFromWorkspace("query.json"); try { process(handler, dslQuery); } catch (ComputedInheritedRulesException e) { LOGGER.error(String.format("ComputeInheritedRules preparation failed with status [%s]", e.getStatusCode()), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, e.getStatusCode(), error); } return buildItemStatus(PLUGIN_NAME, StatusCode.OK, null); } ComputeInheritedRulesPreparationPlugin(); @VisibleForTesting  ComputeInheritedRulesPreparationPlugin(MetaDataClientFactory metaDataClientFactory); }
ComputeInheritedRulesPreparationPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { JsonNode dslQuery = handler.getJsonFromWorkspace("query.json"); try { process(handler, dslQuery); } catch (ComputedInheritedRulesException e) { LOGGER.error(String.format("ComputeInheritedRules preparation failed with status [%s]", e.getStatusCode()), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, e.getStatusCode(), error); } return buildItemStatus(PLUGIN_NAME, StatusCode.OK, null); } ComputeInheritedRulesPreparationPlugin(); @VisibleForTesting  ComputeInheritedRulesPreparationPlugin(MetaDataClientFactory metaDataClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
ComputeInheritedRulesPreparationPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { JsonNode dslQuery = handler.getJsonFromWorkspace("query.json"); try { process(handler, dslQuery); } catch (ComputedInheritedRulesException e) { LOGGER.error(String.format("ComputeInheritedRules preparation failed with status [%s]", e.getStatusCode()), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, e.getStatusCode(), error); } return buildItemStatus(PLUGIN_NAME, StatusCode.OK, null); } ComputeInheritedRulesPreparationPlugin(); @VisibleForTesting  ComputeInheritedRulesPreparationPlugin(MetaDataClientFactory metaDataClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }