PrettyCliOutput implements CliOutput { @Override public void printBackfills(List<BackfillPayload> backfills, boolean noTruncate) { final int cidLength = backfills.stream() .map(x -> effectiveLongFieldLength( Optional.of(x.backfill().workflowId().componentId()), COMPONENT_HEADER, true)) .max(Comparator.naturalOrder()) .orElse(1); final int widLength = backfills.stream() .map(x -> effectiveLongFieldLength( Optional.of(x.backfill().workflowId().id()), WORKFLOW_HEADER, true)) .max(Comparator.naturalOrder()) .orElse(1); final int descriptionLength = backfills.stream() .map(x -> effectiveLongFieldLength( x.backfill().description(), DESCRIPTION_HEADER, noTruncate)) .max(Comparator.naturalOrder()) .orElse(1); printBackfillHeader(cidLength, widLength, descriptionLength); for (BackfillPayload backfillPayload : backfills) { printBackfill(backfillPayload.backfill(), cidLength, widLength, descriptionLength, noTruncate); if (backfillPayload.statuses().isPresent()) { System.out.println(); System.out.println(); printStates(backfillPayload.statuses().get()); } } }  @Override void printStates(RunStateDataPayload runStateDataPayload); @Override void printEvents(List<EventInfo> eventInfos); @Override void printBackfill(Backfill backfill, boolean noTruncate); @Override void printBackfillPayload(BackfillPayload backfillPayload, boolean noTruncate); @Override void printBackfills(List<BackfillPayload> backfills, boolean noTruncate); @Override void printResources(List<Resource> resources); @Override void printMessage(String message); @Override void printWorkflow(Workflow wf, WorkflowState state); @Override void printWorkflows(List<Workflow> workflows); @Override void printError(String message);  }
@Test public void shouldPrintBackfills() { cliOutput.printBackfills( List.of(BackfillPayload.create(backfill(LONG_DESCRIPTION), Optional.empty())), false); assertEquals(EXPECTED_HEADER_WITH_TRUNCATED_DESCRIPTION + " backfill-2 false false 2 " + "2017-01-01 2017-01-02 false 2017-01-01 component " + "workflow2 2019-01-01T00:00:00Z 2019-06-01T00:00:00Z Description which is... FOO=bar\n", outContent.toString()); }
@Test public void shouldPrintBackfillsNoCreateTS() { cliOutput.printBackfills( List.of(BackfillPayload.create(backfillNoCreateTS(LONG_DESCRIPTION), Optional.empty())), false); assertEquals(EXPECTED_HEADER_WITH_TRUNCATED_DESCRIPTION + " backfill-2 false false 2 " + "2017-01-01 2017-01-02 false 2017-01-01 component " + "workflow2 Description which is... FOO=bar\n", outContent.toString()); }
@Test public void shouldPrintBackfillsWithoutTruncating() { cliOutput.printBackfills( List.of(BackfillPayload.create(backfill(LONG_DESCRIPTION), Optional.empty())), true); assertEquals(EXPECTED_HEADER_WITH_FULL_DESCRIPTION + " backfill-2 false false 2 " + "2017-01-01 2017-01-02 false 2017-01-01 component " + "workflow2 2019-01-01T00:00:00Z 2019-06-01T00:00:00Z Description which is long enough to truncate FOO=bar\n", outContent.toString()); }
@Test public void shouldPrintNAWhenBackfillLacksDescription() { cliOutput.printBackfills( List.of(BackfillPayload.create(backfill(null), Optional.empty())) , false); assertEquals(EXPECTED_HEADER + " backfill-2 false false 2 " + "2017-01-01 2017-01-02 false 2017-01-01 " + "component workflow2 2019-01-01T00:00:00Z 2019-06-01T00:00:00Z N/A FOO=bar\n", outContent.toString()); }