@Test
public void testDependencySorting() throws IOException {

  Component a = ServiceTestUtils.createComponent("a");
  Component b = ServiceTestUtils.createComponent("b");
  Component c = ServiceTestUtils.createComponent("c");
  Component d =
      ServiceTestUtils.createComponent("d").dependencies(Arrays.asList("c"));
  Component e = ServiceTestUtils.createComponent("e")
      .dependencies(Arrays.asList("b", "d"));
  verifyDependencySorting(Arrays.asList(a, b, c), a, b, c);
  verifyDependencySorting(Arrays.asList(c, a, b), c, a, b);
  verifyDependencySorting(Arrays.asList(a, b, c, d, e), a, b, c, d, e);
  verifyDependencySorting(Arrays.asList(e, d, c, b, a), c, b, a, d, e);
  c.setDependencies(Arrays.asList("e"));
  try {
    verifyDependencySorting(Arrays.asList(a, b, c, d, e));
    Assert.fail(EXCEPTION_PREFIX + "components with dependency cycle");
  } catch (IllegalArgumentException ex) {
    assertEquals(String.format(
        RestApiErrorMessages.ERROR_DEPENDENCY_CYCLE, Arrays.asList(c, d,
            e)), ex.getMessage());
  }
  SliderFileSystem sfs = ServiceTestUtils.initMockFs();
  Service service = createValidApplication(null);
  service.setComponents(Arrays.asList(c, d, e));
  try {
    ServiceApiUtil.validateAndResolveService(service, sfs,
        CONF_DEFAULT_DNS);
    Assert.fail(EXCEPTION_PREFIX + "components with bad dependencies");
  } catch (IllegalArgumentException ex) {
    assertEquals(String.format(
        RestApiErrorMessages.ERROR_DEPENDENCY_INVALID, "b", "e"), ex
        .getMessage());
  }
}