View Javadoc

1   /*
2    * Copyright (C) 2010 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.jira.rest.client.internal.json;
18  
19  import com.atlassian.jira.rest.client.TestUtil;
20  import com.atlassian.jira.rest.client.api.ExpandableProperty;
21  import com.atlassian.jira.rest.client.api.domain.User;
22  import com.google.common.collect.ImmutableList;
23  import org.junit.Assert;
24  import org.junit.Test;
25  
26  import static org.junit.Assert.assertEquals;
27  
28  
29  public class UserJsonParserTest {
30      @Test
31      public void testParse() throws Exception {
32          final UserJsonParser parser = new UserJsonParser();
33          final User user = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/user/valid.json"));
34          Assert.assertEquals(TestUtil
35                  .toUri("http://localhost:8090/jira/secure/useravatar?size=large&ownerId=admin&avatarId=10054"), user
36                  .getAvatarUri());
37          Assert.assertNull(user.getSmallAvatarUri());
38          assertEquals("admin", user.getName());
39          assertEquals("Administrator", user.getDisplayName());
40          Assert.assertEquals("user@atlassian.com", user.getEmailAddress());
41          Assert.assertEquals(new ExpandableProperty<String>(3, ImmutableList
42                  .of("jira-administrators", "jira-developers", "jira-users")), user.getGroups());
43          Assert.assertNull(user.getTimezone());
44      }
45  
46      @Test
47      public void testParseJira5x0User() throws Exception {
48          final UserJsonParser parser = new UserJsonParser();
49          final User user = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/user/valid-5.0.json"));
50          Assert.assertEquals(TestUtil.toUri("http://localhost:2990/jira/secure/useravatar?avatarId=10082"), user.getAvatarUri());
51          Assert.assertEquals(TestUtil.toUri("http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10082"), user
52                  .getSmallAvatarUri());
53          assertEquals("wseliga", user.getName());
54          assertEquals("Wojciech Seliga", user.getDisplayName());
55          Assert.assertEquals("wseliga@atlassian.com", user.getEmailAddress());
56          Assert.assertEquals(1, user.getGroups().getSize());
57          Assert.assertNull(user.getGroups().getItems());
58          Assert.assertEquals("Europe/Warsaw", user.getTimezone());
59      }
60  
61      @Test
62      public void testParseWhenEmailHidden() throws Exception {
63          final UserJsonParser parser = new UserJsonParser();
64          final User user = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/user/valid-with-hidden-email.json"));
65  
66          Assert.assertNull(user.getEmailAddress());
67      }
68  
69      @Test
70      public void testParseWhenEmailMasked() throws Exception {
71          final UserJsonParser parser = new UserJsonParser();
72          final User user = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/user/valid-with-masked-email.json"));
73  
74          Assert.assertEquals("wojciech dot seliga at spartez dot com", user.getEmailAddress());
75      }
76  
77  }