WorkflowInstanceExecutionData { @JsonCreator public static WorkflowInstanceExecutionData create( @JsonProperty("workflow_instance") WorkflowInstance workflowInstance, @JsonProperty("triggers") List<Trigger> triggers) { return new AutoValue_WorkflowInstanceExecutionData(workflowInstance, triggers); }  @JsonProperty abstract WorkflowInstance workflowInstance(); @JsonProperty abstract List<Trigger> triggers(); @JsonCreator static WorkflowInstanceExecutionData create(
      @JsonProperty("workflow_instance") WorkflowInstance workflowInstance,
      @JsonProperty("triggers") List<Trigger> triggers); static final Comparator<WorkflowInstanceExecutionData> COMPARATOR; }
@Test public void shouldDeserializeExecution() throws Exception { String json = executionJson("exec-id", "busybox:1.0", "commit-sha", TEST_RUNNER_ID, "09", "SUCCESS", Optional.empty()); Execution execution = OBJECT_MAPPER.readValue(json, Execution.class); Execution expected = Execution.create( Optional.of("exec-id"), Optional.of("busybox:1.0"), Optional.of("commit-sha"), Optional.of(TEST_RUNNER_ID), Arrays.asList( ExecStatus.create(Instant.parse("2016-08-03T09:56:03.607Z"), "STARTED", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T09:57:03.607Z"), "RUNNING", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T09:58:03.607Z"), "SUCCESS", Optional.empty()) ) ); assertThat(execution, is(expected)); }
@Test public void shouldDeserializeExecutionNoOptionalFields() throws Exception { String json = "{" + "\"statuses\":[" + statusJson("16:56", "HALTED", Optional.empty()) + "]}"; Execution execution = OBJECT_MAPPER.readValue(json, Execution.class); Execution expected = Execution.create( Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), List.of( ExecStatus.create(Instant.parse("2016-08-03T16:56:03.607Z"), "HALTED", Optional.empty()) ) ); assertThat(execution, is(expected)); }
@Test public void shouldDeserializeTrigger() throws Exception { String jsonExec0 = executionJson("exec-id-0", "busybox:1.0", "commit-sha0", TEST_RUNNER_ID, "09", "FAILED", Optional.of("Exit code 1")); String jsonExec1 = executionJson("exec-id-1", "busybox:1.1","commit-sha1", TEST_RUNNER_ID, "10", "SUCCESS", Optional.empty()); String json = "{" + "\"trigger_id\":\"trig-0\"," + "\"timestamp\":\"" + time("07:55") + "\"," + "\"complete\":true," + "\"executions\":[" + jsonExec0 + "," + jsonExec1 + "]}"; Trigger trigger = OBJECT_MAPPER.readValue(json, Trigger.class); Trigger expected = Trigger.create( "trig-0", time("07:55"), TriggerParameters.zero(), true, Arrays.asList( Execution.create( Optional.of("exec-id-0"), Optional.of("busybox:1.0"), Optional.of("commit-sha0"), Optional.of("test"), Arrays.asList( ExecStatus.create(Instant.parse("2016-08-03T09:56:03.607Z"), "STARTED", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T09:57:03.607Z"), "RUNNING", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T09:58:03.607Z"), "FAILED", Optional.of("Exit code 1")) ) ), Execution.create( Optional.of("exec-id-1"), Optional.of("busybox:1.1"), Optional.of("commit-sha1"), Optional.of("test"), Arrays.asList( ExecStatus.create(Instant.parse("2016-08-03T10:56:03.607Z"), "STARTED", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T10:57:03.607Z"), "RUNNING", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T10:58:03.607Z"), "SUCCESS", Optional.empty()) ) ) ) ); assertThat(trigger, is(expected)); }
@Test public void shouldDeserializeTriggerWithParameters() throws Exception { String jsonExec0 = executionJson("exec-id-0", "busybox:1.0","commit-sha0", TEST_RUNNER_ID, "09", "FAILED", Optional.of("Exit code 1")); String jsonExec1 = executionJson("exec-id-1", "busybox:1.1","commit-sha1", TEST_RUNNER_ID, "10", "SUCCESS", Optional.empty()); String json = "{" + "\"trigger_id\":\"trig-0\"," + "\"timestamp\":\"" + time("07:55") + "\"," + "\"parameters\":{\"env\":{\"FOO\":\"foo\",\"BAR\":\"bar\"}}," + "\"complete\":true," + "\"executions\":[" + jsonExec0 + "," + jsonExec1 + "]}"; Trigger trigger = OBJECT_MAPPER.readValue(json, Trigger.class); Trigger expected = Trigger.create( "trig-0", time("07:55"), TriggerParameters.builder() .env("FOO", "foo", "BAR", "bar") .build(), true, Arrays.asList( Execution.create( Optional.of("exec-id-0"), Optional.of("busybox:1.0"), Optional.of("commit-sha0"), Optional.of("test"), Arrays.asList( ExecStatus.create(Instant.parse("2016-08-03T09:56:03.607Z"), "STARTED", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T09:57:03.607Z"), "RUNNING", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T09:58:03.607Z"), "FAILED", Optional.of("Exit code 1")) ) ), Execution.create( Optional.of("exec-id-1"), Optional.of("busybox:1.1"), Optional.of("commit-sha1"), Optional.of("test"), Arrays.asList( ExecStatus.create(Instant.parse("2016-08-03T10:56:03.607Z"), "STARTED", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T10:57:03.607Z"), "RUNNING", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T10:58:03.607Z"), "SUCCESS", Optional.empty()) ) ) ) ); assertThat(trigger, is(expected)); }
@Test public void shouldDeserializeExecutionData() throws Exception { String jsonExec00 = executionJson("exec-id-00", "busybox:1.0","commit-sha0", TEST_RUNNER_ID, "07", "FAILED", Optional.of("Exit code 1")); String jsonExec01 = executionJson("exec-id-01", "busybox:1.1","commit-sha1", TEST_RUNNER_ID, "08", "SUCCESS", Optional.empty()); String jsonTrigger0 = "{" + "\"trigger_id\":\"trig-0\"," + "\"timestamp\":\"" + time("07:55") + "\"," + "\"complete\":true," + "\"executions\":[" + jsonExec00 + "," + jsonExec01 + "]}"; String jsonExec10 = executionJson("exec-id-10", "busybox:1.2","commit-sha2", TEST_RUNNER_ID, "09", "FAILED", Optional.of("Exit code 1")); String jsonExec11 = executionJson("exec-id-11", "busybox:1.3","commit-sha3", TEST_RUNNER_ID, "10", "SUCCESS", Optional.empty()); String jsonTrigger1 = "{" + "\"trigger_id\":\"trig-1\"," + "\"timestamp\":\"" + time("09:55") + "\"," + "\"complete\":false," + "\"executions\":[" + jsonExec10 + "," + jsonExec11 + "]}"; String json = "{" + "\"workflow_instance\":{" + "\"workflow_id\":{" + "\"component_id\":\"component1\"," + "\"id\":\"endpoint1\"" + "}," + "\"parameter\":\"2016-08-03T06\"" + "}," + "\"triggers\":[" + jsonTrigger0 + "," + jsonTrigger1 + "]}"; WorkflowInstanceExecutionData executionData = OBJECT_MAPPER.readValue(json, WorkflowInstanceExecutionData.class); WorkflowInstanceExecutionData expected = WorkflowInstanceExecutionData.create( WorkflowInstance.parseKey("component1#endpoint1#2016-08-03T06"), Arrays.asList( Trigger.create( "trig-0", time("07:55"), TriggerParameters.zero(), true, Arrays.asList( Execution.create( Optional.of("exec-id-00"), Optional.of("busybox:1.0"), Optional.of("commit-sha0"), Optional.of("test"), Arrays.asList( ExecStatus.create(Instant.parse("2016-08-03T07:56:03.607Z"), "STARTED", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T07:57:03.607Z"), "RUNNING", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T07:58:03.607Z"), "FAILED", Optional.of("Exit code 1")) ) ), Execution.create( Optional.of("exec-id-01"), Optional.of("busybox:1.1"), Optional.of("commit-sha1"), Optional.of("test"), Arrays.asList( ExecStatus.create(Instant.parse("2016-08-03T08:56:03.607Z"), "STARTED", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T08:57:03.607Z"), "RUNNING", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T08:58:03.607Z"), "SUCCESS", Optional.empty()) ) ) ) ), Trigger.create( "trig-1", time("09:55"), TriggerParameters.zero(), false, Arrays.asList( Execution.create( Optional.of("exec-id-10"), Optional.of("busybox:1.2"), Optional.of("commit-sha2"), Optional.of("test"), Arrays.asList( ExecStatus.create(Instant.parse("2016-08-03T09:56:03.607Z"), "STARTED", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T09:57:03.607Z"), "RUNNING", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T09:58:03.607Z"), "FAILED", Optional.of("Exit code 1")) ) ), Execution.create( Optional.of("exec-id-11"), Optional.of("busybox:1.3"), Optional.of("commit-sha3"), Optional.of("test"), Arrays.asList( ExecStatus.create(Instant.parse("2016-08-03T10:56:03.607Z"), "STARTED", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T10:57:03.607Z"), "RUNNING", Optional.empty()), ExecStatus.create(Instant.parse("2016-08-03T10:58:03.607Z"), "SUCCESS", Optional.empty()) ) ) ) ) ) ); assertThat(executionData, is(expected)); }