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.domain.Visibility;
21  import com.atlassian.jira.rest.client.api.domain.Worklog;
22  import org.junit.Test;
23  
24  import static com.atlassian.jira.rest.client.TestUtil.toUri;
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNull;
27  
28  public class WorklogJsonParserTest {
29      @Test
30      public void testParse() throws Exception {
31          final WorklogJsonParser parser = new WorklogJsonParser();
32          final Worklog worklog = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/worklog/valid.json"));
33          assertEquals(toUri("http://localhost:8090/jira/rest/api/latest/worklog/10010"), worklog.getSelf());
34          assertEquals(toUri("http://localhost:8090/jira/rest/api/latest/issue/TST-2"), worklog.getIssueUri());
35          assertEquals(TestConstants.USER_ADMIN_BASIC_DEPRECATED, worklog.getAuthor());
36          assertEquals(TestConstants.USER_ADMIN_BASIC_DEPRECATED, worklog.getUpdateAuthor());
37          assertEquals("my first work", worklog.getComment());
38          assertEquals(TestUtil.toDateTime("2010-08-17T16:35:47.466+0200"), worklog.getCreationDate());
39          assertEquals(TestUtil.toDateTime("2010-08-17T16:35:47.466+0200"), worklog.getUpdateDate());
40          assertEquals(TestUtil.toDateTime("2010-08-15T16:35:00.000+0200"), worklog.getStartDate());
41          assertEquals(60, worklog.getMinutesSpent());
42          assertNull(worklog.getVisibility());
43      }
44  
45      @Test
46      public void testParseWithRoleLevel() throws Exception {
47          final WorklogJsonParser parser = new WorklogJsonParser();
48          final Worklog worklog = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/worklog/valid-roleLevel.json"));
49          assertEquals(toUri("http://localhost:8090/jira/rest/api/latest/worklog/10011"), worklog.getSelf());
50          assertEquals(toUri("http://localhost:8090/jira/rest/api/latest/issue/TST-2"), worklog.getIssueUri());
51          assertEquals(TestConstants.USER1_BASIC_DEPRECATED, worklog.getAuthor());
52          assertEquals(TestConstants.USER1_BASIC_DEPRECATED, worklog.getUpdateAuthor());
53          assertEquals("another piece of work", worklog.getComment());
54          assertEquals(TestUtil.toDateTime("2010-08-17T16:38:00.013+0200"), worklog.getCreationDate());
55          assertEquals(TestUtil.toDateTime("2010-08-17T16:38:24.948+0200"), worklog.getUpdateDate());
56          assertEquals(TestUtil.toDateTime("2010-08-17T16:37:00.000+0200"), worklog.getStartDate());
57          assertEquals(Visibility.role("Developers"), worklog.getVisibility());
58          assertEquals(15, worklog.getMinutesSpent());
59      }
60  
61      @Test
62      public void testParseWithGroupLevel() throws Exception {
63          final WorklogJsonParser parser = new WorklogJsonParser();
64          final Worklog worklog = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/worklog/valid-groupLevel.json"));
65          assertEquals(Visibility.group("jira-users"), worklog.getVisibility());
66      }
67  
68      @Test
69      public void testParseWhenAuthorIsAnonymous() throws Exception {
70          final WorklogJsonParser parser = new WorklogJsonParser();
71          final Worklog worklog = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/worklog/valid-anonymousAuthor.json"));
72          assertNull(worklog.getAuthor());
73          assertNull(worklog.getUpdateAuthor());
74      }
75  
76      @Test
77      public void testParseWhenAuthorIsAnonymousInOldRepresentation() throws Exception {
78          final WorklogJsonParser parser = new WorklogJsonParser();
79          final Worklog worklog = parser.parse(ResourceUtil
80                  .getJsonObjectFromResource("/json/worklog/valid-anonymousAuthor-oldRepresentation.json"));
81          assertNull(worklog.getAuthor());
82          assertNull(worklog.getUpdateAuthor());
83      }
84  
85  }