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 assertNull(project.getName());
43 }
44
45 @Test
46 public void testParseProjectWithNoUrl() throws JSONException {
47 final Project project = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/project/project-no-url.json"));
48 assertEquals("MYT", project.getKey());
49 assertNull(project.getUri());
50 assertNull(project.getDescription());
51 }
52
53 @Test
54 public void testParseProjectInJira4x4() throws JSONException {
55 final Project project = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/project/project-jira-4-4.json"));
56 assertEquals("TST", project.getKey());
57 assertEquals(new DateMidnight(2010, 8, 25).toInstant(), Iterables.getLast(project.getVersions()).getReleaseDate().toInstant());
58 assertEquals("Test Project", project.getName());
59 }
60 }