ClusterController { @DeleteMapping("/apps/{appId}/clusters/{clusterName:.+}") public void delete(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @RequestParam String operator) { Cluster entity = clusterService.findOne(appId, clusterName); if (entity == null) { throw new NotFoundException("cluster not found for clusterName " + clusterName); } if(ConfigConsts.CLUSTER_NAME_DEFAULT.equals(entity.getName())){ throw new BadRequestException("can not delete default cluster!"); } clusterService.delete(entity.getId(), operator); } ClusterController(final ClusterService clusterService); @PostMapping("/apps/{appId}/clusters") ClusterDTO create(@PathVariable("appId") String appId,
                           @RequestParam(value = "autoCreatePrivateNamespace", defaultValue = "true") boolean autoCreatePrivateNamespace,
                           @Valid @RequestBody ClusterDTO dto); @DeleteMapping("/apps/{appId}/clusters/{clusterName:.+}") void delete(@PathVariable("appId") String appId,
                     @PathVariable("clusterName") String clusterName, @RequestParam String operator); @GetMapping("/apps/{appId}/clusters") List<ClusterDTO> find(@PathVariable("appId") String appId); @GetMapping("/apps/{appId}/clusters/{clusterName:.+}") ClusterDTO get(@PathVariable("appId") String appId,
                        @PathVariable("clusterName") String clusterName); @GetMapping("/apps/{appId}/cluster/{clusterName}/unique") boolean isAppIdUnique(@PathVariable("appId") String appId,
                               @PathVariable("clusterName") String clusterName);  }
@Test(expected = BadRequestException.class) public void testDeleteDefaultFail() { Cluster cluster = new Cluster(); cluster.setName(ConfigConsts.CLUSTER_NAME_DEFAULT); when(clusterService.findOne(any(String.class), any(String.class))).thenReturn(cluster); clusterController.delete("1", "2", "d"); }
@Test public void testDeleteSuccess() { Cluster cluster = new Cluster(); when(clusterService.findOne(any(String.class), any(String.class))).thenReturn(cluster); clusterController.delete("1", "2", "d"); verify(clusterService, times(1)).findOne("1", "2"); }