1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.jira.rest.client.internal.json;
18
19 import com.atlassian.jira.rest.client.DateTimeMatcher;
20 import com.atlassian.jira.rest.client.domain.Version;
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
32 public class VersionJsonParserTest {
33
34 @Test
35 public void testParse() throws JSONException, URISyntaxException {
36 VersionJsonParser parser = new VersionJsonParser();
37 final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid.json"));
38
39 assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/version/10000"), version.getSelf());
40 assertEquals("1.1", version.getName());
41 assertEquals("Some version", version.getDescription());
42 Assert.assertFalse(version.isReleased());
43 Assert.assertTrue(version.isArchived());
44 Assert.assertThat(version.getReleaseDate(), DateTimeMatcher.isEqual(
45 new DateTime(2010, 8, 25, 0, 0, 0, 0, DateTimeZone.forOffsetHours(2))));
46 }
47
48 @Test
49 public void testParse2() throws JSONException, URISyntaxException {
50 VersionJsonParser parser = new VersionJsonParser();
51 final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid2-no-releaseDate.json"));
52
53 assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/version/10000"), version.getSelf());
54 assertEquals("1.1abc", version.getName());
55 Assert.assertNull(version.getDescription());
56 Assert.assertTrue(version.isReleased());
57 Assert.assertFalse(version.isArchived());
58 Assert.assertNull(version.getReleaseDate());
59 }
60
61 @Test
62 public void testParseNoDescription() throws JSONException, URISyntaxException {
63 VersionJsonParser parser = new VersionJsonParser();
64 final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid-no-description.json"));
65
66 assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/version/10000"), version.getSelf());
67 assertEquals("1.1", version.getName());
68 Assert.assertNull(version.getDescription());
69 Assert.assertFalse(version.isReleased());
70 Assert.assertTrue(version.isArchived());
71 Assert.assertThat(version.getReleaseDate(), DateTimeMatcher.isEqual(
72 new DateTime(2010, 8, 25, 0, 0, 0, 0, DateTimeZone.forOffsetHours(2))));
73 }
74
75 }