1 package org.apache.maven.plugin.jira;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23 import org.apache.maven.plugin.logging.SystemStreamLog;
24
25 import java.io.UnsupportedEncodingException;
26 import java.net.URLEncoder;
27
28
29
30
31
32
33
34
35 public class JqlQueryBuilderTestCase
36 extends TestCase
37 {
38 private static final String ENCODING = "UTF-8";
39
40 public void testEmptyQuery()
41 {
42 String actual = new JqlQueryBuilder( new SystemStreamLog() ).build();
43 String expected = "";
44 assertEquals( expected, actual );
45 }
46
47 public void testSingleParameterValue()
48 throws UnsupportedEncodingException
49 {
50 String expected = URLEncoder.encode( "project = DOXIA", ENCODING );
51
52 String actual = createBuilder().project( "DOXIA" ).build();
53 assertEquals( expected, actual );
54 }
55
56 public void testFixVersion()
57 throws UnsupportedEncodingException
58 {
59 String expected = URLEncoder.encode( "fixVersion = \"1.0\"", ENCODING );
60
61 String actual = createBuilder().fixVersion( "1.0" ).build();
62 assertEquals( expected, actual );
63 }
64
65 public void testFixVersionCombinedWithOtherParameters()
66 throws UnsupportedEncodingException
67 {
68 String expected = URLEncoder.encode( "project = DOXIA AND fixVersion = \"1.0\"", ENCODING );
69
70 String actual = createBuilder().project( "DOXIA" ).fixVersion( "1.0" ).build();
71 assertEquals( expected, actual );
72 }
73
74 public void testSingleParameterSingleValue()
75 throws UnsupportedEncodingException
76 {
77 String expected = URLEncoder.encode( "priority in (Blocker)", ENCODING );
78
79 String actual = createBuilder().priorityIds( "Blocker" ).build();
80 assertEquals( expected, actual );
81
82 actual = createBuilder().priorityIds( " Blocker " ).build();
83 assertEquals( expected, actual );
84 }
85
86 public void testSingleParameterMultipleValues()
87 throws UnsupportedEncodingException
88 {
89 String expected = URLEncoder.encode( "priority in (Blocker, Critical, Major)", ENCODING );
90
91 String actual = createBuilder().priorityIds( "Blocker,Critical,Major" ).build();
92 assertEquals( expected, actual );
93
94 actual = createBuilder().priorityIds( " Blocker , Critical, Major" ).build();
95 assertEquals( expected, actual );
96 }
97
98 public void testMultipleParameterCombinedWithAND()
99 throws UnsupportedEncodingException
100 {
101 String expected = URLEncoder.encode( "priority in (Blocker) AND status in (Resolved)", ENCODING );
102
103 String actual = createBuilder().priorityIds( "Blocker" ).statusIds( "Resolved" ).build();
104 assertEquals( expected, actual );
105 }
106
107 public void testValueWithSpacesAreQuoted()
108 throws UnsupportedEncodingException
109 {
110 String expected = URLEncoder.encode( "status in (\"In Progress\")", ENCODING );
111
112 String actual = createBuilder().statusIds( "In Progress" ).build();
113 assertEquals( expected, actual );
114 }
115
116 public void testSortSingleRowAscending()
117 throws UnsupportedEncodingException
118 {
119 String expected = URLEncoder.encode( "project = DOXIA ORDER BY key ASC", ENCODING );
120
121 String actual = createBuilder().project( "DOXIA" ).sortColumnNames( "key" ).build();
122 assertEquals( expected, actual );
123
124 actual = createBuilder().project( "DOXIA" ).sortColumnNames( "key ASC" ).build();
125 assertEquals( expected, actual );
126
127 actual = createBuilder().project( "DOXIA" ).sortColumnNames( " key ASC " ).build();
128 assertEquals( expected, actual );
129 }
130
131 public void testSortSingleDescending()
132 throws UnsupportedEncodingException
133 {
134 String expected = URLEncoder.encode( "project = DOXIA ORDER BY key DESC", ENCODING );
135
136 String actual = createBuilder().project( "DOXIA" ).sortColumnNames( "key DESC" ).build();
137 assertEquals( expected, actual );
138
139 actual = createBuilder().project( "DOXIA" ).sortColumnNames( " key DESC " ).build();
140 assertEquals( expected, actual );
141 }
142
143 public void testSortMultipleColumns()
144 throws UnsupportedEncodingException
145 {
146 String expected =
147 URLEncoder.encode( "project = DOXIA ORDER BY key ASC, assignee DESC, reporter ASC", ENCODING );
148
149 String actual =
150 createBuilder().project( "DOXIA" ).sortColumnNames( "key ASC,assignee DESC, reporter ASC" ).build();
151 assertEquals( expected, actual );
152 }
153
154 public void testOrderByIsLastElement()
155 throws UnsupportedEncodingException
156 {
157 String expected =
158 URLEncoder.encode( "project = DOXIA ORDER BY key ASC, assignee DESC, reporter ASC", ENCODING );
159
160 String actual =
161 createBuilder().sortColumnNames( "key ASC,assignee DESC, reporter ASC" ).project( "DOXIA" ).build();
162 assertEquals( expected, actual );
163 }
164
165 private JiraQueryBuilder createBuilder()
166 {
167 return new JqlQueryBuilder( new SystemStreamLog() );
168 }
169 }