1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package it;
18
19 import com.atlassian.jira.rest.client.ExpandableProperty;
20 import com.atlassian.jira.rest.client.IntegrationTestUtil;
21 import com.atlassian.jira.rest.client.TestUtil;
22 import com.atlassian.jira.rest.client.domain.User;
23 import com.atlassian.jira.rest.client.internal.json.TestConstants;
24 import com.google.common.collect.ImmutableList;
25 import org.codehaus.jettison.json.JSONException;
26 import org.junit.Test;
27
28 import javax.ws.rs.core.Response;
29
30 import static com.atlassian.jira.rest.client.IntegrationTestUtil.USER_SLASH;
31 import static com.atlassian.jira.rest.client.IntegrationTestUtil.USER_SLASH_LATEST;
32
33 public class JerseyUserRestClientTest extends AbstractRestoringJiraStateJerseyRestClientTest {
34
35 @Test
36 public void testGetUser() throws JSONException {
37 final User user = client.getUserClient().getUser(ADMIN_USERNAME, pm);
38 assertEquals("wojciech.seliga@spartez.com", user.getEmailAddress());
39 assertEquals("admin", user.getName());
40 assertEquals("Administrator", user.getDisplayName());
41 assertEquals(new ExpandableProperty<String>(3, ImmutableList.of("jira-administrators", "jira-developers", "jira-users")), user.getGroups());
42 assertEquals(IntegrationTestUtil.USER_ADMIN_LATEST.getSelf(), user.getSelf());
43 assertTrue(user.getAvatarUri().toString().contains("ownerId=" + user.getName()));
44
45 final User user2 = client.getUserClient().getUser(TestConstants.USER1_USERNAME, pm);
46 assertEquals(new ExpandableProperty<String>(ImmutableList.of("jira-users")), user2.getGroups());
47 }
48
49 public void testGetUserWithSlash() {
50 final User user = client.getUserClient().getUser(USER_SLASH.getName(), pm);
51 assertEquals(USER_SLASH_LATEST.getSelf(), user.getSelf());
52 assertEquals(USER_SLASH_LATEST.getDisplayName(), user.getDisplayName());
53 }
54
55 public void testGetNonExistingUser() {
56 final String username = "same-fake-user-which-does-not-exist";
57 TestUtil.assertErrorCode(Response.Status.NOT_FOUND, "The user named '" + username + "' does not exist",
58 new Runnable() {
59 @Override
60 public void run() {
61 client.getUserClient().getUser(username, pm);
62 }
63 });
64 }
65
66 public void testGetUserAnonymously() {
67 TestUtil.assertErrorCode(Response.Status.UNAUTHORIZED, new Runnable() {
68 @Override
69 public void run() {
70 setAnonymousMode();
71 client.getUserClient().getUser(TestConstants.USER1_USERNAME, pm);
72 }
73 });
74
75 }
76
77 }