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));
}
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());
}
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));
}
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());
}
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);
}
Aggregations