final List<String> testListValue = ImmutableList.of("testValue");
final Map<String, String> testMapValue = ImmutableMap.of("testInnerKey", "testValue");
// first, add Helix configuration to an InstanceConfig
ParticipantId participantId = ParticipantId.from("testParticipant");
InstanceConfig instanceConfig = new InstanceConfig(participantId);
instanceConfig.setHostName("localhost");
// now, add user configuration
UserConfig userConfig = new UserConfig(Scope.participant(participantId));
userConfig.setSimpleField(testKey, testSimpleValue);
userConfig.setListField(testKey, testListValue);
userConfig.setMapField(testKey, testMapValue);
// add the user configuration to the Helix configuration
instanceConfig.addNamespacedConfig(userConfig);
// get the user configuration back from the property
UserConfig retrievedConfig = UserConfig.from(instanceConfig);
// check that the property still has the host name
Assert.assertTrue(instanceConfig.getHostName().equals("localhost"));
// check that the retrieved config does not contain the host name
Assert.assertEquals(retrievedConfig.getStringField(
InstanceConfigProperty.HELIX_HOST.toString(), "not localhost"), "not localhost");
// check that both the retrieved config and the original config have the added properties
Assert.assertEquals(userConfig.getSimpleField(testKey), testSimpleValue);
Assert.assertEquals(userConfig.getListField(testKey), testListValue);
Assert.assertEquals(userConfig.getMapField(testKey), testMapValue);
Assert.assertEquals(retrievedConfig.getSimpleField(testKey), testSimpleValue);
Assert.assertEquals(retrievedConfig.getListField(testKey), testListValue);
Assert.assertEquals(retrievedConfig.getMapField(testKey), testMapValue);
// test that the property has the user config, but prefixed
Assert.assertEquals(instanceConfig.getRecord().getSimpleField(prefixedKey), testSimpleValue);
Assert.assertEquals(instanceConfig.getRecord().getListField(prefixedKey), testListValue);
Assert.assertEquals(instanceConfig.getRecord().getMapField(prefixedKey), testMapValue);
}