ConfigController { Map<String, String> mergeReleaseConfigurations(List<Release> releases) { Map<String, String> result = Maps.newLinkedHashMap(); for (Release release : Lists.reverse(releases)) { result.putAll(gson.fromJson(release.getConfigurations(), configurationTypeReference)); } return result; } ConfigController(
      final ConfigService configService,
      final AppNamespaceServiceWithCache appNamespaceService,
      final NamespaceUtil namespaceUtil,
      final InstanceConfigAuditUtil instanceConfigAuditUtil,
      final Gson gson); @GetMapping(value = "/{appId}/{clusterName}/{namespace:.+}") ApolloConfig queryConfig(@PathVariable String appId, @PathVariable String clusterName,
                                  @PathVariable String namespace,
                                  @RequestParam(value = "dataCenter", required = false) String dataCenter,
                                  @RequestParam(value = "releaseKey", defaultValue = "-1") String clientSideReleaseKey,
                                  @RequestParam(value = "ip", required = false) String clientIp,
                                  @RequestParam(value = "messages", required = false) String messagesAsString,
                                  HttpServletRequest request, HttpServletResponse response);  }
@Test public void testMergeConfigurations() throws Exception { Gson gson = new Gson(); String key1 = "key1"; String value1 = "value1"; String anotherValue1 = "anotherValue1"; String key2 = "key2"; String value2 = "value2"; Map<String, String> config = ImmutableMap.of(key1, anotherValue1); Map<String, String> anotherConfig = ImmutableMap.of(key1, value1, key2, value2); Release releaseWithHighPriority = new Release(); releaseWithHighPriority.setConfigurations(gson.toJson(config)); Release releaseWithLowPriority = new Release(); releaseWithLowPriority.setConfigurations(gson.toJson(anotherConfig)); Map<String, String> result = configController.mergeReleaseConfigurations( Lists.newArrayList(releaseWithHighPriority, releaseWithLowPriority)); assertEquals(2, result.keySet().size()); assertEquals(anotherValue1, result.get(key1)); assertEquals(value2, result.get(key2)); }
@Test(expected = JsonSyntaxException.class) public void testTransformConfigurationToMapFailed() throws Exception { String someInvalidConfiguration = "xxx"; Release someRelease = new Release(); someRelease.setConfigurations(someInvalidConfiguration); configController.mergeReleaseConfigurations(Lists.newArrayList(someRelease)); }