Search in sources :

Example 1 with LocalFileConfigRepository

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

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

the class DefaultConfigFactoryTest method testCreateConfigFile.

@Test
public void testCreateConfigFile() throws Exception {
    String someNamespace = "someName";
    String anotherNamespace = "anotherName";
    String yetAnotherNamespace = "yetAnotherNamespace";
    Properties someProperties = new Properties();
    LocalFileConfigRepository someLocalConfigRepo = mock(LocalFileConfigRepository.class);
    when(someLocalConfigRepo.getConfig()).thenReturn(someProperties);
    doReturn(someLocalConfigRepo).when(defaultConfigFactory).createLocalConfigRepository(someNamespace);
    doReturn(someLocalConfigRepo).when(defaultConfigFactory).createLocalConfigRepository(anotherNamespace);
    doReturn(someLocalConfigRepo).when(defaultConfigFactory).createLocalConfigRepository(yetAnotherNamespace);
    ConfigFile propertyConfigFile = defaultConfigFactory.createConfigFile(someNamespace, ConfigFileFormat.Properties);
    ConfigFile xmlConfigFile = defaultConfigFactory.createConfigFile(anotherNamespace, ConfigFileFormat.XML);
    ConfigFile jsonConfigFile = defaultConfigFactory.createConfigFile(yetAnotherNamespace, ConfigFileFormat.JSON);
    ConfigFile ymlConfigFile = defaultConfigFactory.createConfigFile(someNamespace, ConfigFileFormat.YML);
    ConfigFile yamlConfigFile = defaultConfigFactory.createConfigFile(someNamespace, ConfigFileFormat.YAML);
    assertThat("Should create PropertiesConfigFile for properties format", propertyConfigFile, is(instanceOf(PropertiesConfigFile.class)));
    assertEquals(someNamespace, propertyConfigFile.getNamespace());
    assertThat("Should create XmlConfigFile for xml format", xmlConfigFile, is(instanceOf(XmlConfigFile.class)));
    assertEquals(anotherNamespace, xmlConfigFile.getNamespace());
    assertThat("Should create JsonConfigFile for json format", jsonConfigFile, is(instanceOf(JsonConfigFile.class)));
    assertEquals(yetAnotherNamespace, jsonConfigFile.getNamespace());
    assertThat("Should create YmlConfigFile for yml format", ymlConfigFile, is(instanceOf(YmlConfigFile.class)));
    assertEquals(someNamespace, ymlConfigFile.getNamespace());
    assertThat("Should create YamlConfigFile for yaml format", yamlConfigFile, is(instanceOf(YamlConfigFile.class)));
    assertEquals(someNamespace, yamlConfigFile.getNamespace());
}
Also used : LocalFileConfigRepository(com.ctrip.framework.apollo.internals.LocalFileConfigRepository) XmlConfigFile(com.ctrip.framework.apollo.internals.XmlConfigFile) YmlConfigFile(com.ctrip.framework.apollo.internals.YmlConfigFile) YamlConfigFile(com.ctrip.framework.apollo.internals.YamlConfigFile) JsonConfigFile(com.ctrip.framework.apollo.internals.JsonConfigFile) PropertiesConfigFile(com.ctrip.framework.apollo.internals.PropertiesConfigFile) ConfigFile(com.ctrip.framework.apollo.ConfigFile) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with LocalFileConfigRepository

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

the class DefaultConfigFactoryFileCachePropertyTest method testCreateFileEnableConfigRepository.

@Test
public void testCreateFileEnableConfigRepository() throws Exception {
    LocalFileConfigRepository someLocalConfigRepository = mock(LocalFileConfigRepository.class);
    when(someConfigUtil.isPropertyFileCacheEnabled()).thenReturn(true);
    doReturn(someLocalConfigRepository).when(configFactory).createLocalConfigRepository(someNamespace);
    ConfigRepository configRepository = configFactory.createConfigRepository(someNamespace);
    assertSame(someLocalConfigRepository, configRepository);
    verify(configFactory, times(1)).createLocalConfigRepository(someNamespace);
    verify(configFactory, never()).createRemoteConfigRepository(someNamespace);
}
Also used : LocalFileConfigRepository(com.ctrip.framework.apollo.internals.LocalFileConfigRepository) RemoteConfigRepository(com.ctrip.framework.apollo.internals.RemoteConfigRepository) LocalFileConfigRepository(com.ctrip.framework.apollo.internals.LocalFileConfigRepository) ConfigRepository(com.ctrip.framework.apollo.internals.ConfigRepository) Test(org.junit.Test)

Example 4 with LocalFileConfigRepository

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

the class DefaultConfigFactoryTest method testCreateLocalConfigRepositoryInLocalDev.

@Test
public void testCreateLocalConfigRepositoryInLocalDev() throws Exception {
    String someNamespace = "someName";
    someEnv = Env.LOCAL;
    LocalFileConfigRepository localFileConfigRepository = defaultConfigFactory.createLocalConfigRepository(someNamespace);
    assertNull(ReflectionTestUtils.getField(localFileConfigRepository, "m_upstream"));
}
Also used : LocalFileConfigRepository(com.ctrip.framework.apollo.internals.LocalFileConfigRepository) Test(org.junit.Test)

Aggregations

LocalFileConfigRepository (com.ctrip.framework.apollo.internals.LocalFileConfigRepository)4 Test (org.junit.Test)4 Properties (java.util.Properties)2 Config (com.ctrip.framework.apollo.Config)1 ConfigFile (com.ctrip.framework.apollo.ConfigFile)1 ConfigRepository (com.ctrip.framework.apollo.internals.ConfigRepository)1 DefaultConfig (com.ctrip.framework.apollo.internals.DefaultConfig)1 JsonConfigFile (com.ctrip.framework.apollo.internals.JsonConfigFile)1 PropertiesConfigFile (com.ctrip.framework.apollo.internals.PropertiesConfigFile)1 RemoteConfigRepository (com.ctrip.framework.apollo.internals.RemoteConfigRepository)1 XmlConfigFile (com.ctrip.framework.apollo.internals.XmlConfigFile)1 YamlConfigFile (com.ctrip.framework.apollo.internals.YamlConfigFile)1 YmlConfigFile (com.ctrip.framework.apollo.internals.YmlConfigFile)1