@Test public void testUpdateUserAvatarNullSession() { 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.updateUserAvatar(null, null, null); fail(); } catch (RemoteApiException e) { assertEquals(400, e.getCode()); assertEquals(ExceptionMessageFormatter.format("Commons", expectedMessage, expectedSolution), e.getMessage()); } }
public void updateUserAvatar(String sessionToken, Long uid, AvatarUpdate avatarUpdate) throws RemoteApiException { checkAuthToken(sessionToken); if (uid == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, UID, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, UID); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } if (avatarUpdate == null) { String reason = logMessage.getMessage(INSTANCE_EMPTY, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(INSTANCE_EMPTY_SOLUTION, UPDATE_USER_AVATAR); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v1/admin/user/" + uid + "/avatar/update"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); apiClient.doPost(path, headerParams, Collections.<String, String>emptyMap(), avatarUpdate, Map.class); }
UserApiClient extends BasePodApiClient { public void updateUserAvatar(String sessionToken, Long uid, AvatarUpdate avatarUpdate) throws RemoteApiException { checkAuthToken(sessionToken); if (uid == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, UID, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, UID); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } if (avatarUpdate == null) { String reason = logMessage.getMessage(INSTANCE_EMPTY, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(INSTANCE_EMPTY_SOLUTION, UPDATE_USER_AVATAR); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v1/admin/user/" + uid + "/avatar/update"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); apiClient.doPost(path, headerParams, Collections.<String, String>emptyMap(), avatarUpdate, Map.class); } }
UserApiClient extends BasePodApiClient { public void updateUserAvatar(String sessionToken, Long uid, AvatarUpdate avatarUpdate) throws RemoteApiException { checkAuthToken(sessionToken); if (uid == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, UID, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, UID); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } if (avatarUpdate == null) { String reason = logMessage.getMessage(INSTANCE_EMPTY, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(INSTANCE_EMPTY_SOLUTION, UPDATE_USER_AVATAR); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v1/admin/user/" + uid + "/avatar/update"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); apiClient.doPost(path, headerParams, Collections.<String, String>emptyMap(), avatarUpdate, Map.class); } UserApiClient(HttpApiClient apiClient, LogMessageSource logMessage); }
UserApiClient extends BasePodApiClient { public void updateUserAvatar(String sessionToken, Long uid, AvatarUpdate avatarUpdate) throws RemoteApiException { checkAuthToken(sessionToken); if (uid == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, UID, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, UID); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } if (avatarUpdate == null) { String reason = logMessage.getMessage(INSTANCE_EMPTY, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(INSTANCE_EMPTY_SOLUTION, UPDATE_USER_AVATAR); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v1/admin/user/" + uid + "/avatar/update"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); apiClient.doPost(path, headerParams, Collections.<String, String>emptyMap(), avatarUpdate, Map.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 void updateUserAvatar(String sessionToken, Long uid, AvatarUpdate avatarUpdate) throws RemoteApiException { checkAuthToken(sessionToken); if (uid == null) { String reason = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING, UID, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(MISSING_PARAMETER_WHEN_CALLING_SOLUTION, UID); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } if (avatarUpdate == null) { String reason = logMessage.getMessage(INSTANCE_EMPTY, UPDATE_USER_AVATAR); String solution = logMessage.getMessage(INSTANCE_EMPTY_SOLUTION, UPDATE_USER_AVATAR); throw new RemoteApiException(HTTP_BAD_REQUEST_ERROR, reason, solution); } String path = "/v1/admin/user/" + uid + "/avatar/update"; Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); apiClient.doPost(path, headerParams, Collections.<String, String>emptyMap(), avatarUpdate, Map.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);  }