@Test public void testGetUserByEmailNullSessionToken() { String expectedMessage = String.format("Missing the required parameter %s", SESSION_TOKEN_HEADER_PARAM); String expectedSolution = String.format("Please check if the required field '%s' is not empty", SESSION_TOKEN_HEADER_PARAM); when(logMessage.getMessage(MISSING_PARAMETER, SESSION_TOKEN_HEADER_PARAM)).thenReturn( expectedMessage); when(logMessage.getMessage(MISSING_PARAMETER_SOLUTION, SESSION_TOKEN_HEADER_PARAM)).thenReturn( expectedSolution); try { apiClient.getUserByEmail(null, null); fail(); } catch (RemoteApiException e) { assertEquals(400, e.getCode()); assertEquals(ExceptionMessageFormatter.format("Commons", expectedMessage, expectedSolution), e.getMessage()); } }
public User getUserByEmail(String sessionToken, String email) throws RemoteApiException { checkAuthToken(sessionToken); if (email == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, EMAIL, GET_USER_BY_EMAIL); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, EMAIL); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v2/user"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); Map<String, String> queryParams = new HashMap<>(); queryParams.put("email", email); queryParams.put("local", Boolean.TRUE.toString()); return apiClient.doGet(path, headerParams, queryParams, User.class); }
UserApiClient extends BasePodApiClient { public User getUserByEmail(String sessionToken, String email) throws RemoteApiException { checkAuthToken(sessionToken); if (email == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, EMAIL, GET_USER_BY_EMAIL); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, EMAIL); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v2/user"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); Map<String, String> queryParams = new HashMap<>(); queryParams.put("email", email); queryParams.put("local", Boolean.TRUE.toString()); return apiClient.doGet(path, headerParams, queryParams, User.class); } }
UserApiClient extends BasePodApiClient { public User getUserByEmail(String sessionToken, String email) throws RemoteApiException { checkAuthToken(sessionToken); if (email == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, EMAIL, GET_USER_BY_EMAIL); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, EMAIL); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v2/user"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); Map<String, String> queryParams = new HashMap<>(); queryParams.put("email", email); queryParams.put("local", Boolean.TRUE.toString()); return apiClient.doGet(path, headerParams, queryParams, User.class); } UserApiClient(HttpApiClient apiClient, LogMessageSource logMessage); }
UserApiClient extends BasePodApiClient { public User getUserByEmail(String sessionToken, String email) throws RemoteApiException { checkAuthToken(sessionToken); if (email == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, EMAIL, GET_USER_BY_EMAIL); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, EMAIL); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v2/user"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); Map<String, String> queryParams = new HashMap<>(); queryParams.put("email", email); queryParams.put("local", Boolean.TRUE.toString()); return apiClient.doGet(path, headerParams, queryParams, User.class); } UserApiClient(HttpApiClient apiClient, LogMessageSource logMessage); User getUserByEmail(String sessionToken, String email); User getUserByUsername(String sessionToken, String username); User getUserById(String sessionToken, Long userId); UserDetail createUser(String sessionToken, UserCreate userInfo); UserDetail updateUser(String sessionToken, Long uid, UserAttributes attributes); void updateUserAvatar(String sessionToken, Long uid, AvatarUpdate avatarUpdate); }
UserApiClient extends BasePodApiClient { public User getUserByEmail(String sessionToken, String email) throws RemoteApiException { checkAuthToken(sessionToken); if (email == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, EMAIL, GET_USER_BY_EMAIL); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, EMAIL); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v2/user"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); Map<String, String> queryParams = new HashMap<>(); queryParams.put("email", email); queryParams.put("local", Boolean.TRUE.toString()); return apiClient.doGet(path, headerParams, queryParams, User.class); } UserApiClient(HttpApiClient apiClient, LogMessageSource logMessage); User getUserByEmail(String sessionToken, String email); User getUserByUsername(String sessionToken, String username); User getUserById(String sessionToken, Long userId); UserDetail createUser(String sessionToken, UserCreate userInfo); UserDetail updateUser(String sessionToken, Long uid, UserAttributes attributes); void updateUserAvatar(String sessionToken, Long uid, AvatarUpdate avatarUpdate);  }