Search in sources :

Example 1 with YamlParser

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);
}
Also used : YamlParser(com.ctrip.framework.apollo.util.yaml.YamlParser) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OrderedProperties(com.ctrip.framework.apollo.util.OrderedProperties) Properties(java.util.Properties) OrderedProperties(com.ctrip.framework.apollo.util.OrderedProperties) Test(org.junit.Test)

Aggregations

OrderedProperties (com.ctrip.framework.apollo.util.OrderedProperties)1 YamlParser (com.ctrip.framework.apollo.util.yaml.YamlParser)1 Properties (java.util.Properties)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1