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.api.domain.Filter;
20 import org.apache.commons.lang.StringUtils;
21 import org.codehaus.jettison.json.JSONException;
22 import org.codehaus.jettison.json.JSONObject;
23 import org.junit.Test;
24
25 import static com.atlassian.jira.rest.client.TestUtil.toUri;
26 import static com.atlassian.jira.rest.client.internal.json.TestConstants.USER_ADMIN_BASIC_LATEST;
27 import static org.hamcrest.MatcherAssert.assertThat;
28 import static org.hamcrest.Matchers.anyOf;
29 import static org.hamcrest.Matchers.is;
30
31 public class FilterJsonParserTest {
32
33 @Test
34 public void testParseWithoutShares() throws Exception {
35 final Filter actual = parseFilter("/json/filter/valid-no-shares.json");
36 final Filter expectedOld = new Filter(toUri("http://localhost:8090/jira/rest/api/latest/filter/10000"), 10000L,
37 "Bugs in Test project", StringUtils.EMPTY, "project = TST AND issuetype = Bug",
38 toUri("http://localhost:8090/jira/secure/IssueNavigator.jspa?mode=hide&requestId=10000"),
39 toUri("http://localhost:8090/jira/rest/api/latest/search?jql=project+%3D+TST+AND+issuetype+%3D+Bug"),
40 USER_ADMIN_BASIC_LATEST, true);
41 final Filter expectedNew = new Filter(toUri("http://localhost:8090/jira/rest/api/latest/filter/10000"), 10000L,
42 "Bugs in Test project", StringUtils.EMPTY, "project = TST AND issuetype = Bug",
43 toUri("http://localhost:8090/jira/secure/issues/?filter=10000"),
44 toUri("http://localhost:8090/jira/rest/api/latest/search?jql=project+%3D+TST+AND+issuetype+%3D+Bug"),
45 USER_ADMIN_BASIC_LATEST, true);
46 assertThat(actual, anyOf(is(expectedOld), is(expectedNew)));
47 }
48
49 @Test
50 public void testParseWithShares() throws Exception {
51 final Filter actual = parseFilter("/json/filter/valid-with-shares.json");
52 final Filter expectedOld = new Filter(toUri("http://localhost:8090/jira/rest/api/latest/filter/10003"), 10003L,
53 "Resolved bugs", "For testing shares.", "issuetype = Bug AND status = Resolved",
54 toUri("http://localhost:8090/jira/secure/IssueNavigator.jspa?mode=hide&requestId=10003"),
55 toUri("http://localhost:8090/jira/rest/api/latest/search?jql=issuetype+%3D+Bug+AND+status+%3D+Resolved"),
56 USER_ADMIN_BASIC_LATEST, true);
57 final Filter expectedNew = new Filter(toUri("http://localhost:8090/jira/rest/api/latest/filter/10003"), 10003L,
58 "Resolved bugs", "For testing shares.", "issuetype = Bug AND status = Resolved",
59 toUri("http://localhost:8090/jira/secure/issues/?filter=10003"),
60 toUri("http://localhost:8090/jira/rest/api/latest/search?jql=issuetype+%3D+Bug+AND+status+%3D+Resolved"),
61 USER_ADMIN_BASIC_LATEST, true);
62 assertThat(actual, anyOf(is(expectedOld), is(expectedNew)));
63 }
64
65 @Test
66 public void testParseNotFavourite() throws Exception {
67 final Filter actual = parseFilter("/json/filter/valid-not-favourite.json");
68 final Filter expectedOld = new Filter(toUri("http://localhost:8090/jira/rest/api/latest/filter/10001"), 10001L,
69 "Tasks in Test project - not favuorite filter", StringUtils.EMPTY, "project = TST AND issuetype = Task",
70 toUri("http://localhost:8090/jira/secure/IssueNavigator.jspa?mode=hide&requestId=10001"),
71 toUri("http://localhost:8090/jira/rest/api/latest/search?jql=project+%3D+TST+AND+issuetype+%3D+Task"),
72 USER_ADMIN_BASIC_LATEST, false);
73 final Filter expectedNew = new Filter(toUri("http://localhost:8090/jira/rest/api/latest/filter/10001"), 10001L,
74 "Tasks in Test project - not favuorite filter", StringUtils.EMPTY, "project = TST AND issuetype = Task",
75 toUri("http://localhost:8090/jira/issues/?filter=10001"),
76 toUri("http://localhost:8090/jira/rest/api/latest/search?jql=project+%3D+TST+AND+issuetype+%3D+Task"),
77 USER_ADMIN_BASIC_LATEST, false);
78 assertThat(actual, anyOf(is(expectedOld), is(expectedNew)));
79 }
80
81 @Test
82 public void testParseWitSubscriptionsBugJRA30958() throws Exception {
83 final Filter actual = parseFilter("/json/filter/valid-with-subscriptions-bug-JRA-30958-subscription-have-no-elements.json");
84 final Filter expectedOld = new Filter(toUri("http://localhost:8090/jira/rest/api/latest/filter/10004"), 10004L,
85 "All in project Test", "For testing subscriptions.", "project = TST",
86 toUri("http://localhost:8090/jira/secure/IssueNavigator.jspa?mode=hide&requestId=10004"),
87 toUri("http://localhost:8090/jira/rest/api/latest/search?jql=project+%3D+TST"),
88 USER_ADMIN_BASIC_LATEST, true);
89 final Filter expectedNew = new Filter(toUri("http://localhost:8090/jira/rest/api/latest/filter/10004"), 10004L,
90 "All in project Test", "For testing subscriptions.", "project = TST",
91 toUri("http://localhost:8090/jira/issues/?filter=10004"),
92 toUri("http://localhost:8090/jira/rest/api/latest/search?jql=project+%3D+TST"),
93 USER_ADMIN_BASIC_LATEST, true);
94 assertThat(actual, anyOf(is(expectedOld), is(expectedNew)));
95 }
96
97 private Filter parseFilter(String resourcePath) throws JSONException {
98 final JSONObject issueJson = ResourceUtil.getJsonObjectFromResource(resourcePath);
99 final FilterJsonParser parser = new FilterJsonParser();
100 return parser.parse(issueJson);
101 }
102 }