@Test public void testUpdate() throws IOException, Exception { System.out.println(getFileContents("ReqnUnitRequest.json")); System.out.println(getFileContents("ReqnUnitResponse.json")); List<RegistrationUnit> expectedRegistrationUnit = new ArrayList<>(); expectedRegistrationUnit.add(getExpectedRegistrationUnitForCreateAndUpdate().get(0)); when(registrationUnitService.updateAsync(Matchers.any(RegnUnitRequest.class))) .thenReturn(expectedRegistrationUnit); System.out.println(expectedRegistrationUnit.get(0)); try { mockMvc.perform(post("/regnUnits/_update").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) { System.out.println(e.getMessage()); e.printStackTrace(); } }
@PostMapping @RequestMapping("_update") public ResponseEntity<?> update(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForUpdate(requestInfo, regnUnitRequestBindingResults); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.updateAsync(regnUnitRequest); if (registrationUnitsList.isEmpty()) { return errorHandler.getUpdateErrorResponse(regnUnitRequestBindingResults, requestInfo, regnUnitRequest.getRegnUnit()); } } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getCause()); } return getSuccessResponse(registrationUnitsList, requestInfo); }
RegistrationUnitController { @PostMapping @RequestMapping("_update") public ResponseEntity<?> update(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForUpdate(requestInfo, regnUnitRequestBindingResults); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.updateAsync(regnUnitRequest); if (registrationUnitsList.isEmpty()) { return errorHandler.getUpdateErrorResponse(regnUnitRequestBindingResults, requestInfo, regnUnitRequest.getRegnUnit()); } } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getCause()); } return getSuccessResponse(registrationUnitsList, requestInfo); } }
RegistrationUnitController { @PostMapping @RequestMapping("_update") public ResponseEntity<?> update(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForUpdate(requestInfo, regnUnitRequestBindingResults); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.updateAsync(regnUnitRequest); if (registrationUnitsList.isEmpty()) { return errorHandler.getUpdateErrorResponse(regnUnitRequestBindingResults, requestInfo, regnUnitRequest.getRegnUnit()); } } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getCause()); } return getSuccessResponse(registrationUnitsList, requestInfo); }  }
RegistrationUnitController { @PostMapping @RequestMapping("_update") public ResponseEntity<?> update(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForUpdate(requestInfo, regnUnitRequestBindingResults); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.updateAsync(regnUnitRequest); if (registrationUnitsList.isEmpty()) { return errorHandler.getUpdateErrorResponse(regnUnitRequestBindingResults, requestInfo, regnUnitRequest.getRegnUnit()); } } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getCause()); } 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("_update") public ResponseEntity<?> update(@RequestBody @Valid RegnUnitRequest regnUnitRequest, BindingResult regnUnitRequestBindingResults) { LOGGER.info("regnUnitRequest : " + regnUnitRequest); RequestInfo requestInfo = regnUnitRequest.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForUpdate(requestInfo, regnUnitRequestBindingResults); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.updateAsync(regnUnitRequest); if (registrationUnitsList.isEmpty()) { return errorHandler.getUpdateErrorResponse(regnUnitRequestBindingResults, requestInfo, regnUnitRequest.getRegnUnit()); } } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(regnUnitRequestBindingResults, requestInfo, "Encountered : " + e.getCause()); } 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; }