@Test @WithMockUser public void test_should_search_users() throws Exception { when(userService.searchUsers(argThat(new UserSearchMatcher(getUserSearch())), anyBoolean())).thenReturn(getUserModels()); mockMvc.perform(post("/_search/").contentType(MediaType.APPLICATION_JSON_UTF8) .content(getFileContents("getUserByIdRequest.json"))).andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json(getFileContents("userSearchResponse.json"))); }
private UserSearchResponse searchUsers(@RequestBody UserSearchRequest request, HttpHeaders headers) { UserSearchCriteria searchCriteria = request.toDomain(); if(!isInterServiceCall(headers)){ if((isEmpty(searchCriteria.getId()) && isEmpty(searchCriteria.getUuid())) && (searchCriteria.getLimit() > defaultSearchSize || searchCriteria.getLimit() == 0)) searchCriteria.setLimit(defaultSearchSize); } List<User> userModels = userService.searchUsers(searchCriteria, isInterServiceCall(headers)); List<UserSearchResponseContent> userContracts = userModels.stream().map(UserSearchResponseContent::new) .collect(Collectors.toList()); ResponseInfo responseInfo = ResponseInfo.builder().status(String.valueOf(HttpStatus.OK.value())).build(); return new UserSearchResponse(responseInfo, userContracts); }
UserController { private UserSearchResponse searchUsers(@RequestBody UserSearchRequest request, HttpHeaders headers) { UserSearchCriteria searchCriteria = request.toDomain(); if(!isInterServiceCall(headers)){ if((isEmpty(searchCriteria.getId()) && isEmpty(searchCriteria.getUuid())) && (searchCriteria.getLimit() > defaultSearchSize || searchCriteria.getLimit() == 0)) searchCriteria.setLimit(defaultSearchSize); } List<User> userModels = userService.searchUsers(searchCriteria, isInterServiceCall(headers)); List<UserSearchResponseContent> userContracts = userModels.stream().map(UserSearchResponseContent::new) .collect(Collectors.toList()); ResponseInfo responseInfo = ResponseInfo.builder().status(String.valueOf(HttpStatus.OK.value())).build(); return new UserSearchResponse(responseInfo, userContracts); } }
UserController { private UserSearchResponse searchUsers(@RequestBody UserSearchRequest request, HttpHeaders headers) { UserSearchCriteria searchCriteria = request.toDomain(); if(!isInterServiceCall(headers)){ if((isEmpty(searchCriteria.getId()) && isEmpty(searchCriteria.getUuid())) && (searchCriteria.getLimit() > defaultSearchSize || searchCriteria.getLimit() == 0)) searchCriteria.setLimit(defaultSearchSize); } List<User> userModels = userService.searchUsers(searchCriteria, isInterServiceCall(headers)); List<UserSearchResponseContent> userContracts = userModels.stream().map(UserSearchResponseContent::new) .collect(Collectors.toList()); ResponseInfo responseInfo = ResponseInfo.builder().status(String.valueOf(HttpStatus.OK.value())).build(); return new UserSearchResponse(responseInfo, userContracts); } @Autowired  UserController(UserService userService, TokenService tokenService); }
UserController { private UserSearchResponse searchUsers(@RequestBody UserSearchRequest request, HttpHeaders headers) { UserSearchCriteria searchCriteria = request.toDomain(); if(!isInterServiceCall(headers)){ if((isEmpty(searchCriteria.getId()) && isEmpty(searchCriteria.getUuid())) && (searchCriteria.getLimit() > defaultSearchSize || searchCriteria.getLimit() == 0)) searchCriteria.setLimit(defaultSearchSize); } List<User> userModels = userService.searchUsers(searchCriteria, isInterServiceCall(headers)); List<UserSearchResponseContent> userContracts = userModels.stream().map(UserSearchResponseContent::new) .collect(Collectors.toList()); ResponseInfo responseInfo = ResponseInfo.builder().status(String.valueOf(HttpStatus.OK.value())).build(); return new UserSearchResponse(responseInfo, userContracts); } @Autowired  UserController(UserService userService, TokenService tokenService); @PostMapping("/citizen/_create") Object createCitizen(@RequestBody CreateUserRequest createUserRequest); @PostMapping("/users/_createnovalidate") UserDetailResponse createUserWithoutValidation(@RequestBody CreateUserRequest createUserRequest,
			@RequestHeader HttpHeaders headers); @PostMapping("/_search") UserSearchResponse get(@RequestBody UserSearchRequest request, @RequestHeader HttpHeaders headers); @PostMapping("/v1/_search") UserSearchResponse getV1(@RequestBody UserSearchRequest request, @RequestHeader HttpHeaders headers); @PostMapping("/_details") CustomUserDetails getUser(@RequestParam(value = "access_token") String accessToken); @PostMapping("/users/_updatenovalidate") UserDetailResponse updateUserWithoutValidation(@RequestBody final CreateUserRequest createUserRequest,
														  @RequestHeader HttpHeaders headers); @PostMapping("/profile/_update") UserDetailResponse patch(@RequestBody final CreateUserRequest createUserRequest); }
UserController { private UserSearchResponse searchUsers(@RequestBody UserSearchRequest request, HttpHeaders headers) { UserSearchCriteria searchCriteria = request.toDomain(); if(!isInterServiceCall(headers)){ if((isEmpty(searchCriteria.getId()) && isEmpty(searchCriteria.getUuid())) && (searchCriteria.getLimit() > defaultSearchSize || searchCriteria.getLimit() == 0)) searchCriteria.setLimit(defaultSearchSize); } List<User> userModels = userService.searchUsers(searchCriteria, isInterServiceCall(headers)); List<UserSearchResponseContent> userContracts = userModels.stream().map(UserSearchResponseContent::new) .collect(Collectors.toList()); ResponseInfo responseInfo = ResponseInfo.builder().status(String.valueOf(HttpStatus.OK.value())).build(); return new UserSearchResponse(responseInfo, userContracts); } @Autowired  UserController(UserService userService, TokenService tokenService); @PostMapping("/citizen/_create") Object createCitizen(@RequestBody CreateUserRequest createUserRequest); @PostMapping("/users/_createnovalidate") UserDetailResponse createUserWithoutValidation(@RequestBody CreateUserRequest createUserRequest,
			@RequestHeader HttpHeaders headers); @PostMapping("/_search") UserSearchResponse get(@RequestBody UserSearchRequest request, @RequestHeader HttpHeaders headers); @PostMapping("/v1/_search") UserSearchResponse getV1(@RequestBody UserSearchRequest request, @RequestHeader HttpHeaders headers); @PostMapping("/_details") CustomUserDetails getUser(@RequestParam(value = "access_token") String accessToken); @PostMapping("/users/_updatenovalidate") UserDetailResponse updateUserWithoutValidation(@RequestBody final CreateUserRequest createUserRequest,
														  @RequestHeader HttpHeaders headers); @PostMapping("/profile/_update") UserDetailResponse patch(@RequestBody final CreateUserRequest createUserRequest);  }