@Test
public void testAddDependencies() throws IOException {

  RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
  InputStream testJsonIS = getClass().getClassLoader().
          getResourceAsStream(TEST_RCO_DATA_FILE);
  ObjectMapper mapper = new ObjectMapper();
  Map<String,Object> testData = mapper.readValue(testJsonIS,
      new TypeReference<Map<String,Object>>() {});
  rco.addDependencies(testData);
  mapper.setVisibility(JsonMethod.ALL, JsonAutoDetect.Visibility.ANY);
  String dump = mapper.writeValueAsString(rco.getDependencies());
  // Depends on hashing, string representation can be different
  // We need a sophisticated comparison
  List<String> parts = Arrays.asList(dump.substring(1, 522).split(Pattern.quote("],")));
  assertEquals(3, parts.size());
  assertTrue(parts.contains("\"RoleCommandPair{role=SECONDARY_NAMENODE, cmd=UPGRADE}\":[{\"role\":{\"name\":\"NAMENODE\"},\"cmd\":\"UPGRADE\"}"));
  assertTrue(parts.contains("\"RoleCommandPair{role=SECONDARY_NAMENODE, cmd=START}\":[{\"role\":{\"name\":\"NAMENODE\"},\"cmd\":\"START\"}"));
  boolean datanodeCommandExists = false;
  for (String part : parts) {
    if (part.contains("RoleCommandPair{role=DATANODE, cmd=STOP}")) {
      datanodeCommandExists = true;
      String[] parts2 = part.split(Pattern.quote(":["));
      assertEquals(2, parts2.length);
      assertEquals("\"RoleCommandPair{role=DATANODE, cmd=STOP}\"", parts2[0]);
      List<String> components = Arrays.asList(new String[]{"\"role\":{\"name\":\"HBASE_MASTER\"},\"cmd\":\"STOP\"",
                                                           "\"role\":{\"name\":\"RESOURCEMANAGER\"},\"cmd\":\"STOP\"",
                                                           "\"role\":{\"name\":\"TASKTRACKER\"},\"cmd\":\"STOP\"",
                                                           "\"role\":{\"name\":\"NODEMANAGER\"},\"cmd\":\"STOP\"",
                                                           "\"role\":{\"name\":\"HISTORYSERVER\"},\"cmd\":\"STOP\"",
                                                           "\"role\":{\"name\":\"JOBTRACKER\"},\"cmd\":\"STOP\""});
      Assert.assertTrue(CollectionPresentationUtils.isStringPermutationOfCollection(parts2[1], components, "},{", 1, 1));
    }
  }
  assertTrue(datanodeCommandExists);
}