@Test
public void testFinalizeResult() throws Exception{

  Result result = new ResultImpl(true);
  createClusterResultTree(result.getResultTree());
  ClusterBlueprintRenderer renderer = new TestBlueprintRenderer(topology);
  Result blueprintResult = renderer.finalizeResult(result);
  TreeNode<Resource> blueprintTree = blueprintResult.getResultTree();
  assertNull(blueprintTree.getStringProperty("isCollection"));
  assertEquals(1, blueprintTree.getChildren().size());
  TreeNode<Resource> blueprintNode = blueprintTree.getChildren().iterator().next();
  assertEquals(0, blueprintNode.getChildren().size());
  Resource blueprintResource = blueprintNode.getObject();
  Map<String, Map<String, Object>> properties = blueprintResource.getPropertiesMap();
  assertEquals("HDP", properties.get("Blueprints").get("stack_name"));
  assertEquals("1.3.3", properties.get("Blueprints").get("stack_version"));
  Collection<Map<String, Object>> host_groups = (Collection<Map<String, Object>>) properties.get("").get("host_groups");
  assertEquals(2, host_groups.size());
  for (Map<String, Object> hostGroupProperties : host_groups) {
    String host_group_name = (String) hostGroupProperties.get("name");
    if (host_group_name.equals("host_group_1")) {
      assertEquals("1", hostGroupProperties.get("cardinality"));
      Collection<Map<String, String>> components = (Collection<Map<String, String>>) hostGroupProperties.get("components");
      // 4 specified components and ambari server
      assertEquals(5, components.size());
      Set<String> expectedValues = new HashSet<String>(
          Arrays.asList("JOBTRACKER", "TASKTRACKER", "NAMENODE", "DATANODE", "AMBARI_SERVER"));
      Set<String> actualValues = new HashSet<String>();
      for (Map<String, String> componentProperties : components) {
        assertEquals(1, componentProperties.size());
        actualValues.add(componentProperties.get("name"));
      }
      assertEquals(expectedValues, actualValues);
    } else if (host_group_name.equals("host_group_2")) {
      // cardinality is 2 because 2 hosts share same topology
      assertEquals("2", hostGroupProperties.get("cardinality"));
      Collection<Map<String, String>> components = (Collection<Map<String, String>>) hostGroupProperties.get("components");
      assertEquals(2, components.size());
      Set<String> expectedValues = new HashSet<String>(
          Arrays.asList("TASKTRACKER", "DATANODE"));
      Set<String> actualValues = new HashSet<String>();
      for (Map<String, String> componentProperties : components) {
        assertEquals(1, componentProperties.size());
        actualValues.add(componentProperties.get("name"));
      }
      assertEquals(expectedValues, actualValues);
    }
  }
}