ConfigController { ApolloNotificationMessages transformMessages(String messagesAsString) { ApolloNotificationMessages notificationMessages = null; if (!Strings.isNullOrEmpty(messagesAsString)) { try { notificationMessages = gson.fromJson(messagesAsString, ApolloNotificationMessages.class); } catch (Throwable ex) { Tracer.logError(ex); } } return notificationMessages; } 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 testTransformMessages() throws Exception { String someKey = "someKey"; long someNotificationId = 1; String anotherKey = "anotherKey"; long anotherNotificationId = 2; ApolloNotificationMessages notificationMessages = new ApolloNotificationMessages(); notificationMessages.put(someKey, someNotificationId); notificationMessages.put(anotherKey, anotherNotificationId); String someMessagesAsString = gson.toJson(notificationMessages); ApolloNotificationMessages result = configController.transformMessages(someMessagesAsString); assertEquals(notificationMessages.getDetails(), result.getDetails()); }
@Test public void testTransformInvalidMessages() throws Exception { String someInvalidMessages = "someInvalidMessages"; assertNull(configController.transformMessages(someInvalidMessages)); }