@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());
  }
@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);
  }