@Test public void testForSearch() throws IOException, Exception { List<RegistrationUnit> expectedRegistrationUnit = new ArrayList<>(); expectedRegistrationUnit.add(getRegnUnitsFromDB().get(0)); expectedRegistrationUnit.add(getRegnUnitsFromDB().get(1)); expectedRegistrationUnit.add(getRegnUnitsFromDB().get(2)); when(registrationUnitService.search(Matchers.any(RegistrationUnitSearchCriteria.class))) .thenReturn(expectedRegistrationUnit); try { mockMvc.perform(post("/regnUnits/_search").content(getFileContents("RequestInfo.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()) .andExpect(content().json(getFileContents("RegistrationUnits.json"))); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
@PostMapping @RequestMapping("_search") public ResponseEntity<?> search(@RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult bindingResultsForRequestInfoWrapper, @ModelAttribute @Valid RegistrationUnitSearchCriteria regnUnitSearchCriteria, BindingResult bindingResultsForSearchCriteria) { LOGGER.info("requestInfoWrapper : " + requestInfoWrapper); LOGGER.info("regnUnitSearchCriteria : " + regnUnitSearchCriteria); RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForSearch(requestInfo, bindingResultsForRequestInfoWrapper, bindingResultsForSearchCriteria); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.search(regnUnitSearchCriteria); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(bindingResultsForSearchCriteria, requestInfo, "Encountered : " + e.getMessage()); } return getSuccessResponse(registrationUnitsList, requestInfo); }
RegistrationUnitController { @PostMapping @RequestMapping("_search") public ResponseEntity<?> search(@RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult bindingResultsForRequestInfoWrapper, @ModelAttribute @Valid RegistrationUnitSearchCriteria regnUnitSearchCriteria, BindingResult bindingResultsForSearchCriteria) { LOGGER.info("requestInfoWrapper : " + requestInfoWrapper); LOGGER.info("regnUnitSearchCriteria : " + regnUnitSearchCriteria); RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForSearch(requestInfo, bindingResultsForRequestInfoWrapper, bindingResultsForSearchCriteria); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.search(regnUnitSearchCriteria); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(bindingResultsForSearchCriteria, requestInfo, "Encountered : " + e.getMessage()); } return getSuccessResponse(registrationUnitsList, requestInfo); } }
RegistrationUnitController { @PostMapping @RequestMapping("_search") public ResponseEntity<?> search(@RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult bindingResultsForRequestInfoWrapper, @ModelAttribute @Valid RegistrationUnitSearchCriteria regnUnitSearchCriteria, BindingResult bindingResultsForSearchCriteria) { LOGGER.info("requestInfoWrapper : " + requestInfoWrapper); LOGGER.info("regnUnitSearchCriteria : " + regnUnitSearchCriteria); RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForSearch(requestInfo, bindingResultsForRequestInfoWrapper, bindingResultsForSearchCriteria); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.search(regnUnitSearchCriteria); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(bindingResultsForSearchCriteria, requestInfo, "Encountered : " + e.getMessage()); } return getSuccessResponse(registrationUnitsList, requestInfo); }  }
RegistrationUnitController { @PostMapping @RequestMapping("_search") public ResponseEntity<?> search(@RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult bindingResultsForRequestInfoWrapper, @ModelAttribute @Valid RegistrationUnitSearchCriteria regnUnitSearchCriteria, BindingResult bindingResultsForSearchCriteria) { LOGGER.info("requestInfoWrapper : " + requestInfoWrapper); LOGGER.info("regnUnitSearchCriteria : " + regnUnitSearchCriteria); RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForSearch(requestInfo, bindingResultsForRequestInfoWrapper, bindingResultsForSearchCriteria); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.search(regnUnitSearchCriteria); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(bindingResultsForSearchCriteria, 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("_search") public ResponseEntity<?> search(@RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult bindingResultsForRequestInfoWrapper, @ModelAttribute @Valid RegistrationUnitSearchCriteria regnUnitSearchCriteria, BindingResult bindingResultsForSearchCriteria) { LOGGER.info("requestInfoWrapper : " + requestInfoWrapper); LOGGER.info("regnUnitSearchCriteria : " + regnUnitSearchCriteria); RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = errorHandler.handleBindingErrorsForSearch(requestInfo, bindingResultsForRequestInfoWrapper, bindingResultsForSearchCriteria); if (errorResponseEntity != null) return errorResponseEntity; List<RegistrationUnit> registrationUnitsList = null; try { registrationUnitsList = registrationUnitService.search(regnUnitSearchCriteria); } catch (Exception e) { LOGGER.error(" Error While Procssing the Request!"); return errorHandler.getUnExpectedErrorResponse(bindingResultsForSearchCriteria, 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; }