Search in sources :

Example 1 with ConfigFileFormat

use of com.ctrip.framework.apollo.core.enums.ConfigFileFormat in project apollo by ctripcorp.

the class DefaultConfigManagerTest method testGetConfigFileMultipleTimesWithSameNamespace.

@Test
public void testGetConfigFileMultipleTimesWithSameNamespace() throws Exception {
    String someNamespace = "someName";
    ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties;
    ConfigFile someConfigFile = defaultConfigManager.getConfigFile(someNamespace, someConfigFileFormat);
    ConfigFile anotherConfigFile = defaultConfigManager.getConfigFile(someNamespace, someConfigFileFormat);
    assertThat("Get config file multiple times with the same namespace should return the same config file instance", someConfigFile, equalTo(anotherConfigFile));
}
Also used : ConfigFileFormat(com.ctrip.framework.apollo.core.enums.ConfigFileFormat) ConfigFile(com.ctrip.framework.apollo.ConfigFile) Test(org.junit.Test)

Example 2 with ConfigFileFormat

use of com.ctrip.framework.apollo.core.enums.ConfigFileFormat in project apollo by ctripcorp.

the class ConfigServiceTest method testMockConfigFactoryForConfigFile.

@Test
public void testMockConfigFactoryForConfigFile() throws Exception {
    String someNamespace = "mock";
    ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties;
    String someNamespaceFileName = String.format("%s.%s", someNamespace, someConfigFileFormat.getValue());
    MockInjector.setInstance(ConfigFactory.class, someNamespaceFileName, new MockConfigFactory());
    ConfigFile configFile = ConfigService.getConfigFile(someNamespace, someConfigFileFormat);
    assertEquals(someNamespaceFileName, configFile.getNamespace());
    assertEquals(someNamespaceFileName + ":" + someConfigFileFormat.getValue(), configFile.getContent());
}
Also used : ConfigFileFormat(com.ctrip.framework.apollo.core.enums.ConfigFileFormat) Test(org.junit.Test)

Example 3 with ConfigFileFormat

use of com.ctrip.framework.apollo.core.enums.ConfigFileFormat 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)

Example 4 with ConfigFileFormat

use of com.ctrip.framework.apollo.core.enums.ConfigFileFormat in project apollo by ctripcorp.

the class DefaultConfigManagerTest method testGetConfigFile.

@Test
public void testGetConfigFile() throws Exception {
    String someNamespace = "someName";
    ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties;
    ConfigFile configFile = defaultConfigManager.getConfigFile(someNamespace, someConfigFileFormat);
    assertEquals(someConfigFileFormat, configFile.getConfigFileFormat());
    assertEquals(someConfigContent, configFile.getContent());
}
Also used : ConfigFileFormat(com.ctrip.framework.apollo.core.enums.ConfigFileFormat) ConfigFile(com.ctrip.framework.apollo.ConfigFile) Test(org.junit.Test)

Example 5 with ConfigFileFormat

use of com.ctrip.framework.apollo.core.enums.ConfigFileFormat 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)

Aggregations

ConfigFileFormat (com.ctrip.framework.apollo.core.enums.ConfigFileFormat)6 Test (org.junit.Test)4 ConfigFile (com.ctrip.framework.apollo.ConfigFile)2 PropertiesCompatibleFileConfigRepository (com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository)2 Config (com.ctrip.framework.apollo.Config)1 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)1 ConfigRepository (com.ctrip.framework.apollo.internals.ConfigRepository)1 DefaultConfig (com.ctrip.framework.apollo.internals.DefaultConfig)1 LocalFileConfigRepository (com.ctrip.framework.apollo.internals.LocalFileConfigRepository)1 RemoteConfigRepository (com.ctrip.framework.apollo.internals.RemoteConfigRepository)1 Properties (java.util.Properties)1