com.ctrip.framework.apollo.Config Java Examples
The following examples show how to use
com.ctrip.framework.apollo.Config.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApolloApplicationContextInitializer.java From apollo with Apache License 2.0 | 6 votes |
/** * Initialize Apollo Configurations Just after environment is ready. * * @param environment */ protected void initialize(ConfigurableEnvironment environment) { if (environment.getPropertySources().contains(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME)) { //already initialized return; } String namespaces = environment.getProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_NAMESPACES, ConfigConsts.NAMESPACE_APPLICATION); logger.debug("Apollo bootstrap namespaces: {}", namespaces); List<String> namespaceList = NAMESPACE_SPLITTER.splitToList(namespaces); CompositePropertySource composite = new CompositePropertySource(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME); for (String namespace : namespaceList) { Config config = ConfigService.getConfig(namespace); composite.addPropertySource(configPropertySourceFactory.getConfigPropertySource(namespace, config)); } environment.getPropertySources().addFirst(composite); }
Example #2
Source File: ApolloMockServerApiTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testDeleteSamePropertyTwice() throws Exception { Config otherConfig = ConfigService.getConfig(anotherNamespace); final Semaphore changes = new Semaphore(0); otherConfig.addChangeListener(new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { changes.release(); } }); assertEquals("otherValue6", otherConfig.getProperty("key6", null)); embeddedApollo.deleteProperty(anotherNamespace, "key6"); embeddedApollo.deleteProperty(anotherNamespace, "key6"); assertTrue(changes.tryAcquire(5, TimeUnit.SECONDS)); assertNull(otherConfig.getProperty("key6", null)); assertEquals(0, changes.availablePermits()); }
Example #3
Source File: JavaConfigAnnotationTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testApolloConfigWithInheritance() throws Exception { Config applicationConfig = mock(Config.class); Config fxApolloConfig = mock(Config.class); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationConfig); mockConfig(FX_APOLLO_NAMESPACE, fxApolloConfig); prepareYamlConfigFile(APPLICATION_YAML_NAMESPACE, readYamlContentAsConfigFileProperties("case9.yml")); TestApolloChildConfigBean bean = getBean(TestApolloChildConfigBean.class, AppConfig6.class); assertEquals(applicationConfig, bean.getConfig()); assertEquals(applicationConfig, bean.getAnotherConfig()); assertEquals(fxApolloConfig, bean.getYetAnotherConfig()); assertEquals(applicationConfig, bean.getSomeConfig()); }
Example #4
Source File: JavaConfigAnnotationTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testApolloConfigChangeListenerWithYamlFile() throws Exception { String someKey = "someKey"; String someValue = "someValue"; String anotherValue = "anotherValue"; YamlConfigFile configFile = prepareYamlConfigFile(APPLICATION_YAML_NAMESPACE, readYamlContentAsConfigFileProperties("case9.yml")); TestApolloConfigChangeListenerWithYamlFile bean = getBean(TestApolloConfigChangeListenerWithYamlFile.class, AppConfig9.class); Config yamlConfig = bean.getYamlConfig(); SettableFuture<ConfigChangeEvent> future = bean.getConfigChangeEventFuture(); assertEquals(someValue, yamlConfig.getProperty(someKey, null)); assertFalse(future.isDone()); configFile.onRepositoryChange(APPLICATION_YAML_NAMESPACE, readYamlContentAsConfigFileProperties("case9-new.yml")); ConfigChangeEvent configChangeEvent = future.get(100, TimeUnit.MILLISECONDS); ConfigChange change = configChangeEvent.getChange(someKey); assertEquals(someValue, change.getOldValue()); assertEquals(anotherValue, change.getNewValue()); assertEquals(anotherValue, yamlConfig.getProperty(someKey, null)); }
Example #5
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testMultiplePropertiesCompatiblePropertySourcesWithSameProperties() throws Exception { int someTimeout = 1000; int anotherTimeout = someTimeout + 1; int someBatch = 2000; Properties properties = mock(Properties.class); when(properties.getProperty(TIMEOUT_PROPERTY)).thenReturn(String.valueOf(someTimeout)); when(properties.getProperty(BATCH_PROPERTY)).thenReturn(String.valueOf(someBatch)); PropertiesCompatibleConfigFile configFile = mock(PropertiesCompatibleConfigFile.class); when(configFile.asProperties()).thenReturn(properties); mockConfigFile("application.yml", configFile); Config fxApollo = mock(Config.class); when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout)); mockConfig(FX_APOLLO_NAMESPACE, fxApollo); check(someTimeout, someBatch, AppConfig11.class); }
Example #6
Source File: DefaultConfigFactoryTest.java From apollo with Apache License 2.0 | 6 votes |
@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).createLocalConfigRepository(someNamespace); Config result = defaultConfigFactory.create(someNamespace); assertThat("DefaultConfigFactory should create DefaultConfig", result, is(instanceOf(DefaultConfig.class))); assertEquals(someValue, result.getProperty(someKey, null)); }
Example #7
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testMultiplePropertySourcesCoverWithSameProperties() throws Exception { //Multimap does not maintain the strict input order of namespace. int someTimeout = 1000; int anotherTimeout = someTimeout + 1; int someBatch = 2000; Config fxApollo = mock(Config.class); when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout)); when(fxApollo.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch)); mockConfig(FX_APOLLO_NAMESPACE, fxApollo); Config application = mock(Config.class); when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout)); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application); check(someTimeout, someBatch, AppConfig6.class); }
Example #8
Source File: BootstrapConfigTest.java From apollo with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() throws Exception { doSetUp(); System.setProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_ENABLED, "true"); System.setProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_NAMESPACES, String.format("%s, %s", ConfigConsts.NAMESPACE_APPLICATION, FX_APOLLO_NAMESPACE)); Config config = mock(Config.class); Config anotherConfig = mock(Config.class); when(config.getPropertyNames()).thenReturn(Sets.newHashSet(TEST_BEAN_CONDITIONAL_ON_KEY)); when(config.getProperty(eq(TEST_BEAN_CONDITIONAL_ON_KEY), anyString())).thenReturn(Boolean.TRUE.toString()); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, anotherConfig); mockConfig(FX_APOLLO_NAMESPACE, config); }
Example #9
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testMultiplePropertySourcesCoverWithSamePropertiesWithPropertiesCompatiblePropertySource() throws Exception { //Multimap does not maintain the strict input order of namespace. int someTimeout = 1000; int anotherTimeout = someTimeout + 1; int someBatch = 2000; Config fxApollo = mock(Config.class); when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout)); when(fxApollo.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch)); mockConfig(FX_APOLLO_NAMESPACE, fxApollo); Config application = mock(Config.class); when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout)); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application); check(someTimeout, someBatch, AppConfig6.class); }
Example #10
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testMultiplePropertySourcesWithSamePropertiesWithWeight() throws Exception { int someTimeout = 1000; int anotherTimeout = someTimeout + 1; int someBatch = 2000; Config application = mock(Config.class); when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout)); when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch)); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application); Config fxApollo = mock(Config.class); when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout)); mockConfig(FX_APOLLO_NAMESPACE, fxApollo); check(anotherTimeout, someBatch, AppConfig2.class, AppConfig4.class); }
Example #11
Source File: JavaConfigAnnotationTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testApolloConfig() throws Exception { Config applicationConfig = mock(Config.class); Config fxApolloConfig = mock(Config.class); String someKey = "someKey"; String someValue = "someValue"; mockConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationConfig); mockConfig(FX_APOLLO_NAMESPACE, fxApolloConfig); prepareYamlConfigFile(APPLICATION_YAML_NAMESPACE, readYamlContentAsConfigFileProperties("case9.yml")); TestApolloConfigBean1 bean = getBean(TestApolloConfigBean1.class, AppConfig1.class); assertEquals(applicationConfig, bean.getConfig()); assertEquals(applicationConfig, bean.getAnotherConfig()); assertEquals(fxApolloConfig, bean.getYetAnotherConfig()); Config yamlConfig = bean.getYamlConfig(); assertEquals(someValue, yamlConfig.getProperty(someKey, null)); }
Example #12
Source File: DefaultConfigManager.java From apollo with Apache License 2.0 | 6 votes |
@Override public Config getConfig(String namespace) { Config config = m_configs.get(namespace); if (config == null) { synchronized (this) { config = m_configs.get(namespace); if (config == null) { ConfigFactory factory = m_factoryManager.getFactory(namespace); config = factory.create(namespace); m_configs.put(namespace, config); } } } return config; }
Example #13
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testApplicationPropertySourceWithValueInjectedAsConstructorArgs() throws Exception { int someTimeout = 1000; int someBatch = 2000; Config config = mock(Config.class); when(config.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout)); when(config.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch)); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig7.class); TestJavaConfigBean3 bean = context.getBean(TestJavaConfigBean3.class); assertEquals(someTimeout, bean.getTimeout()); assertEquals(someBatch, bean.getBatch()); }
Example #14
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testNestedProperty() throws Exception { String a = "a"; String b = "b"; int someValue = 1234; Config config = mock(Config.class); when(config.getProperty(eq(a), anyString())).thenReturn(a); when(config.getProperty(eq(b), anyString())).thenReturn(b); when(config.getProperty(eq(String.format("%s.%s", a, b)), anyString())) .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()); }
Example #15
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@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), anyString())).thenReturn(a); when(config.getProperty(eq(b), anyString())).thenReturn(b); when(config.getProperty(eq(c), anyString())).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()); }
Example #16
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testNestedPropertyWithNestedDefaultValue() throws Exception { String a = "a"; String b = "b"; Config config = mock(Config.class); when(config.getProperty(eq(a), anyString())).thenReturn(a); when(config.getProperty(eq(b), anyString())).thenReturn(b); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NestedPropertyConfig1.class); TestNestedPropertyBean bean = context.getBean(TestNestedPropertyBean.class); assertEquals(100, bean.getNestedProperty()); }
Example #17
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testMultipleNestedProperty() throws Exception { String a = "a"; String b = "b"; String nestedKey = "c.d"; String nestedProperty = String.format("${%s}", nestedKey); int someValue = 1234; Config config = mock(Config.class); when(config.getProperty(eq(a), anyString())).thenReturn(a); when(config.getProperty(eq(b), anyString())).thenReturn(b); when(config.getProperty(eq(String.format("%s.%s", a, b)), anyString())).thenReturn(nestedProperty); when(config.getProperty(eq(nestedKey), anyString())).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()); }
Example #18
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testMultipleNestedPropertyWithDefaultValue() throws Exception { String a = "a"; String b = "b"; String nestedKey = "c.d"; int someValue = 1234; String nestedProperty = String.format("${%s:%d}", nestedKey, someValue); Config config = mock(Config.class); when(config.getProperty(eq(a), anyString())).thenReturn(a); when(config.getProperty(eq(b), anyString())).thenReturn(b); when(config.getProperty(eq(String.format("%s.%s", a, b)), anyString())).thenReturn(nestedProperty); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NestedPropertyConfig1.class); TestNestedPropertyBean bean = context.getBean(TestNestedPropertyBean.class); assertEquals(someValue, bean.getNestedProperty()); }
Example #19
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testApolloJsonValue() { String someJson = "[{\"a\":\"astring\", \"b\":10},{\"a\":\"astring2\", \"b\":20}]"; String otherJson = "[{\"a\":\"otherString\", \"b\":10},{\"a\":\"astring2\", \"b\":20}]"; Config config = mock(Config.class); when(config.getProperty(eq(JSON_PROPERTY), anyString())).thenReturn(someJson); when(config.getProperty(eq(OTHER_JSON_PROPERTY), anyString())).thenReturn(otherJson); when(config.getProperty(eq("a"), anyString())).thenReturn(JSON_PROPERTY); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( AppConfig8.class); TestJsonPropertyBean testJsonPropertyBean = context.getBean(TestJsonPropertyBean.class); assertEquals(2, testJsonPropertyBean.getJsonBeanList().size()); assertEquals("astring", testJsonPropertyBean.getJsonBeanList().get(0).getA()); assertEquals(10, testJsonPropertyBean.getJsonBeanList().get(0).getB()); assertEquals("astring2", testJsonPropertyBean.getJsonBeanList().get(1).getA()); assertEquals(20, testJsonPropertyBean.getJsonBeanList().get(1).getB()); assertEquals(testJsonPropertyBean.getJsonBeanList(), testJsonPropertyBean.getEmbeddedJsonBeanList()); assertEquals("otherString", testJsonPropertyBean.getOtherJsonBeanList().get(0).getA()); assertEquals(10, testJsonPropertyBean.getOtherJsonBeanList().get(0).getB()); assertEquals("astring2", testJsonPropertyBean.getOtherJsonBeanList().get(1).getA()); assertEquals(20, testJsonPropertyBean.getOtherJsonBeanList().get(1).getB()); }
Example #20
Source File: XmlConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testMultiplePropertySourcesWithSamePropertiesWithWeight() throws Exception { int someTimeout = 1000; int anotherTimeout = someTimeout + 1; int someBatch = 2000; Config application = mock(Config.class); when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout)); when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch)); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application); Config fxApollo = mock(Config.class); when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout)); mockConfig(FX_APOLLO_NAMESPACE, fxApollo); check("spring/XmlConfigPlaceholderTest4.xml", anotherTimeout, someBatch); }
Example #21
Source File: XmlConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testMultiplePropertySourcesWithSameProperties2() throws Exception { int someTimeout = 1000; int anotherTimeout = someTimeout + 1; int someBatch = 2000; Config application = mock(Config.class); when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout)); when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch)); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application); Config fxApollo = mock(Config.class); when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout)); mockConfig(FX_APOLLO_NAMESPACE, fxApollo); check("spring/XmlConfigPlaceholderTest6.xml", anotherTimeout, someBatch); }
Example #22
Source File: XmlConfigPlaceholderTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testMultiplePropertySourcesWithSameProperties() throws Exception { int someTimeout = 1000; int anotherTimeout = someTimeout + 1; int someBatch = 2000; Config application = mock(Config.class); when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout)); when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch)); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application); Config fxApollo = mock(Config.class); when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout)); mockConfig(FX_APOLLO_NAMESPACE, fxApollo); check("spring/XmlConfigPlaceholderTest3.xml", someTimeout, someBatch); }
Example #23
Source File: ConfigIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@Test public void testGetConfigWithLocalFileAndWithRemoteConfig() throws Exception { String someKey = "someKey"; String someValue = "someValue"; String anotherValue = "anotherValue"; Properties properties = new Properties(); properties.put(someKey, someValue); createLocalCachePropertyFile(properties); ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, anotherValue)); ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig); startServerWithHandlers(handler); Config config = ConfigService.getAppConfig(); assertEquals(anotherValue, config.getProperty(someKey, null)); }
Example #24
Source File: JavaConfigPlaceholderTest.java From apollo with Apache License 2.0 | 5 votes |
@Test(expected = BeanCreationException.class) public void testApolloJsonValueWithNoPropertyValue() throws Exception { Config config = mock(Config.class); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config); new AnnotationConfigApplicationContext(AppConfig8.class); }
Example #25
Source File: ConfigIntegrationTest.java From apollo with Apache License 2.0 | 5 votes |
@Test public void testOrderGetConfigWithLocalFileAndWithRemoteConfig() throws Exception { String someKey = "someKey"; String someValue = "someValue"; String anotherValue = "anotherValue"; String someKey1 = "someKey1"; String someValue1 = "someValue1"; String anotherValue1 = "anotherValue1"; String someKey2 = "someKey2"; String someValue2 = "someValue2"; setPropertiesOrderEnabled(true); Properties properties = new OrderedProperties(); properties.put(someKey, someValue); properties.put(someKey1, someValue1); properties.put(someKey2, someValue2); createLocalCachePropertyFile(properties); Map<String, String> configurations = new LinkedHashMap<>(); configurations.put(someKey, anotherValue); configurations.put(someKey1, anotherValue1); configurations.put(someKey2, someValue2); ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.copyOf(configurations)); ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig); startServerWithHandlers(handler); Config config = ConfigService.getAppConfig(); assertEquals(anotherValue, config.getProperty(someKey, null)); Set<String> propertyNames = config.getPropertyNames(); Iterator<String> it = propertyNames.iterator(); assertEquals(someKey, it.next()); assertEquals(someKey1, it.next()); assertEquals(someKey2, it.next()); assertEquals(anotherValue1, config.getProperty(someKey1, "")); }
Example #26
Source File: XmlConfigPlaceholderTest.java From apollo with Apache License 2.0 | 5 votes |
@Test public void testApplicationPropertySource() throws Exception { int someTimeout = 1000; int someBatch = 2000; Config config = mock(Config.class); when(config.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout)); when(config.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch)); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config); check("spring/XmlConfigPlaceholderTest2.xml", someTimeout, someBatch); }
Example #27
Source File: JavaConfigAnnotationTest.java From apollo with Apache License 2.0 | 5 votes |
@Test(expected = BeanCreationException.class) public void testApolloConfigChangeListenerWithWrongParamType() throws Exception { Config applicationConfig = mock(Config.class); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationConfig); getBean(TestApolloConfigChangeListenerBean2.class, AppConfig4.class); }
Example #28
Source File: JavaConfigAnnotationTest.java From apollo with Apache License 2.0 | 5 votes |
@Test(expected = BeanCreationException.class) public void testApolloConfigWithWrongFieldType() throws Exception { Config applicationConfig = mock(Config.class); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationConfig); getBean(TestApolloConfigBean2.class, AppConfig2.class); }
Example #29
Source File: XmlConfigPlaceholderTest.java From apollo with Apache License 2.0 | 5 votes |
@Test public void testMultiplePropertySources() throws Exception { int someTimeout = 1000; int someBatch = 2000; Config application = mock(Config.class); when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout)); mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application); Config fxApollo = mock(Config.class); when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch)); mockConfig(FX_APOLLO_NAMESPACE, fxApollo); check("spring/XmlConfigPlaceholderTest3.xml", someTimeout, someBatch); }
Example #30
Source File: ConfigIntegrationTest.java From apollo with Apache License 2.0 | 5 votes |
@Test public void testGetConfigWithLocalFileAndRemoteConfigError() throws Exception { String someKey = "someKey"; String someValue = "someValue"; Properties properties = new Properties(); properties.put(someKey, someValue); createLocalCachePropertyFile(properties); ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null); startServerWithHandlers(handler); Config config = ConfigService.getAppConfig(); assertEquals(someValue, config.getProperty(someKey, null)); }