use of com.ctrip.framework.apollo.internals.YamlConfigFile 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());
}
use of com.ctrip.framework.apollo.internals.YamlConfigFile in project apollo by ctripcorp.
the class JavaConfigAnnotationTest method testApolloConfigChangeListenerResolveExpressionFromSelfYaml.
@Test
public void testApolloConfigChangeListenerResolveExpressionFromSelfYaml() throws IOException {
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, mock(Config.class));
final String resolvedValue = "resolve.from.self.yml";
YamlConfigFile yamlConfigFile = prepareYamlConfigFile(resolvedValue, readYamlContentAsConfigFileProperties(resolvedValue));
getSimpleBean(TestApolloConfigChangeListenerResolveExpressionFromSelfYamlConfiguration.class);
verify(yamlConfigFile, times(1)).addChangeListener(any(ConfigFileChangeListener.class));
}
use of com.ctrip.framework.apollo.internals.YamlConfigFile in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithTypeMismatchWithYamlFile.
@Test
public void testAutoUpdateWithTypeMismatchWithYamlFile() throws Exception {
int initialTimeout = 1000;
int initialBatch = 2000;
int newTimeout = 1001;
YamlConfigFile configFile = prepareYamlConfigFile("application.yaml", readYamlContentAsConfigFileProperties("case5.yaml"));
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig12.class);
TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
assertEquals(initialTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
configFile.onRepositoryChange("application.yaml", readYamlContentAsConfigFileProperties("case5-new.yaml"));
TimeUnit.MILLISECONDS.sleep(300);
assertEquals(newTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
}
use of com.ctrip.framework.apollo.internals.YamlConfigFile in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithOneYamlFile.
@Test
public void testAutoUpdateWithOneYamlFile() throws Exception {
int initialTimeout = 1000;
int initialBatch = 2000;
int newTimeout = 1001;
int newBatch = 2001;
YamlConfigFile configFile = prepareYamlConfigFile("application.yaml", readYamlContentAsConfigFileProperties("case1.yaml"));
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig12.class);
TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
assertEquals(initialTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
configFile.onRepositoryChange("application.yaml", readYamlContentAsConfigFileProperties("case1-new.yaml"));
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(newTimeout, bean.getTimeout());
assertEquals(newBatch, bean.getBatch());
}
use of com.ctrip.framework.apollo.internals.YamlConfigFile in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithNewPropertiesWithYamlFile.
@Test
public void testAutoUpdateWithNewPropertiesWithYamlFile() throws Exception {
int initialTimeout = 1000;
int newTimeout = 1001;
int newBatch = 2001;
YamlConfigFile configFile = prepareYamlConfigFile("application.yaml", readYamlContentAsConfigFileProperties("case3.yaml"));
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig12.class);
TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
assertEquals(initialTimeout, bean.getTimeout());
assertEquals(DEFAULT_BATCH, bean.getBatch());
configFile.onRepositoryChange("application.yaml", readYamlContentAsConfigFileProperties("case3-new.yaml"));
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(newTimeout, bean.getTimeout());
assertEquals(newBatch, bean.getBatch());
}
Aggregations