ConfigFileController implements ReleaseMessageListener { @GetMapping(value = "/json/{appId}/{clusterName}/{namespace:.+}") public ResponseEntity<String> queryConfigAsJson(@PathVariable String appId, @PathVariable String clusterName, @PathVariable String namespace, @RequestParam(value = "dataCenter", required = false) String dataCenter, @RequestParam(value = "ip", required = false) String clientIp, HttpServletRequest request, HttpServletResponse response) throws IOException { String result = queryConfig(ConfigFileOutputFormat.JSON, appId, clusterName, namespace, dataCenter, clientIp, request, response); if (result == null) { return NOT_FOUND_RESPONSE; } return new ResponseEntity<>(result, jsonResponseHeaders, HttpStatus.OK); } ConfigFileController(
      final ConfigController configController,
      final NamespaceUtil namespaceUtil,
      final WatchKeysUtil watchKeysUtil,
      final GrayReleaseRulesHolder grayReleaseRulesHolder); @GetMapping(value = "/{appId}/{clusterName}/{namespace:.+}") ResponseEntity<String> queryConfigAsProperties(@PathVariable String appId,
                                                        @PathVariable String clusterName,
                                                        @PathVariable String namespace,
                                                        @RequestParam(value = "dataCenter", required = false) String dataCenter,
                                                        @RequestParam(value = "ip", required = false) String clientIp,
                                                        HttpServletRequest request,
                                                        HttpServletResponse response); @GetMapping(value = "/json/{appId}/{clusterName}/{namespace:.+}") ResponseEntity<String> queryConfigAsJson(@PathVariable String appId,
                                                  @PathVariable String clusterName,
                                                  @PathVariable String namespace,
                                                  @RequestParam(value = "dataCenter", required = false) String dataCenter,
                                                  @RequestParam(value = "ip", required = false) String clientIp,
                                                  HttpServletRequest request,
                                                  HttpServletResponse response); @Override void handleMessage(ReleaseMessage message, String channel);  }
@Test public void testQueryConfigAsJson() throws Exception { String someKey = "someKey"; String someValue = "someValue"; Type responseType = new TypeToken<Map<String, String>>(){}.getType(); String someWatchKey = "someWatchKey"; Set<String> watchKeys = Sets.newHashSet(someWatchKey); Map<String, String> configurations = ImmutableMap.of(someKey, someValue); ApolloConfig someApolloConfig = mock(ApolloConfig.class); when(configController .queryConfig(someAppId, someClusterName, someNamespace, someDataCenter, "-1", someClientIp, null, someRequest, someResponse)).thenReturn(someApolloConfig); when(someApolloConfig.getConfigurations()).thenReturn(configurations); when(watchKeysUtil .assembleAllWatchKeys(someAppId, someClusterName, someNamespace, someDataCenter)) .thenReturn(watchKeys); ResponseEntity<String> response = configFileController .queryConfigAsJson(someAppId, someClusterName, someNamespace, someDataCenter, someClientIp, someRequest, someResponse); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(configurations, GSON.fromJson(response.getBody(), responseType)); }