MdsRestController { @RequestMapping(value = "/{moduleName}/{namespace}/{entityName}", method = RequestMethod.POST) @ResponseBody public Object post(@PathVariable String moduleName, @PathVariable String namespace, @PathVariable String entityName, HttpServletRequest request) { return doPost(entityName, moduleName, namespace, request); }  @RequestMapping(value = "/{moduleName}/{namespace}/{entityName}", method = RequestMethod.GET) @ResponseBody Object get(@PathVariable String moduleName, @PathVariable String namespace,
                    @PathVariable String entityName, @RequestParam Map<String, String> requestParams); @RequestMapping(value = "/{moduleName}/{entityName}", method = RequestMethod.GET) @ResponseBody Object get(@PathVariable String moduleName, @PathVariable String entityName,
                    @RequestParam Map<String, String> requestParams); @RequestMapping(value = "/lookup/{entityName}/{lookupName}", method = RequestMethod.GET) @ResponseBody Object lookupGet(@PathVariable String entityName, @PathVariable String lookupName,
                      @RequestParam Map<String, String> requestParams); @RequestMapping(value = "/lookup/{moduleName}/{entityName}/{lookupName}", method = RequestMethod.GET) @ResponseBody Object lookupGet(@PathVariable String moduleName, @PathVariable String entityName,
                      @PathVariable String lookupName, @RequestParam Map<String, String> requestParams); @RequestMapping(value = "/lookup/{moduleName}/{namespace}/{entityName}/{lookupName}", method = RequestMethod.GET) @ResponseBody Object lookupGet(@PathVariable String moduleName, @PathVariable String namespace,
                      @PathVariable String entityName, @PathVariable String lookupName,
                      @RequestParam Map<String, String> requestParams); @RequestMapping(value = "/{entityName}", method = RequestMethod.GET) @ResponseBody Object get(@PathVariable String entityName, @RequestParam Map<String, String> requestParams); @RequestMapping(value = "/{moduleName}/{namespace}/{entityName}", method = RequestMethod.POST) @ResponseBody Object post(@PathVariable String moduleName, @PathVariable String namespace,
                    @PathVariable String entityName, HttpServletRequest request); @RequestMapping(value = "/{moduleName}/{entityName}", method = RequestMethod.POST) @ResponseBody Object post(@PathVariable String moduleName, @PathVariable String entityName,
                     HttpServletRequest request); @RequestMapping(value = "/{entityName}", method = RequestMethod.POST) @ResponseBody Object post(@PathVariable String entityName, HttpServletRequest request); @RequestMapping(value = "/{moduleName}/{namespace}/{entityName}", method = RequestMethod.PUT) @ResponseBody Object put(@PathVariable String moduleName, @PathVariable String namespace,
                     @PathVariable String entityName, HttpServletRequest request); @RequestMapping(value = "/{moduleName}/{entityName}", method = RequestMethod.PUT) @ResponseBody Object put(@PathVariable String moduleName, @PathVariable String entityName,
                     HttpServletRequest request); @RequestMapping(value = "/{entityName}", method = RequestMethod.PUT) @ResponseBody Object put(@PathVariable String entityName, HttpServletRequest request); @RequestMapping(value = "/{moduleName}/{namespace}/{entityName}/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void delete(@PathVariable String moduleName, @PathVariable String namespace,
                    @PathVariable String entityName, @PathVariable Long id); @RequestMapping(value = "/{moduleName}/{entityName}/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void delete(@PathVariable String moduleName, @PathVariable String entityName,
                    @PathVariable Long id); @RequestMapping(value = "/{entityName}/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void delete(@PathVariable String entityName, @PathVariable Long id); @ExceptionHandler({RestNotSupportedException.class, RestLookupNotFoundException.class, RestEntityNotFoundException.class, RestNoLookupResultException.class}) @ResponseStatus(HttpStatus.NOT_FOUND) void handleRestNotSupportedException(Exception e); @ExceptionHandler({RestOperationNotSupportedException.class, RestLookupExecutionForbiddenException.class}) @ResponseStatus(HttpStatus.FORBIDDEN) void handleRestOperationNotSupportedException(Exception e); @ExceptionHandler({RestBadBodyFormatException.class, InvalidParameterException.class, JDOUserException.class, IllegalArgumentException.class, NucleusUserException.class, org.springframework.orm.jdo.JdoUsageException.class}) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody String handleBadBodyException(RuntimeException e); @ExceptionHandler(ConstraintViolationException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody String handleConstraintViolationException(ConstraintViolationException e); @ExceptionHandler({JdoOptimisticLockingFailureException.class, NucleusOptimisticException.class}) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody String handleOptimisticTransactionException(ConstraintViolationException e);  }
@Test public void shouldReturn400ForBadBody() throws Exception { when(restFacadeRetriever.getRestFacade(ENTITY_NAME, MODULE_NAME, NAMESPACE)) .thenReturn(restFacade); when(restFacade.create(any(InputStream.class))) .thenThrow(new RestBadBodyFormatException("bad body")); mockMvc.perform( post(buildUrl(ENTITY_NAME, MODULE_NAME, NAMESPACE)) .body("Bad body".getBytes(Charset.forName("UTF-8"))) ).andExpect(status().isBadRequest()); verify(restFacade).create(any(InputStream.class)); }
@Test public void shouldReturn400ForConstraintViolationException() throws Exception { when(restFacadeRetriever.getRestFacade(ENTITY_NAME, MODULE_NAME, NAMESPACE)) .thenReturn(restFacade); when(restFacade.create(any(InputStream.class))) .thenThrow(new ConstraintViolationException(null)); mockMvc.perform( post(buildUrl(ENTITY_NAME, MODULE_NAME, NAMESPACE)) ).andExpect(status().isBadRequest()); verify(restFacade).create(any(InputStream.class)); }