@Test
public void testPopulateSettingList() throws Exception {

  StackEntity stackEntity = new StackEntity();
  stackEntity.setStackName("test-stack-name");
  stackEntity.setStackVersion("test-stack-version");
  BlueprintEntity entity = createMock(BlueprintEntity.class);
  expect(entity.getStack()).andReturn(stackEntity).anyTimes();
  HashMap<PropertyInfo.PropertyType, Set<String>> pwdProperties = new HashMap<PropertyInfo.PropertyType, Set<String>>() {{
    put(PropertyInfo.PropertyType.PASSWORD, new HashSet<String>(){{
      add("test.password");
    }});
  }};
  StackInfo info = createMock(StackInfo.class);
  expect(info.getConfigPropertiesTypes("type1")).andReturn(new HashMap<PropertyInfo.PropertyType, Set<String>>()).anyTimes();
  expect(info.getConfigPropertiesTypes("type2")).andReturn(new HashMap<PropertyInfo.PropertyType, Set<String>>()).anyTimes();
  expect(info.getConfigPropertiesTypes("type3")).andReturn(pwdProperties).anyTimes();
  expect(metaInfo.getStack("test-stack-name", "test-stack-version")).andReturn(info).anyTimes();
  replay(info, metaInfo, entity);
  // Blueprint setting entities
  // Global recovery setting
  BlueprintSettingEntity settingEntity1 = new BlueprintSettingEntity();
  settingEntity1.setSettingName("recovery_settings");
  settingEntity1.setSettingData("[{\"recovery_enabled\":\"true\"}]");
  settingEntity1.setBlueprintEntity(entity);
  // Service exceptions setting
  BlueprintSettingEntity settingEntity2 = new BlueprintSettingEntity();
  settingEntity2.setSettingName("service_settings");
  settingEntity2.setSettingData("[{\"name\":\"HDFS\", \"recovery_enabled\":\"false\"}, " +
          "{\"name\":\"ZOOKEEPER\", \"recovery_enabled\":\"false\"}]");
  settingEntity2.setBlueprintEntity(entity);
  // Service component exceptions setting
  BlueprintSettingEntity settingEntity3 = new BlueprintSettingEntity();
  settingEntity3.setSettingName("component_settings");
  settingEntity3.setSettingData("[{\"name\":\"METRICS_MONITOR\", \"recovery_enabled\":\"false\"}," +
          "{\"name\":\"KAFKA_CLIENT\", \"recovery_enabled\":\"false\"}]");
  settingEntity3.setBlueprintEntity(entity);
  List<BlueprintSettingEntity> settingEntities = new ArrayList();
  settingEntities.add(settingEntity1);
  settingEntities.add(settingEntity2);
  settingEntities.add(settingEntity3);
  List<Map<String, Object>> settings = provider.populateSettingList(settingEntities);
  assertNotNull(settings);
  assertEquals(settingEntities.size(), settings.size());
  // Verify global recovery setting
  Map<String, Object> setting1 = settings.get(0);
  assertNotNull(setting1);
  assertEquals(1, setting1.size());
  assertTrue(setting1.containsKey("recovery_settings"));
  List<Map<String, String>> setting1value = (List<Map<String, String>>) setting1.get("recovery_settings");
  assertNotNull(setting1value);
  assertEquals(1, setting1value.size());
  assertTrue(setting1value.get(0).containsKey("recovery_enabled"));
  assertEquals(setting1value.get(0).get("recovery_enabled"), "true");
  // Verify service exceptions
  Map<String, Object> setting2 = settings.get(1);
  assertNotNull(setting2);
  assertEquals(1, setting2.size());
  assertTrue(setting2.containsKey("service_settings"));
  List<Map<String, String>> setting2value = (List<Map<String, String>>) setting2.get("service_settings");
  assertNotNull(setting2value);
  assertEquals(2, setting2value.size());
  // first service exception is HDFS
  assertTrue(setting2value.get(0).containsKey("name"));
  assertEquals(setting2value.get(0).get("name"), "HDFS");
  assertTrue(setting2value.get(0).containsKey("recovery_enabled"));
  assertEquals(setting2value.get(0).get("recovery_enabled"), "false");
  // second service exception is ZOOKEEPER
  assertTrue(setting2value.get(1).containsKey("name"));
  assertEquals(setting2value.get(1).get("name"), "ZOOKEEPER");
  assertTrue(setting2value.get(1).containsKey("recovery_enabled"));
  assertEquals(setting2value.get(1).get("recovery_enabled"), "false");
  // Verify service component exceptions
  Map<String, Object> setting3 = settings.get(2);
  assertNotNull(setting3);
  assertEquals(1, setting3.size());
  assertTrue(setting3.containsKey("component_settings"));
  List<Map<String, String>> setting3value = (List<Map<String, String>>) setting3.get("component_settings");
  assertNotNull(setting3value);
  assertEquals(2, setting3value.size());
  // first service component exception is METRICS_MONITOR
  assertTrue(setting3value.get(0).containsKey("name"));
  assertEquals(setting3value.get(0).get("name"), "METRICS_MONITOR");
  assertTrue(setting3value.get(0).containsKey("recovery_enabled"));
  assertEquals(setting3value.get(0).get("recovery_enabled"), "false");
  // second service component exception is KAFKA_CLIENT
  assertTrue(setting3value.get(1).containsKey("name"));
  assertEquals(setting3value.get(1).get("name"), "KAFKA_CLIENT");
  assertTrue(setting3value.get(1).containsKey("recovery_enabled"));
  assertEquals(setting3value.get(1).get("recovery_enabled"), "false");
}