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