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.TestUtil;
20 import com.atlassian.jira.rest.client.domain.Project;
21 import com.google.common.collect.Iterables;
22 import org.codehaus.jettison.json.JSONException;
23 import org.joda.time.DateMidnight;
24 import org.junit.Test;
25
26 import static com.atlassian.jira.rest.client.IterableMatcher.hasOnlyElements;
27 import static org.junit.Assert.*;
28
29 public class ProjectJsonParserTest {
30 private final ProjectJsonParser parser = new ProjectJsonParser();
31
32 @Test
33 public void testParse() throws Exception {
34 final Project project = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/project/valid.json"));
35 assertEquals(TestUtil.toUri("http://localhost:8090/jira/rest/api/latest/project/TST"), project.getSelf());
36 assertEquals("This is my description here.\r\nAnother line.", project.getDescription());
37 assertEquals(TestConstants.USER_ADMIN, project.getLead());
38 assertEquals("http://example.com", project.getUri().toString());
39 assertEquals("TST", project.getKey());
40 assertThat(project.getVersions(), hasOnlyElements(TestConstants.VERSION_1, TestConstants.VERSION_1_1));
41 assertThat(project.getComponents(), hasOnlyElements(TestConstants.BCOMPONENT_A, TestConstants.BCOMPONENT_B));
42 }
43
44 @Test
45 public void testParseProjectWithNoUrl() throws JSONException {
46 final Project project = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/project/project-no-url.json"));
47 assertEquals("MYT", project.getKey());
48 assertNull(project.getUri());
49 assertNull(project.getDescription());
50 }
51
52 @Test
53 public void testParseProjectInJira4x4() throws JSONException {
54 final Project project = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/project/project-jira-4-4.json"));
55 assertEquals("TST", project.getKey());
56 assertEquals(new DateMidnight(2010, 8, 25).toInstant(), Iterables.getLast(project.getVersions()).getReleaseDate().toInstant());
57 }
58 }