Search in sources :

Example 1 with ConfigRepository

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

the class DefaultConfigFactoryFileCachePropertyTest method testCreateFileDisableConfigRepository.

@Test
public void testCreateFileDisableConfigRepository() throws Exception {
    RemoteConfigRepository someRemoteConfigRepository = mock(RemoteConfigRepository.class);
    when(someConfigUtil.isPropertyFileCacheEnabled()).thenReturn(false);
    doReturn(someRemoteConfigRepository).when(configFactory).createRemoteConfigRepository(someNamespace);
    ConfigRepository configRepository = configFactory.createConfigRepository(someNamespace);
    assertSame(someRemoteConfigRepository, configRepository);
    verify(configFactory, never()).createLocalConfigRepository(someNamespace);
    verify(configFactory, times(1)).createRemoteConfigRepository(someNamespace);
}
Also used : RemoteConfigRepository(com.ctrip.framework.apollo.internals.RemoteConfigRepository) 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 2 with ConfigRepository

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

the class DefaultConfigFactory method create.

@Override
public Config create(String namespace) {
    ConfigFileFormat format = determineFileFormat(namespace);
    ConfigRepository configRepository = null;
    // for ConfigFileFormat.Properties
    if (ConfigFileFormat.isPropertiesCompatible(format) && format != ConfigFileFormat.Properties) {
        configRepository = createPropertiesCompatibleFileConfigRepository(namespace, format);
    } else {
        configRepository = createConfigRepository(namespace);
    }
    logger.debug("Created a configuration repository of type [{}] for namespace [{}]", configRepository.getClass().getName(), namespace);
    return this.createRepositoryConfig(namespace, configRepository);
}
Also used : ConfigFileFormat(com.ctrip.framework.apollo.core.enums.ConfigFileFormat) RemoteConfigRepository(com.ctrip.framework.apollo.internals.RemoteConfigRepository) LocalFileConfigRepository(com.ctrip.framework.apollo.internals.LocalFileConfigRepository) PropertiesCompatibleFileConfigRepository(com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository) ConfigRepository(com.ctrip.framework.apollo.internals.ConfigRepository)

Example 3 with ConfigRepository

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

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

the class AbstractSpringIntegrationTest method prepareConfig.

protected SimpleConfig prepareConfig(String namespaceName, Properties properties) {
    ConfigRepository configRepository = mock(ConfigRepository.class);
    when(configRepository.getConfig()).thenReturn(properties);
    SimpleConfig config = new SimpleConfig(ConfigConsts.NAMESPACE_APPLICATION, configRepository);
    mockConfig(namespaceName, config);
    return config;
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ConfigRepository(com.ctrip.framework.apollo.internals.ConfigRepository)

Example 5 with ConfigRepository

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

the class AbstractSpringIntegrationTest method prepareYamlConfigFile.

protected static YamlConfigFile prepareYamlConfigFile(String namespaceNameWithFormat, Properties properties) {
    ConfigRepository configRepository = mock(ConfigRepository.class);
    when(configRepository.getConfig()).thenReturn(properties);
    // spy it for testing after
    YamlConfigFile configFile = spy(new YamlConfigFile(namespaceNameWithFormat, configRepository));
    mockConfigFile(namespaceNameWithFormat, configFile);
    return configFile;
}
Also used : ConfigRepository(com.ctrip.framework.apollo.internals.ConfigRepository) YamlConfigFile(com.ctrip.framework.apollo.internals.YamlConfigFile)

Aggregations

ConfigRepository (com.ctrip.framework.apollo.internals.ConfigRepository)5 LocalFileConfigRepository (com.ctrip.framework.apollo.internals.LocalFileConfigRepository)3 RemoteConfigRepository (com.ctrip.framework.apollo.internals.RemoteConfigRepository)3 Test (org.junit.Test)2 ConfigFileFormat (com.ctrip.framework.apollo.core.enums.ConfigFileFormat)1 PropertiesCompatibleFileConfigRepository (com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository)1 SimpleConfig (com.ctrip.framework.apollo.internals.SimpleConfig)1 YamlConfigFile (com.ctrip.framework.apollo.internals.YamlConfigFile)1