@Test public void testCreate() throws IOException, Exception { List<RegistrationUnit> expectedRegistrationUnit = new ArrayList<>(); expectedRegistrationUnit.add(getExpectedRegistrationUnitForCreateAndUpdate().get(0)); when(registrationUnitService.createAsync(Matchers.any(RegnUnitRequest.class))) .thenReturn(expectedRegistrationUnit); try { mockMvc.perform(post("/regnUnits/_create").content(getFileContents("ReqnUnitRequest.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json(getFileContents("ReqnUnitResponse.json"))); } catch (Exception e) { e.printStackTrace(); } }
@PostMapping @RequestMapping("_create") public ResponseEntity<?> create(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); registrationUnitValidator.validate(regnUnitRequest, regnUnitRequestBindingResults); if (regnUnitRequestBindingResults.hasErrors()) return new ResponseEntity<>(errorHandler.getErrorResponse(regnUnitRequestBindingResults, requestInfo), HttpStatus.BAD_REQUEST); List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.createAsync(regnUnitRequest); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getMessage()); } return getSuccessResponse(registrationUnitsList, requestInfo); }
RegistrationUnitController { @PostMapping @RequestMapping("_create") public ResponseEntity<?> create(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); registrationUnitValidator.validate(regnUnitRequest, regnUnitRequestBindingResults); if (regnUnitRequestBindingResults.hasErrors()) return new ResponseEntity<>(errorHandler.getErrorResponse(regnUnitRequestBindingResults, requestInfo), HttpStatus.BAD_REQUEST); List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.createAsync(regnUnitRequest); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getMessage()); } return getSuccessResponse(registrationUnitsList, requestInfo); } }
RegistrationUnitController { @PostMapping @RequestMapping("_create") public ResponseEntity<?> create(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); registrationUnitValidator.validate(regnUnitRequest, regnUnitRequestBindingResults); if (regnUnitRequestBindingResults.hasErrors()) return new ResponseEntity<>(errorHandler.getErrorResponse(regnUnitRequestBindingResults, requestInfo), HttpStatus.BAD_REQUEST); List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.createAsync(regnUnitRequest); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getMessage()); } return getSuccessResponse(registrationUnitsList, requestInfo); }  }
RegistrationUnitController { @PostMapping @RequestMapping("_create") public ResponseEntity<?> create(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); registrationUnitValidator.validate(regnUnitRequest, regnUnitRequestBindingResults); if (regnUnitRequestBindingResults.hasErrors()) return new ResponseEntity<>(errorHandler.getErrorResponse(regnUnitRequestBindingResults, requestInfo), HttpStatus.BAD_REQUEST); List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.createAsync(regnUnitRequest); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getMessage()); } return getSuccessResponse(registrationUnitsList, requestInfo); }  @PostMapping @RequestMapping("_create") ResponseEntity<?> create(@RequestBody @Valid RegnUnitRequest regnUnitRequest,
			BindingResult regnUnitRequestBindingResults); @PostMapping @RequestMapping("_search") ResponseEntity<?> search(@RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult bindingResultsForRequestInfoWrapper,
			@ModelAttribute @Valid RegistrationUnitSearchCriteria regnUnitSearchCriteria,
			BindingResult bindingResultsForSearchCriteria); @PostMapping @RequestMapping("_update") ResponseEntity<?> update(@RequestBody @Valid RegnUnitRequest regnUnitRequest,
			BindingResult regnUnitRequestBindingResults); }
RegistrationUnitController { @PostMapping @RequestMapping("_create") public ResponseEntity<?> create(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); registrationUnitValidator.validate(regnUnitRequest, regnUnitRequestBindingResults); if (regnUnitRequestBindingResults.hasErrors()) return new ResponseEntity<>(errorHandler.getErrorResponse(regnUnitRequestBindingResults, requestInfo), HttpStatus.BAD_REQUEST); List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.createAsync(regnUnitRequest); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getMessage()); } return getSuccessResponse(registrationUnitsList, requestInfo); }  @PostMapping @RequestMapping("_create") ResponseEntity<?> create(@RequestBody @Valid RegnUnitRequest regnUnitRequest,
			BindingResult regnUnitRequestBindingResults); @PostMapping @RequestMapping("_search") ResponseEntity<?> search(@RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult bindingResultsForRequestInfoWrapper,
			@ModelAttribute @Valid RegistrationUnitSearchCriteria regnUnitSearchCriteria,
			BindingResult bindingResultsForSearchCriteria); @PostMapping @RequestMapping("_update") ResponseEntity<?> update(@RequestBody @Valid RegnUnitRequest regnUnitRequest,
			BindingResult regnUnitRequestBindingResults); static final Logger LOGGER; }