CtripUserService implements UserService { UserServiceRequest assembleSearchUserRequest(String keyword, int offset, int limit) { Map<String, Object> query = Maps.newHashMap(); Map<String, Object> multiMatchMap = Maps.newHashMap(); multiMatchMap.put("fields", searchUserMatchFields); multiMatchMap.put("operator", "and"); multiMatchMap.put("query", keyword); multiMatchMap.put("type", "best_fields"); query.put("multi_match", multiMatchMap); return assembleUserServiceRequest(query, offset, limit); } CtripUserService(PortalConfig portalConfig); @Override List<UserInfo> searchUsers(String keyword, int offset, int limit); @Override UserInfo findByUserId(String userId); @Override List<UserInfo> findByUserIds(List<String> userIds);  }
@Test public void testAssembleSearchUserRequest() throws Exception { String someKeyword = "someKeyword"; int someOffset = 0; int someLimit = 10; CtripUserService.UserServiceRequest request = ctripUserService.assembleSearchUserRequest(someKeyword, someOffset, someLimit); assertEquals(someUserServiceToken, request.getAccess_token()); CtripUserService.UserServiceRequestBody requestBody = request.getRequest_body(); assertEquals("itdb_emloyee", requestBody.getIndexAlias()); Map<String, Object> queryJson = requestBody.getQueryJson(); assertEquals(someOffset, queryJson.get("from")); assertEquals(someLimit, queryJson.get("size")); Map<String, Object> query = (Map<String, Object>) queryJson.get("query"); Map<String, Object> multiMatchMap = (Map<String, Object>) query.get("multi_match"); assertEquals(someKeyword, multiMatchMap.get("query")); }