RemoteConfigRepository extends AbstractConfigRepository { String assembleQueryConfigUrl(String uri, String appId, String cluster, String namespace, String dataCenter, ApolloNotificationMessages remoteMessages, ApolloConfig previousConfig) { String path = "configs/%s/%s/%s"; List<String> pathParams = Lists.newArrayList(pathEscaper.escape(appId), pathEscaper.escape(cluster), pathEscaper.escape(namespace)); Map<String, String> queryParams = Maps.newHashMap(); if (previousConfig != null) { queryParams.put("releaseKey", queryParamEscaper.escape(previousConfig.getReleaseKey())); } if (!Strings.isNullOrEmpty(dataCenter)) { queryParams.put("dataCenter", queryParamEscaper.escape(dataCenter)); } String localIp = m_configUtil.getLocalIp(); if (!Strings.isNullOrEmpty(localIp)) { queryParams.put("ip", queryParamEscaper.escape(localIp)); } if (remoteMessages != null) { queryParams.put("messages", queryParamEscaper.escape(GSON.toJson(remoteMessages))); } String pathExpanded = String.format(path, pathParams.toArray()); if (!queryParams.isEmpty()) { pathExpanded += "?" + MAP_JOINER.join(queryParams); } if (!uri.endsWith("/")) { uri += "/"; } return uri + pathExpanded; } RemoteConfigRepository(String namespace); @Override Properties getConfig(); @Override void setUpstreamRepository(ConfigRepository upstreamConfigRepository); @Override ConfigSourceType getSourceType(); void onLongPollNotified(ServiceDTO longPollNotifiedServiceDto, ApolloNotificationMessages remoteMessages);  }
@Test public void testAssembleQueryConfigUrl() throws Exception { Gson gson = new Gson(); String someUri = "http: String someAppId = "someAppId"; String someCluster = "someCluster+ &.-_someSign"; String someReleaseKey = "20160705193346-583078ef5716c055+20160705193308-31c471ddf9087c3f"; ApolloNotificationMessages notificationMessages = new ApolloNotificationMessages(); String someKey = "someKey"; long someNotificationId = 1; String anotherKey = "anotherKey"; long anotherNotificationId = 2; notificationMessages.put(someKey, someNotificationId); notificationMessages.put(anotherKey, anotherNotificationId); RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace); ApolloConfig someApolloConfig = mock(ApolloConfig.class); when(someApolloConfig.getReleaseKey()).thenReturn(someReleaseKey); String queryConfigUrl = remoteConfigRepository .assembleQueryConfigUrl(someUri, someAppId, someCluster, someNamespace, null, notificationMessages, someApolloConfig); remoteConfigLongPollService.stopLongPollingRefresh(); assertTrue(queryConfigUrl .contains( "http: assertTrue(queryConfigUrl .contains("releaseKey=20160705193346-583078ef5716c055%2B20160705193308-31c471ddf9087c3f")); assertTrue(queryConfigUrl .contains("messages=" + UrlEscapers.urlFormParameterEscaper() .escape(gson.toJson(notificationMessages)))); }