Search in sources :

Example 21 with Config

use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.

the class DefaultConfigFactoryTest method testCreate.

@Test
public void testCreate() throws Exception {
    String someNamespace = "someName";
    Properties someProperties = new Properties();
    String someKey = "someKey";
    String someValue = "someValue";
    someProperties.setProperty(someKey, someValue);
    LocalFileConfigRepository someLocalConfigRepo = mock(LocalFileConfigRepository.class);
    when(someLocalConfigRepo.getConfig()).thenReturn(someProperties);
    doReturn(someLocalConfigRepo).when(defaultConfigFactory).createConfigRepository(someNamespace);
    Config result = defaultConfigFactory.create(someNamespace);
    assertThat("DefaultConfigFactory should create DefaultConfig", result, is(instanceOf(DefaultConfig.class)));
    assertEquals(someValue, result.getProperty(someKey, null));
}
Also used : LocalFileConfigRepository(com.ctrip.framework.apollo.internals.LocalFileConfigRepository) DefaultConfig(com.ctrip.framework.apollo.internals.DefaultConfig) Config(com.ctrip.framework.apollo.Config) Properties(java.util.Properties) Test(org.junit.Test)

Example 22 with Config

use of com.ctrip.framework.apollo.Config 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 23 with Config

use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.

the class JavaConfigAnnotationTest method testEnableApolloConfigResolveExpressionSimple.

@Test
public void testEnableApolloConfigResolveExpressionSimple() {
    String someKey = "someKey-2020-11-14-1750";
    String someValue = UUID.randomUUID().toString();
    mockConfig(ConfigConsts.NAMESPACE_APPLICATION, mock(Config.class));
    Config xxxConfig = mock(Config.class);
    when(xxxConfig.getProperty(eq(someKey), Mockito.nullable(String.class))).thenReturn(someValue);
    mockConfig("xxx", xxxConfig);
    TestEnableApolloConfigResolveExpressionWithDefaultValueConfiguration configuration = getSimpleBean(TestEnableApolloConfigResolveExpressionWithDefaultValueConfiguration.class);
    // check
    assertEquals(someValue, configuration.getSomeKey());
    verify(xxxConfig, times(1)).getProperty(eq(someKey), Mockito.nullable(String.class));
}
Also used : EnableApolloConfig(com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig) ApolloConfig(com.ctrip.framework.apollo.spring.annotation.ApolloConfig) SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) Config(com.ctrip.framework.apollo.Config) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 24 with Config

use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.

the class JavaConfigAnnotationTest method testApolloConfigChangeListenerResolveExpressionSimple.

@Test
public void testApolloConfigChangeListenerResolveExpressionSimple() {
    // for ignore, no listener use it
    Config ignoreConfig = mock(Config.class);
    mockConfig("ignore.for.listener", ignoreConfig);
    Config applicationConfig = mock(Config.class);
    mockConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationConfig);
    System.setProperty(ApolloClientSystemConsts.APOLLO_PROPERTY_NAMES_CACHE_ENABLE, "true");
    getSimpleBean(TestApolloConfigChangeListenerResolveExpressionSimpleConfiguration.class);
    // no using
    verify(ignoreConfig, never()).addChangeListener(any(ConfigChangeListener.class));
    // one invocation for spring value auto update
    // one invocation for the @ApolloConfigChangeListener annotation
    // one invocation for CachedCompositePropertySource clear cache listener
    verify(applicationConfig, times(3)).addChangeListener(any(ConfigChangeListener.class));
}
Also used : ConfigChangeListener(com.ctrip.framework.apollo.ConfigChangeListener) ApolloConfigChangeListener(com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener) EnableApolloConfig(com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig) ApolloConfig(com.ctrip.framework.apollo.spring.annotation.ApolloConfig) SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) Config(com.ctrip.framework.apollo.Config) Test(org.junit.Test)

Example 25 with Config

use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.

the class JavaConfigAnnotationTest method testEnableApolloConfigResolveExpressionFromSystemProperty.

@Test
public void testEnableApolloConfigResolveExpressionFromSystemProperty() {
    mockConfig(ConfigConsts.NAMESPACE_APPLICATION, mock(Config.class));
    final String someKey = "someKey-2020-11-14-1750";
    final String someValue = UUID.randomUUID().toString();
    final String resolvedNamespaceName = "yyy";
    System.setProperty(SystemPropertyKeyConstants.SIMPLE_NAMESPACE, resolvedNamespaceName);
    Config yyyConfig = mock(Config.class);
    when(yyyConfig.getProperty(eq(someKey), Mockito.nullable(String.class))).thenReturn(someValue);
    mockConfig(resolvedNamespaceName, yyyConfig);
    TestEnableApolloConfigResolveExpressionWithDefaultValueConfiguration configuration = getSimpleBean(TestEnableApolloConfigResolveExpressionWithDefaultValueConfiguration.class);
    // check
    assertEquals(someValue, configuration.getSomeKey());
    verify(yyyConfig, times(1)).getProperty(eq(someKey), Mockito.nullable(String.class));
}
Also used : EnableApolloConfig(com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig) ApolloConfig(com.ctrip.framework.apollo.spring.annotation.ApolloConfig) SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) 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