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.api.domain.Version;
20  import com.atlassian.jira.rest.client.test.matchers.DateTimeMatcher;
21  import org.codehaus.jettison.json.JSONException;
22  import org.joda.time.DateTime;
23  import org.joda.time.DateTimeZone;
24  import org.junit.Assert;
25  import org.junit.Test;
26  
27  import java.net.URI;
28  import java.net.URISyntaxException;
29  
30  import static org.junit.Assert.assertEquals;
31  import static org.junit.Assert.assertNull;
32  
33  public class VersionJsonParserTest {
34  
35      @Test
36      public void testParse() throws JSONException, URISyntaxException {
37          VersionJsonParser parser = new VersionJsonParser();
38          final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid.json"));
39  
40          assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/version/10000"), version.getSelf());
41          assertEquals(Long.valueOf(10000), version.getId());
42          assertEquals("1.1", version.getName());
43          assertEquals("Some version", version.getDescription());
44          Assert.assertFalse(version.isReleased());
45          Assert.assertTrue(version.isArchived());
46          Assert.assertThat(version.getReleaseDate(), DateTimeMatcher.isEqual(
47                  new DateTime(2010, 8, 25, 0, 0, 0, 0, DateTimeZone.forOffsetHours(2))));
48      }
49  
50      @Test
51      public void testParseNoReleaseDate() throws JSONException, URISyntaxException {
52          VersionJsonParser parser = new VersionJsonParser();
53          final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid2-no-releaseDate.json"));
54  
55          assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/version/10000"), version.getSelf());
56          assertEquals(Long.valueOf(10000), version.getId());
57          assertEquals("1.1abc", version.getName());
58          assertNull(version.getDescription());
59          Assert.assertTrue(version.isReleased());
60          Assert.assertFalse(version.isArchived());
61          assertNull(version.getReleaseDate());
62      }
63  
64      @Test
65      public void testParseNoId() throws JSONException, URISyntaxException {
66          VersionJsonParser parser = new VersionJsonParser();
67          final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid-no-id.json"));
68  
69          assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/version/10000"), version.getSelf());
70          assertNull(version.getId());
71          assertEquals("1.1", version.getName());
72          assertEquals("Some version", version.getDescription());
73          Assert.assertFalse(version.isReleased());
74          Assert.assertTrue(version.isArchived());
75          Assert.assertThat(version.getReleaseDate(), DateTimeMatcher.isEqual(
76                  new DateTime(2010, 8, 25, 0, 0, 0, 0, DateTimeZone.forOffsetHours(2))));
77      }
78  
79      @Test
80      public void testParseNoDescription() throws JSONException, URISyntaxException {
81          VersionJsonParser parser = new VersionJsonParser();
82          final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid-no-description.json"));
83  
84          assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/version/10000"), version.getSelf());
85          assertEquals(Long.valueOf(10000), version.getId());
86          assertEquals("1.1", version.getName());
87          assertNull(version.getDescription());
88          Assert.assertFalse(version.isReleased());
89          Assert.assertTrue(version.isArchived());
90          Assert.assertThat(version.getReleaseDate(), DateTimeMatcher.isEqual(
91                  new DateTime(2010, 8, 25, 0, 0, 0, 0, DateTimeZone.forOffsetHours(2))));
92      }
93  
94  }