@Test
public void testRoleHostMapping() throws Exception {

  AgentProviderService aps = createAgentProviderService(new Configuration());
  StateAccessForProviders appState = new ProviderAppState("undefined", null) {
    @Override
    public ClusterDescription getClusterStatus() {
      ClusterDescription cd = new ClusterDescription();
      cd.status = new HashMap<String, Object>();
      cd.status.put(ClusterDescriptionKeys.KEY_CLUSTER_LIVE, buildRoleMap());
      return cd;
    }
    @Override
    public Map<String, Map<String, ClusterNode>> getRoleClusterNodeMapping() {
      return buildRoleMap();
    }
    public Map<String, Map<String, ClusterNode>> buildRoleMap() {
      Map<String, Map<String, ClusterNode>> roleMap = new HashMap<String, Map<String, ClusterNode>>();
      ClusterNode cn1 = new ClusterNode(new MockContainerId(1));
      cn1.host = "FIRST_HOST";
      Map<String, ClusterNode> map1 = new HashMap<String, ClusterNode>();
      map1.put("FIRST_CONTAINER", cn1);
      ClusterNode cn2 = new ClusterNode(new MockContainerId(2));
      cn2.host = "SECOND_HOST";
      Map<String, ClusterNode> map2 = new HashMap<String, ClusterNode>();
      map2.put("SECOND_CONTAINER", cn2);
      ClusterNode cn3 = new ClusterNode(new MockContainerId(3));
      cn3.host = "THIRD_HOST";
      map2.put("THIRD_CONTAINER", cn3);
      roleMap.put("FIRST_ROLE", map1);
      roleMap.put("SECOND_ROLE", map2);
      return roleMap;
    }
    @Override
    public boolean isApplicationLive() {
      return true;
    }
    @Override
    public ClusterDescription refreshClusterStatus() {
      // do nothing
      return null;
    }
  };
  aps.setAmState(appState);
  Map<String, String> tokens = new HashMap<String, String>();
  aps.addRoleRelatedTokens(tokens);
  Assert.assertEquals(2, tokens.size());
  Assert.assertEquals("FIRST_HOST", tokens.get("${FIRST_ROLE_HOST}"));
  Assert.assertEquals("THIRD_HOST,SECOND_HOST", tokens.get("${SECOND_ROLE_HOST}"));
  aps.close();
}