NamespaceController { @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces") public NamespaceDTO create(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @Valid @RequestBody NamespaceDTO dto) { Namespace entity = BeanUtils.transform(Namespace.class, dto); Namespace managedEntity = namespaceService.findOne(appId, clusterName, entity.getNamespaceName()); if (managedEntity != null) { throw new BadRequestException("namespace already exist."); } entity = namespaceService.save(entity); return BeanUtils.transform(NamespaceDTO.class, entity); } NamespaceController(final NamespaceService namespaceService); @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces") NamespaceDTO create(@PathVariable("appId") String appId,
                             @PathVariable("clusterName") String clusterName,
                             @Valid @RequestBody NamespaceDTO dto); @DeleteMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}") void delete(@PathVariable("appId") String appId,
                     @PathVariable("clusterName") String clusterName,
                     @PathVariable("namespaceName") String namespaceName, @RequestParam String operator); @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces") List<NamespaceDTO> find(@PathVariable("appId") String appId,
                                 @PathVariable("clusterName") String clusterName); @GetMapping("/namespaces/{namespaceId}") NamespaceDTO get(@PathVariable("namespaceId") Long namespaceId); @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}") NamespaceDTO get(@PathVariable("appId") String appId,
                          @PathVariable("clusterName") String clusterName,
                          @PathVariable("namespaceName") String namespaceName); @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/associated-public-namespace") NamespaceDTO findPublicNamespaceForAssociatedNamespace(@PathVariable String appId,
                                                                @PathVariable String clusterName,
                                                                @PathVariable String namespaceName); @GetMapping("/apps/{appId}/namespaces/publish_info") Map<String, Boolean> namespacePublishInfo(@PathVariable String appId);  }
@Test public void create() { try { NamespaceDTO namespaceDTO = new NamespaceDTO(); namespaceDTO.setClusterName("cluster"); namespaceDTO.setNamespaceName("invalid name"); namespaceDTO.setAppId("whatever"); restTemplate.postForEntity( url("/apps/{appId}/clusters/{clusterName}/namespaces"), namespaceDTO, NamespaceDTO.class, namespaceDTO.getAppId(), namespaceDTO.getClusterName()); Assert.fail("Should throw"); } catch (HttpClientErrorException e) { Assert.assertThat(new String(e.getResponseBodyAsByteArray()), containsString(InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE)); } }