Commit 67043cce authored by Greg Messner's avatar Greg Messner
Browse files

Added getUser(String username) and test for same.

parent 376d5ac1
...@@ -74,6 +74,24 @@ public class UserApi extends AbstractApi { ...@@ -74,6 +74,24 @@ public class UserApi extends AbstractApi {
return (response.readEntity(User.class)); return (response.readEntity(User.class));
} }
/**
* Lookup a user by username.
*
* NOTE: This is for admin users only.
*
* GET /users?username=:username
*
* @param username the username of the user to get
* @return the User instance for the specified username
* @throws GitLabApiException if any exception occurs
*/
public User getUser(String username) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("username", username, true);
Response response = get(Response.Status.OK, formData.asMap(), "users");
List<User> users = response.readEntity(new GenericType<List<User>>() {});
return (users.isEmpty() ? null : users.get(0));
}
/** /**
* Search users by Email or username * Search users by Email or username
* *
......
...@@ -82,4 +82,11 @@ public class TestUserApi { ...@@ -82,4 +82,11 @@ public class TestUserApi {
assertNotNull(currentUser); assertNotNull(currentUser);
assertEquals(TEST_USERNAME, currentUser.getUsername()); assertEquals(TEST_USERNAME, currentUser.getUsername());
} }
@Test
public void testLookupUser() throws GitLabApiException {
User user = gitLabApi.getUserApi().getUser(TEST_USERNAME);
assertNotNull(user);
assertEquals(TEST_USERNAME, user.getUsername());
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment