Search in sources :

Example 1 with PropertiesCompatibleFileConfigRepository

use of com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository in project apollo by ctripcorp.

the class DefaultConfigFactory method createPropertiesCompatibleFileConfigRepository.

PropertiesCompatibleFileConfigRepository createPropertiesCompatibleFileConfigRepository(String namespace, ConfigFileFormat format) {
    String actualNamespaceName = trimNamespaceFormat(namespace, format);
    PropertiesCompatibleConfigFile configFile = (PropertiesCompatibleConfigFile) ConfigService.getConfigFile(actualNamespaceName, format);
    return new PropertiesCompatibleFileConfigRepository(configFile);
}
Also used : PropertiesCompatibleFileConfigRepository(com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository) PropertiesCompatibleConfigFile(com.ctrip.framework.apollo.PropertiesCompatibleConfigFile)

Example 2 with PropertiesCompatibleFileConfigRepository

use of com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository in project apollo by ctripcorp.

the class DefaultConfigFactoryTest method testCreatePropertiesCompatibleFileConfigRepository.

@Test
public void testCreatePropertiesCompatibleFileConfigRepository() throws Exception {
    ConfigFileFormat somePropertiesCompatibleFormat = ConfigFileFormat.YML;
    String someNamespace = "someName" + "." + somePropertiesCompatibleFormat;
    Properties someProperties = new Properties();
    String someKey = "someKey";
    String someValue = "someValue";
    someProperties.setProperty(someKey, someValue);
    PropertiesCompatibleFileConfigRepository someRepository = mock(PropertiesCompatibleFileConfigRepository.class);
    when(someRepository.getConfig()).thenReturn(someProperties);
    doReturn(someRepository).when(defaultConfigFactory).createPropertiesCompatibleFileConfigRepository(someNamespace, somePropertiesCompatibleFormat);
    Config result = defaultConfigFactory.create(someNamespace);
    assertThat("DefaultConfigFactory should create DefaultConfig", result, is(instanceOf(DefaultConfig.class)));
    assertEquals(someValue, result.getProperty(someKey, null));
}
Also used : ConfigFileFormat(com.ctrip.framework.apollo.core.enums.ConfigFileFormat) DefaultConfig(com.ctrip.framework.apollo.internals.DefaultConfig) Config(com.ctrip.framework.apollo.Config) Properties(java.util.Properties) PropertiesCompatibleFileConfigRepository(com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository) Test(org.junit.Test)

Aggregations

PropertiesCompatibleFileConfigRepository (com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository)2 Config (com.ctrip.framework.apollo.Config)1 PropertiesCompatibleConfigFile (com.ctrip.framework.apollo.PropertiesCompatibleConfigFile)1 ConfigFileFormat (com.ctrip.framework.apollo.core.enums.ConfigFileFormat)1 DefaultConfig (com.ctrip.framework.apollo.internals.DefaultConfig)1 Properties (java.util.Properties)1 Test (org.junit.Test)1