Search in sources :

Example 36 with Config

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);
}
Also used : EnableApolloConfig(com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig) Config(com.ctrip.framework.apollo.Config) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 37 with Config

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());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EnableApolloConfig(com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig) Config(com.ctrip.framework.apollo.Config) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 38 with Config

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);
}
Also used : EnableApolloConfig(com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig) Config(com.ctrip.framework.apollo.Config) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 39 with Config

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());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EnableApolloConfig(com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig) Config(com.ctrip.framework.apollo.Config) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 40 with Config

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);
}
Also used : EnableApolloConfig(com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig) Config(com.ctrip.framework.apollo.Config) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Config (com.ctrip.framework.apollo.Config)94 Test (org.junit.Test)79 EnableApolloConfig (com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig)39 Matchers.anyString (org.mockito.Matchers.anyString)31 ApolloConfig (com.ctrip.framework.apollo.spring.annotation.ApolloConfig)26 ConfigChangeListener (com.ctrip.framework.apollo.ConfigChangeListener)22 SimpleConfig (com.ctrip.framework.apollo.internals.SimpleConfig)20 ConfigChangeEvent (com.ctrip.framework.apollo.model.ConfigChangeEvent)16 BaseIntegrationTest (com.ctrip.framework.apollo.BaseIntegrationTest)13 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)13 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)13 ApolloConfigChangeListener (com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener)10 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 Properties (java.util.Properties)6 ConfigFactory (com.ctrip.framework.apollo.spi.ConfigFactory)5 PureApolloConfigFactory (com.ctrip.framework.apollo.config.data.internals.PureApolloConfigFactory)4 DefaultConfigFactory (com.ctrip.framework.apollo.spi.DefaultConfigFactory)4 OrderedProperties (com.ctrip.framework.apollo.util.OrderedProperties)4 Set (java.util.Set)4 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)3