CtripUserService implements UserService { UserServiceRequest assembleFindUserRequest(List<String> userIds) { Map<String, Object> query = ImmutableMap.of("filtered", ImmutableMap .of("filter", ImmutableMap.of("terms", ImmutableMap.of("empaccount", userIds)))); return assembleUserServiceRequest(query, 0, userIds.size()); } 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 testAssembleFindUserRequest() throws Exception { String someUserId = "someUser"; String anotherUserId = "anotherUser"; List<String> userIds = Lists.newArrayList(someUserId, anotherUserId); CtripUserService.UserServiceRequest request = ctripUserService.assembleFindUserRequest(userIds); assertEquals(someUserServiceToken, request.getAccess_token()); CtripUserService.UserServiceRequestBody requestBody = request.getRequest_body(); assertEquals("itdb_emloyee", requestBody.getIndexAlias()); Map<String, Object> queryJson = requestBody.getQueryJson(); assertEquals(0, queryJson.get("from")); assertEquals(2, queryJson.get("size")); Map<String, Object> query = (Map<String, Object>) queryJson.get("query"); Map<String, Object> terms = getMapFromMap(getMapFromMap(getMapFromMap(query, "filtered"), "filter"), "terms"); List<String> userIdTerms = (List<String>) terms.get("empaccount"); assertTrue(userIdTerms.containsAll(userIds)); }