@Test
public void testStatusFromStageEntities() throws Exception {

  // completed request
  Collection<StageEntity> stages = getStageEntities(
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED),
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED),
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED)
  );
  CalculatedStatus status = CalculatedStatus.statusFromStageEntities(stages);
  assertEquals(HostRoleStatus.COMPLETED, status.getStatus());
  assertEquals(100.0, status.getPercent(), 0.1);
  // in progress request
  stages = getStageEntities(
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED),
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.IN_PROGRESS, HostRoleStatus.PENDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING)
  );
  status = CalculatedStatus.statusFromStageEntities(stages);
  assertEquals(HostRoleStatus.IN_PROGRESS, status.getStatus());
  assertEquals(48.3, status.getPercent(), 0.1);
  // pending request
  stages = getStageEntities(
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING)
  );
  status = CalculatedStatus.statusFromStageEntities(stages);
  assertEquals(HostRoleStatus.PENDING, status.getStatus());
  assertEquals(0.0, status.getPercent(), 0.1);
  // failed request
  stages = getStageEntities(
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED),
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.FAILED, HostRoleStatus.PENDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING)
  );
  status = CalculatedStatus.statusFromStageEntities(stages);
  assertEquals(HostRoleStatus.FAILED, status.getStatus());
  assertEquals(55.55, status.getPercent(), 0.1);
  // timed out request
  stages = getStageEntities(
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED),
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.TIMEDOUT),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING)
  );
  status = CalculatedStatus.statusFromStageEntities(stages);
  assertEquals(HostRoleStatus.TIMEDOUT, status.getStatus());
  assertEquals(66.66, status.getPercent(), 0.1);
  // holding request
  stages = getStageEntities(
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED),
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING)
  );
  status = CalculatedStatus.statusFromStageEntities(stages);
  assertEquals(HostRoleStatus.HOLDING, status.getStatus());
  assertEquals(47.5, status.getPercent(), 0.1);
  // holding failed request
  stages = getStageEntities(
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED),
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING)
  );
  status = CalculatedStatus.statusFromStageEntities(stages);
  assertEquals(HostRoleStatus.HOLDING, status.getStatus());
  assertEquals(47.5, status.getPercent(), 0.1);
  // holding timed out request
  stages = getStageEntities(
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED),
      getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING),
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING)
  );
  status = CalculatedStatus.statusFromStageEntities(stages);
  assertEquals(HostRoleStatus.HOLDING, status.getStatus());
  assertEquals(47.5, status.getPercent(), 0.1);
}