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.ExpandableProperty;
20  import com.atlassian.jira.rest.client.TestUtil;
21  import com.atlassian.jira.rest.client.domain.User;
22  import com.google.common.collect.ImmutableList;
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNull;
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  		assertEquals(TestUtil.toUri("http://localhost:8090/jira/secure/useravatar?size=large&ownerId=admin&avatarId=10054"), user.getAvatarUri());
35  		assertNull(user.getSmallAvatarUri());
36  		assertEquals("admin", user.getName());
37  		assertEquals("Administrator", user.getDisplayName());
38  		assertEquals("user@atlassian.com", user.getEmailAddress());
39  		assertEquals(new ExpandableProperty<String>(3, ImmutableList.of("jira-administrators", "jira-developers", "jira-users")), user.getGroups());
40  		assertNull(user.getTimezone());
41  	}
42  
43  	@Test
44  	public void testParseJira5x0User() throws Exception {
45  		final UserJsonParser parser = new UserJsonParser();
46  		final User user = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/user/valid-5.0.json"));
47  		assertEquals(TestUtil.toUri("http://localhost:2990/jira/secure/useravatar?avatarId=10082"), user.getAvatarUri());
48  		assertEquals(TestUtil.toUri("http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10082"), user.getSmallAvatarUri());
49  		assertEquals("wseliga", user.getName());
50  		assertEquals("Wojciech Seliga", user.getDisplayName());
51  		assertEquals("wseliga@atlassian.com", user.getEmailAddress());
52  		assertEquals(1, user.getGroups().getSize());
53  		assertNull(user.getGroups().getItems());
54  		assertEquals("Europe/Warsaw", user.getTimezone());
55  	}
56  
57  	@Test
58  	public void testParseWhenEmailHidden() throws Exception {
59  		final UserJsonParser parser = new UserJsonParser();
60  		final User user = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/user/valid-with-hidden-email.json"));
61  
62  		assertNull(user.getEmailAddress());
63  	}
64  
65  	@Test
66  	public void testParseWhenEmailMasked() throws Exception {
67  		final UserJsonParser parser = new UserJsonParser();
68  		final User user = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/user/valid-with-masked-email.json"));
69  
70  		assertEquals("wojciech dot seliga at spartez dot com", user.getEmailAddress());
71  	}
72  
73  }