RemoteConfigLongPollService { String assembleLongPollRefreshUrl(String uri, String appId, String cluster, String dataCenter, Map<String, Long> notificationsMap) { Map<String, String> queryParams = Maps.newHashMap(); queryParams.put("appId", queryParamEscaper.escape(appId)); queryParams.put("cluster", queryParamEscaper.escape(cluster)); queryParams .put("notifications", queryParamEscaper.escape(assembleNotifications(notificationsMap))); 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)); } String params = MAP_JOINER.join(queryParams); if (!uri.endsWith("/")) { uri += "/"; } return uri + "notifications/v2?" + params; } RemoteConfigLongPollService(); boolean submit(String namespace, RemoteConfigRepository remoteConfigRepository);  }
@Test public void testAssembleLongPollRefreshUrl() throws Exception { String someUri = someServerUrl; String someAppId = "someAppId"; String someCluster = "someCluster+ &.-_someSign"; String someNamespace = "someName"; long someNotificationId = 1; Map<String, Long> notificationsMap = ImmutableMap.of(someNamespace, someNotificationId); String longPollRefreshUrl = remoteConfigLongPollService .assembleLongPollRefreshUrl(someUri, someAppId, someCluster, null, notificationsMap); assertTrue(longPollRefreshUrl.contains(someServerUrl + "/notifications/v2?")); assertTrue(longPollRefreshUrl.contains("appId=" + someAppId)); assertTrue(longPollRefreshUrl.contains("cluster=someCluster%2B+%26.-_someSign")); assertTrue(longPollRefreshUrl.contains( "notifications=%5B%7B%22namespaceName%22%3A%22" + someNamespace + "%22%2C%22notificationId%22%3A" + 1 + "%7D%5D")); }
@Test public void testAssembleLongPollRefreshUrlWithMultipleNamespaces() throws Exception { String someUri = someServerUrl; String someAppId = "someAppId"; String someCluster = "someCluster+ &.-_someSign"; String someNamespace = "someName"; String anotherNamespace = "anotherName"; long someNotificationId = 1; long anotherNotificationId = 2; Map<String, Long> notificationsMap = ImmutableMap.of(someNamespace, someNotificationId, anotherNamespace, anotherNotificationId); String longPollRefreshUrl = remoteConfigLongPollService .assembleLongPollRefreshUrl(someUri, someAppId, someCluster, null, notificationsMap); assertTrue(longPollRefreshUrl.contains(someServerUrl + "/notifications/v2?")); assertTrue(longPollRefreshUrl.contains("appId=" + someAppId)); assertTrue(longPollRefreshUrl.contains("cluster=someCluster%2B+%26.-_someSign")); assertTrue( longPollRefreshUrl.contains("notifications=%5B%7B%22namespaceName%22%3A%22" + someNamespace + "%22%2C%22notificationId%22%3A" + someNotificationId + "%7D%2C%7B%22namespaceName%22%3A%22" + anotherNamespace + "%22%2C%22notificationId%22%3A" + anotherNotificationId + "%7D%5D")); }