use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class JavaConfigPlaceholderTest method testPropertySourceWithNoNamespace.
@Test
public void testPropertySourceWithNoNamespace() throws Exception {
int someTimeout = 1000;
int someBatch = 2000;
Config config = mock(Config.class);
when(config.getProperty(eq(TIMEOUT_PROPERTY), Mockito.nullable(String.class))).thenReturn(String.valueOf(someTimeout));
when(config.getProperty(eq(BATCH_PROPERTY), Mockito.nullable(String.class))).thenReturn(String.valueOf(someBatch));
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config);
check(someTimeout, someBatch, AppConfig1.class);
}
use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class JavaConfigPlaceholderTest method testNestedPropertyWithDefaultValue.
@Test
public void testNestedPropertyWithDefaultValue() throws Exception {
String a = "a";
String b = "b";
String c = "c";
int someValue = 1234;
Config config = mock(Config.class);
when(config.getProperty(eq(a), Mockito.nullable(String.class))).thenReturn(a);
when(config.getProperty(eq(b), Mockito.nullable(String.class))).thenReturn(b);
when(config.getProperty(eq(c), Mockito.nullable(String.class))).thenReturn(String.valueOf(someValue));
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NestedPropertyConfig1.class);
TestNestedPropertyBean bean = context.getBean(TestNestedPropertyBean.class);
assertEquals(someValue, bean.getNestedProperty());
}
use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class JavaConfigPlaceholderTest method testMultiplePropertySources.
@Test
public void testMultiplePropertySources() throws Exception {
int someTimeout = 1000;
int someBatch = 2000;
Config application = mock(Config.class);
when(application.getProperty(eq(TIMEOUT_PROPERTY), Mockito.nullable(String.class))).thenReturn(String.valueOf(someTimeout));
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application);
Config fxApollo = mock(Config.class);
when(application.getProperty(eq(BATCH_PROPERTY), Mockito.nullable(String.class))).thenReturn(String.valueOf(someBatch));
mockConfig(FX_APOLLO_NAMESPACE, fxApollo);
check(someTimeout, someBatch, AppConfig3.class);
}
use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class JavaConfigPlaceholderTest method testNestedPropertyWithNestedDefaultValue.
@Test
public void testNestedPropertyWithNestedDefaultValue() throws Exception {
String a = "a";
String b = "b";
Config config = mock(Config.class);
when(config.getProperty(eq(a), Mockito.nullable(String.class))).thenReturn(a);
when(config.getProperty(eq(b), Mockito.nullable(String.class))).thenReturn(b);
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NestedPropertyConfig1.class);
TestNestedPropertyBean bean = context.getBean(TestNestedPropertyBean.class);
assertEquals(100, bean.getNestedProperty());
}
use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class JavaConfigPlaceholderTest method testApplicationPropertySource.
@Test
public void testApplicationPropertySource() throws Exception {
int someTimeout = 1000;
int someBatch = 2000;
Config config = mock(Config.class);
when(config.getProperty(eq(TIMEOUT_PROPERTY), Mockito.nullable(String.class))).thenReturn(String.valueOf(someTimeout));
when(config.getProperty(eq(BATCH_PROPERTY), Mockito.nullable(String.class))).thenReturn(String.valueOf(someBatch));
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config);
check(someTimeout, someBatch, AppConfig2.class);
}
Aggregations