@Test public void testSearch() throws IOException, Exception { List<EmployeeInfo> expectedEmployeesList = getExpectedEmployeesForSearch(); ResponseInfo expectedResponseInfo = new ResponseInfo("emp", "1.0", "2017-01-18T07:18:23.130Z", "uief87324", "20170310130900", "200"); Map<String, Object> empMap = new HashMap<String, Object>() {{ put("ResponseInfo", expectedResponseInfo); put("Employee", expectedEmployeesList); }}; ResponseEntity<?> responseEntity = new ResponseEntity<>(empMap, HttpStatus.OK); when(employeeService.getEmployees(any(EmployeeCriteria.class), any(RequestInfo.class))) .thenReturn(expectedEmployeesList); when(responseInfoFactory.createResponseInfoFromRequestInfo(any(RequestInfo.class), any(Boolean.class))) .thenReturn(expectedResponseInfo); doReturn(responseEntity).when(responseEntityFactory).getSuccessResponse(anyMapOf(String.class, Object.class), any(RequestInfo.class)); mockMvc.perform(post("/employees/_search").param("tenantId", "1").param("id", "100") .content(getFileContents("RequestInfo.json")).contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json( getFileContents("employeeSearchResponse1.json"))); }
@PostMapping("_search") @ResponseBody public ResponseEntity<?> search(@ModelAttribute @Valid EmployeeCriteria employeeCriteria, BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult requestBodyBindingResult) { RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = requestValidator.validateSearchRequest(requestInfo, modelAttributeBindingResult, requestBodyBindingResult); if (errorResponseEntity != null) return errorResponseEntity; Map<String, Object> employeeMap = null; try { employeeMap = employeeService.getPaginatedEmployees(employeeCriteria, requestInfo); } catch (Exception exception) { log.error("Error while processing request " + employeeCriteria, exception); return errorHandler.getResponseEntityForUnexpectedErrors(requestInfo); } return responseEntityFactory.getSuccessResponse(employeeMap, requestInfo); }
EmployeeController { @PostMapping("_search") @ResponseBody public ResponseEntity<?> search(@ModelAttribute @Valid EmployeeCriteria employeeCriteria, BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult requestBodyBindingResult) { RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = requestValidator.validateSearchRequest(requestInfo, modelAttributeBindingResult, requestBodyBindingResult); if (errorResponseEntity != null) return errorResponseEntity; Map<String, Object> employeeMap = null; try { employeeMap = employeeService.getPaginatedEmployees(employeeCriteria, requestInfo); } catch (Exception exception) { log.error("Error while processing request " + employeeCriteria, exception); return errorHandler.getResponseEntityForUnexpectedErrors(requestInfo); } return responseEntityFactory.getSuccessResponse(employeeMap, requestInfo); } }
EmployeeController { @PostMapping("_search") @ResponseBody public ResponseEntity<?> search(@ModelAttribute @Valid EmployeeCriteria employeeCriteria, BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult requestBodyBindingResult) { RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = requestValidator.validateSearchRequest(requestInfo, modelAttributeBindingResult, requestBodyBindingResult); if (errorResponseEntity != null) return errorResponseEntity; Map<String, Object> employeeMap = null; try { employeeMap = employeeService.getPaginatedEmployees(employeeCriteria, requestInfo); } catch (Exception exception) { log.error("Error while processing request " + employeeCriteria, exception); return errorHandler.getResponseEntityForUnexpectedErrors(requestInfo); } return responseEntityFactory.getSuccessResponse(employeeMap, requestInfo); }  }
EmployeeController { @PostMapping("_search") @ResponseBody public ResponseEntity<?> search(@ModelAttribute @Valid EmployeeCriteria employeeCriteria, BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult requestBodyBindingResult) { RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = requestValidator.validateSearchRequest(requestInfo, modelAttributeBindingResult, requestBodyBindingResult); if (errorResponseEntity != null) return errorResponseEntity; Map<String, Object> employeeMap = null; try { employeeMap = employeeService.getPaginatedEmployees(employeeCriteria, requestInfo); } catch (Exception exception) { log.error("Error while processing request " + employeeCriteria, exception); return errorHandler.getResponseEntityForUnexpectedErrors(requestInfo); } return responseEntityFactory.getSuccessResponse(employeeMap, requestInfo); }  @PostMapping("_search") @ResponseBody ResponseEntity<?> search(@ModelAttribute @Valid EmployeeCriteria employeeCriteria,
			BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping("_baseregisterreport") @ResponseBody ResponseEntity<?> baseregisterreport(
			@ModelAttribute @Valid BaseRegisterReportRequest baseRegisterReportRequest,
			BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping("_employeewithoutassignmentreport") @ResponseBody ResponseEntity<?> employeeWithoutAssignment(@ModelAttribute @Valid EmployeeCriteria employeeCriteria,
			BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping("_loggedinemployee") @ResponseBody ResponseEntity<?> loggedInEmployee(@RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping("{id}/_search") @ResponseBody ResponseEntity<?> get(@ModelAttribute @Valid EmployeeGetRequest employeeGetRequest,
			BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping(value = "/_create") @ResponseBody ResponseEntity<?> create(@RequestBody @Valid EmployeeRequest employeeRequest, BindingResult bindingResult); @PostMapping(value = "/_bulkcreate") @ResponseBody ResponseEntity<?> bulkCreate(@RequestBody @Valid EmployeeBulkRequest employeeBulkRequest,
			BindingResult bindingResult); @PostMapping(value = "/_update") @ResponseBody ResponseEntity<?> update(@RequestBody @Valid EmployeeRequest employeeRequest, BindingResult bindingResult); @PostMapping(value = "/_updateemployee") @ResponseBody ResponseEntity<?> updateEmployee(@RequestBody @Valid EmployeeRequest employeeRequest,
			BindingResult bindingResult); ResponseEntity<?> getSuccessResponseForCreate(Employee employee, RequestInfo requestInfo); ResponseEntity<?> getSuccessResponseForGet(Employee employee, RequestInfo requestInfo); ResponseEntity<?> getSuccessResponseForUpdate(Employee employee, RequestInfo requestInfo); }
EmployeeController { @PostMapping("_search") @ResponseBody public ResponseEntity<?> search(@ModelAttribute @Valid EmployeeCriteria employeeCriteria, BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper, BindingResult requestBodyBindingResult) { RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); ResponseEntity<?> errorResponseEntity = requestValidator.validateSearchRequest(requestInfo, modelAttributeBindingResult, requestBodyBindingResult); if (errorResponseEntity != null) return errorResponseEntity; Map<String, Object> employeeMap = null; try { employeeMap = employeeService.getPaginatedEmployees(employeeCriteria, requestInfo); } catch (Exception exception) { log.error("Error while processing request " + employeeCriteria, exception); return errorHandler.getResponseEntityForUnexpectedErrors(requestInfo); } return responseEntityFactory.getSuccessResponse(employeeMap, requestInfo); }  @PostMapping("_search") @ResponseBody ResponseEntity<?> search(@ModelAttribute @Valid EmployeeCriteria employeeCriteria,
			BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping("_baseregisterreport") @ResponseBody ResponseEntity<?> baseregisterreport(
			@ModelAttribute @Valid BaseRegisterReportRequest baseRegisterReportRequest,
			BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping("_employeewithoutassignmentreport") @ResponseBody ResponseEntity<?> employeeWithoutAssignment(@ModelAttribute @Valid EmployeeCriteria employeeCriteria,
			BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping("_loggedinemployee") @ResponseBody ResponseEntity<?> loggedInEmployee(@RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping("{id}/_search") @ResponseBody ResponseEntity<?> get(@ModelAttribute @Valid EmployeeGetRequest employeeGetRequest,
			BindingResult modelAttributeBindingResult, @RequestBody @Valid RequestInfoWrapper requestInfoWrapper,
			BindingResult requestBodyBindingResult); @PostMapping(value = "/_create") @ResponseBody ResponseEntity<?> create(@RequestBody @Valid EmployeeRequest employeeRequest, BindingResult bindingResult); @PostMapping(value = "/_bulkcreate") @ResponseBody ResponseEntity<?> bulkCreate(@RequestBody @Valid EmployeeBulkRequest employeeBulkRequest,
			BindingResult bindingResult); @PostMapping(value = "/_update") @ResponseBody ResponseEntity<?> update(@RequestBody @Valid EmployeeRequest employeeRequest, BindingResult bindingResult); @PostMapping(value = "/_updateemployee") @ResponseBody ResponseEntity<?> updateEmployee(@RequestBody @Valid EmployeeRequest employeeRequest,
			BindingResult bindingResult); ResponseEntity<?> getSuccessResponseForCreate(Employee employee, RequestInfo requestInfo); ResponseEntity<?> getSuccessResponseForGet(Employee employee, RequestInfo requestInfo); ResponseEntity<?> getSuccessResponseForUpdate(Employee employee, RequestInfo requestInfo);  }