Search in sources :

Example 1 with DefaultConfig

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

the class DefaultConfigFactoryTest method testCreate.

@Test
public void testCreate() throws Exception {
    String someNamespace = "someName";
    Properties someProperties = new Properties();
    String someKey = "someKey";
    String someValue = "someValue";
    someProperties.setProperty(someKey, someValue);
    LocalFileConfigRepository someLocalConfigRepo = mock(LocalFileConfigRepository.class);
    when(someLocalConfigRepo.getConfig()).thenReturn(someProperties);
    doReturn(someLocalConfigRepo).when(defaultConfigFactory).createConfigRepository(someNamespace);
    Config result = defaultConfigFactory.create(someNamespace);
    assertThat("DefaultConfigFactory should create DefaultConfig", result, is(instanceOf(DefaultConfig.class)));
    assertEquals(someValue, result.getProperty(someKey, null));
}
Also used : LocalFileConfigRepository(com.ctrip.framework.apollo.internals.LocalFileConfigRepository) DefaultConfig(com.ctrip.framework.apollo.internals.DefaultConfig) Config(com.ctrip.framework.apollo.Config) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with DefaultConfig

use of com.ctrip.framework.apollo.internals.DefaultConfig 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

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