InstanceConfigController { @GetMapping("/by-namespace") public PageDTO<InstanceDTO> getInstancesByNamespace( @RequestParam("appId") String appId, @RequestParam("clusterName") String clusterName, @RequestParam("namespaceName") String namespaceName, @RequestParam(value = "instanceAppId", required = false) String instanceAppId, Pageable pageable) { Page<Instance> instances; if (Strings.isNullOrEmpty(instanceAppId)) { instances = instanceService.findInstancesByNamespace(appId, clusterName, namespaceName, pageable); } else { instances = instanceService.findInstancesByNamespaceAndInstanceAppId(instanceAppId, appId, clusterName, namespaceName, pageable); } List<InstanceDTO> instanceDTOs = BeanUtils.batchTransform(InstanceDTO.class, instances.getContent()); return new PageDTO<>(instanceDTOs, pageable, instances.getTotalElements()); } InstanceConfigController(final ReleaseService releaseService, final InstanceService instanceService); @GetMapping("/by-release") PageDTO<InstanceDTO> getByRelease(@RequestParam("releaseId") long releaseId,
                                           Pageable pageable); @GetMapping("/by-namespace-and-releases-not-in") List<InstanceDTO> getByReleasesNotIn(@RequestParam("appId") String appId,
                                              @RequestParam("clusterName") String clusterName,
                                              @RequestParam("namespaceName") String namespaceName,
                                              @RequestParam("releaseIds") String releaseIds); @GetMapping("/by-namespace") PageDTO<InstanceDTO> getInstancesByNamespace(
      @RequestParam("appId") String appId, @RequestParam("clusterName") String clusterName,
      @RequestParam("namespaceName") String namespaceName,
      @RequestParam(value = "instanceAppId", required = false) String instanceAppId,
      Pageable pageable); @GetMapping("/by-namespace/count") long getInstancesCountByNamespace(@RequestParam("appId") String appId,
                                          @RequestParam("clusterName") String clusterName,
                                          @RequestParam("namespaceName") String namespaceName);  }
@Test public void testGetInstancesByNamespace() throws Exception { String someAppId = "someAppId"; String someClusterName = "someClusterName"; String someNamespaceName = "someNamespaceName"; String someIp = "someIp"; long someInstanceId = 1; long anotherInstanceId = 2; Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName, someNamespaceName, someIp); Instance anotherInstance = assembleInstance(anotherInstanceId, someAppId, someClusterName, someNamespaceName, someIp); Page<Instance> instances = new PageImpl<>(Lists.newArrayList(someInstance, anotherInstance), pageable, 2); when(instanceService.findInstancesByNamespace(someAppId, someClusterName, someNamespaceName, pageable)).thenReturn(instances); PageDTO<InstanceDTO> result = instanceConfigController.getInstancesByNamespace(someAppId, someClusterName, someNamespaceName, null, pageable); assertEquals(2, result.getContent().size()); InstanceDTO someInstanceDto = null; InstanceDTO anotherInstanceDto = null; for (InstanceDTO instanceDTO : result.getContent()) { if (instanceDTO.getId() == someInstanceId) { someInstanceDto = instanceDTO; } else if (instanceDTO.getId() == anotherInstanceId) { anotherInstanceDto = instanceDTO; } } verifyInstance(someInstance, someInstanceDto); verifyInstance(anotherInstance, anotherInstanceDto); }
@Test public void testGetInstancesByNamespaceAndInstanceAppId() throws Exception { String someInstanceAppId = "someInstanceAppId"; String someAppId = "someAppId"; String someClusterName = "someClusterName"; String someNamespaceName = "someNamespaceName"; String someIp = "someIp"; long someInstanceId = 1; long anotherInstanceId = 2; Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName, someNamespaceName, someIp); Instance anotherInstance = assembleInstance(anotherInstanceId, someAppId, someClusterName, someNamespaceName, someIp); Page<Instance> instances = new PageImpl<>(Lists.newArrayList(someInstance, anotherInstance), pageable, 2); when(instanceService.findInstancesByNamespaceAndInstanceAppId(someInstanceAppId, someAppId, someClusterName, someNamespaceName, pageable)).thenReturn(instances); PageDTO<InstanceDTO> result = instanceConfigController.getInstancesByNamespace(someAppId, someClusterName, someNamespaceName, someInstanceAppId, pageable); assertEquals(2, result.getContent().size()); InstanceDTO someInstanceDto = null; InstanceDTO anotherInstanceDto = null; for (InstanceDTO instanceDTO : result.getContent()) { if (instanceDTO.getId() == someInstanceId) { someInstanceDto = instanceDTO; } else if (instanceDTO.getId() == anotherInstanceId) { anotherInstanceDto = instanceDTO; } } verifyInstance(someInstance, someInstanceDto); verifyInstance(anotherInstance, anotherInstanceDto); }