@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));
}