use of com.ctrip.framework.apollo.util.yaml.YamlParser in project apollo by ctripcorp.
the class YamlConfigFileTest method testWhenHasContentWithOrder.
@Test
public void testWhenHasContentWithOrder() throws Exception {
when(propertiesFactory.getPropertiesInstance()).thenAnswer(new Answer<Properties>() {
@Override
public Properties answer(InvocationOnMock invocation) {
return new OrderedProperties();
}
});
Properties someProperties = new Properties();
String key = ConfigConsts.CONFIG_FILE_CONTENT_KEY;
String someContent = "someKey: 'someValue'\nsomeKey2: 'someValue2'";
someProperties.setProperty(key, someContent);
someSourceType = ConfigSourceType.LOCAL;
Properties yamlProperties = new YamlParser().yamlToProperties(someContent);
when(configRepository.getConfig()).thenReturn(someProperties);
when(configRepository.getSourceType()).thenReturn(someSourceType);
when(yamlParser.yamlToProperties(someContent)).thenReturn(yamlProperties);
YamlConfigFile configFile = new YamlConfigFile(someNamespace, configRepository);
assertSame(someContent, configFile.getContent());
assertSame(yamlProperties, configFile.asProperties());
String[] actualArrays = configFile.asProperties().keySet().toArray(new String[] {});
String[] expectedArrays = { "someKey", "someKey2" };
assertArrayEquals(expectedArrays, actualArrays);
}
Aggregations