六、测试模式

    文件名格式约定为

    更多使用demo可以参考ApolloMockServerApiTest.java和。

    1. @RunWith(SpringJUnit4ClassRunner.class)@SpringApplicationConfiguration(classes = TestConfiguration.class)public class SpringIntegrationTest { // 启动apollo的mockserver @ClassRule public static EmbeddedApollo embeddedApollo = new EmbeddedApollo();

    2. @Test @DirtiesContext public void testListenerTriggeredByAdd() throws InterruptedException, ExecutionException, TimeoutException { String otherNamespace = "othernamespace"; embeddedApollo.addOrModifyPropery(otherNamespace,"someKey","someValue"); ConfigChangeEvent changeEvent = testBean.futureData.get(5000, TimeUnit.MILLISECONDS); assertEquals(otherNamespace, changeEvent.getNamespace()); assertEquals("someValue", changeEvent.getChange("someKey").getNewValue()); }

    3. static class TestBean{ @Value("${key1:default}") String key1; @Value("${key2:default}") String key2;