@Test
public void testPopulateConfigurationList() 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);
  // attributes is null
  BlueprintConfigEntity config1 = new BlueprintConfigEntity();
  config1.setType("type1");
  config1.setConfigData("{\"key1\":\"value1\"}");
  config1.setBlueprintEntity(entity);
  // attributes is empty
  BlueprintConfigEntity config2 = new BlueprintConfigEntity();
  config2.setType("type2");
  config2.setConfigData("{\"key2\":\"value2\"}");
  config2.setConfigAttributes("{}");
  config2.setBlueprintEntity(entity);
  // attributes is provided
  BlueprintConfigEntity config3 = new BlueprintConfigEntity();
  config3.setType("type3");
  config3.setConfigData("{\"key3\":\"value3\",\"key4\":\"value4\",\"test.password\":\"pwdValue\"}");
  config3.setConfigAttributes("{\"final\":{\"key3\":\"attrValue1\",\"key4\":\"attrValue2\"}}");
  config3.setBlueprintEntity(entity);
  List<Map<String, Map<String, Object>>> configs =
      provider.populateConfigurationList(Arrays.asList(config1, config2, config3));
  assertNotNull(configs);
  assertEquals(3, configs.size());
  Map<String, Map<String, Object>> configuration1 = configs.get(0);
  assertNotNull(configuration1);
  assertEquals(1, configuration1.size());
  assertTrue(configuration1.containsKey("type1"));
  Map<String, Object> typeConfig1 = configuration1.get("type1");
  assertNotNull(typeConfig1);
  assertEquals(1, typeConfig1.size());
  assertTrue(typeConfig1.containsKey(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID));
  Map<String, String> confProperties1
      = (Map<String, String>) typeConfig1.get(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID);
  assertNotNull(confProperties1);
  assertEquals(1, confProperties1.size());
  assertEquals("value1", confProperties1.get("key1"));
  Map<String, Map<String, Object>> configuration2 = configs.get(1);
  assertNotNull(configuration2);
  assertEquals(1, configuration2.size());
  assertTrue(configuration2.containsKey("type2"));
  Map<String, Object> typeConfig2 = configuration2.get("type2");
  assertNotNull(typeConfig2);
  assertEquals(1, typeConfig2.size());
  assertTrue(typeConfig2.containsKey(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID));
  Map<String, String> confProperties2
      = (Map<String, String>) typeConfig2.get(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID);
  assertNotNull(confProperties2);
  assertEquals(1, confProperties2.size());
  assertEquals("value2", confProperties2.get("key2"));
  Map<String, Map<String, Object>> configuration3 = configs.get(2);
  assertNotNull(configuration3);
  assertEquals(1, configuration3.size());
  assertTrue(configuration3.containsKey("type3"));
  Map<String, Object> typeConfig3 = configuration3.get("type3");
  assertNotNull(typeConfig3);
  assertEquals(2, typeConfig3.size());
  assertTrue(typeConfig3.containsKey(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID));
  Map<String, String> confProperties3
      = (Map<String, String>) typeConfig3.get(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID);
  assertNotNull(confProperties3);
  assertEquals(3, confProperties3.size());
  assertEquals("value3", confProperties3.get("key3"));
  assertEquals("value4", confProperties3.get("key4"));
  assertEquals("SECRET:type3:-1:test.password", confProperties3.get("test.password"));
  assertTrue(typeConfig3.containsKey(BlueprintResourceProvider.PROPERTIES_ATTRIBUTES_PROPERTY_ID));
  Map<String, Map<String, String>> confAttributes3
      = (Map<String, Map<String, String>>) typeConfig3.get(BlueprintResourceProvider.PROPERTIES_ATTRIBUTES_PROPERTY_ID);
  assertNotNull(confAttributes3);
  assertEquals(1, confAttributes3.size());
  assertTrue(confAttributes3.containsKey("final"));
  Map<String, String> finalAttrs = confAttributes3.get("final");
  assertEquals(2, finalAttrs.size());
  assertEquals("attrValue1", finalAttrs.get("key3"));
  assertEquals("attrValue2", finalAttrs.get("key4"));
}