CliMain { private void workflowCreate() throws IOException, ExecutionException, InterruptedException { final String component = namespace.getString(parser.workflowCreateComponentId.getDest()); final File file = namespace.get(parser.workflowCreateFile.getDest()); final ObjectReader workflowReader = Json.YAML_MAPPER.reader() .forType(WorkflowConfiguration.class); final MappingIterator<WorkflowConfiguration> iterator; if (file == null || file.getName().equals("-")) { iterator = workflowReader.readValues(System.in); } else { iterator = workflowReader.readValues(file); } final List<WorkflowConfiguration> configurations; try { configurations = iterator.readAll(); } catch (IOException e) { throw createInputErrorException(e); } boolean invalid = false; for (WorkflowConfiguration configuration : configurations) { var workflow = Workflow.create(component, configuration); var errors = cliContext.workflowValidator().validateWorkflow(workflow); if (!errors.isEmpty()) { cliOutput.printError("Invalid workflow configuration: " + configuration.id()); errors.forEach(error -> cliOutput.printError(" error: " + error)); invalid = true; } } if (invalid) { throw CliExitException.of(ExitStatus.ArgumentError); } final List<CompletionStage<Workflow>> futures = configurations.stream() .map(configuration -> styxClient.createOrUpdateWorkflow(component, configuration)) .collect(toList()); for (CompletionStage<Workflow> future : futures) { final Workflow created = future.toCompletableFuture().get(); cliOutput.printMessage("Workflow " + created.workflowId() + " in component " + created.componentId() + " created."); } } private  CliMain(
      StyxCliParser parser,
      Namespace namespace,
      String apiHost,
      CliOutput cliOutput,
      CliContext cliContext,
      boolean debug); static void main(String... args);  }
@Test public void testWorkflowCreate() throws Exception { final String component = "quux"; final Path workflowsFile = fileFromResource("workflows.yaml"); final List<WorkflowConfiguration> expected = Json.YAML_MAPPER .reader().forType(WorkflowConfiguration.class) .<WorkflowConfiguration>readValues(workflowsFile.toFile()) .readAll(); assertThat(expected, is(not(Matchers.empty()))); when(client.createOrUpdateWorkflow(any(), any())).thenAnswer(a -> { final String comp = a.getArgument(0); final WorkflowConfiguration wfConfig = a.getArgument(1); return CompletableFuture.completedFuture(Workflow.create(comp, wfConfig)); }); CliMain.run(cliContext, "workflow", "create", component, "-f", workflowsFile.toString()); for (WorkflowConfiguration workflowConfiguration : expected) { verify(client).createOrUpdateWorkflow(component, workflowConfiguration); verify(cliOutput).printMessage("Workflow " + workflowConfiguration.id() + " in component " + component + " created."); } }