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.Comment;
21 import com.atlassian.jira.rest.client.domain.Visibility;
22 import org.codehaus.jettison.json.JSONException;
23 import org.codehaus.jettison.json.JSONObject;
24 import org.junit.Test;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNull;
28
29
30 public class CommentJsonParserTest {
31 @Test
32 public void testParse() throws Exception {
33 final JSONObject commentsJson = ResourceUtil.getJsonObjectFromResource("/json/comment/valid.json");
34 final CommentJsonParser parser = new CommentJsonParser();
35
36 final JSONObject comment1Json = commentsJson.getJSONArray("value").getJSONObject(0);
37 final Comment comment1 = parser.parse(comment1Json);
38 assertEquals("some comment", comment1.getBody());
39 assertEquals(TestConstants.USER_ADMIN, comment1.getAuthor());
40 assertEquals(TestConstants.USER_ADMIN, comment1.getUpdateAuthor());
41 assertEquals(TestUtil.toDateTime("2010-08-17T16:40:57.791+0200"), comment1.getCreationDate());
42 assertEquals(TestUtil.toDateTime("2010-08-17T16:40:57.791+0200"), comment1.getUpdateDate());
43 assertEquals(TestUtil.toUri("http://localhost:8090/jira/rest/api/latest/comment/10020"), comment1.getSelf());
44 assertEquals(Visibility.role("Administrators"), comment1.getVisibility());
45
46 final JSONObject comment3Json = commentsJson.getJSONArray("value").getJSONObject(2);
47 final Comment comment3 = parser.parse(comment3Json);
48 assertEquals(Visibility.group("jira-users"), comment3.getVisibility());
49
50 final JSONObject comment2Json = commentsJson.getJSONArray("value").getJSONObject(1);
51 final Comment comment2 = parser.parse(comment2Json);
52 assertNull(comment2.getVisibility());
53 }
54
55 @Test
56 public void testParseAnonymous() throws JSONException {
57 final CommentJsonParser parser = new CommentJsonParser();
58 final JSONObject json = ResourceUtil.getJsonObjectFromResource("/json/comment/valid-anonymous.json");
59 final JSONObject commentJson = json.getJSONArray("value").getJSONObject(0);
60 final Comment comment = parser.parse(commentJson);
61 assertNull(comment.getAuthor());
62 assertNull(comment.getUpdateAuthor());
63 assertEquals("Comment from anonymous user", comment.getBody());
64
65 }
66 }