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()
53 .project( "DOXIA" )
54 .build();
55 assertEquals( expected, actual );
56 }
57
58 public void testFixVersion()
59 throws UnsupportedEncodingException
60 {
61 String expected = URLEncoder.encode( "fixVersion = \"1.0\"",
62 ENCODING );
63
64 String actual = createBuilder()
65 .fixVersion( "1.0" )
66 .build();
67 assertEquals( expected, actual );
68 }
69
70 public void testFixVersionCombinedWithOtherParameters()
71 throws UnsupportedEncodingException
72 {
73 String expected = URLEncoder.encode( "project = DOXIA AND fixVersion = \"1.0\"",
74 ENCODING );
75
76 String actual = createBuilder()
77 .project( "DOXIA" )
78 .fixVersion( "1.0" )
79 .build();
80 assertEquals( expected, actual );
81 }
82
83 public void testSingleParameterSingleValue()
84 throws UnsupportedEncodingException
85 {
86 String expected = URLEncoder.encode( "priority in (Blocker)",
87 ENCODING );
88
89 String actual = createBuilder()
90 .priorityIds( "Blocker" )
91 .build();
92 assertEquals( expected, actual );
93
94 actual = createBuilder()
95 .priorityIds( " Blocker " )
96 .build();
97 assertEquals( expected, actual );
98 }
99
100 public void testSingleParameterMultipleValues()
101 throws UnsupportedEncodingException
102 {
103 String expected = URLEncoder.encode( "priority in (Blocker, Critical, Major)",
104 ENCODING );
105
106 String actual = createBuilder()
107 .priorityIds( "Blocker,Critical,Major" )
108 .build();
109 assertEquals( expected, actual );
110
111 actual = createBuilder()
112 .priorityIds( " Blocker , Critical, Major" )
113 .build();
114 assertEquals( expected, actual );
115 }
116
117 public void testMultipleParameterCombinedWithAND()
118 throws UnsupportedEncodingException
119 {
120 String expected = URLEncoder.encode( "priority in (Blocker) AND status in (Resolved)",
121 ENCODING );
122
123 String actual = createBuilder()
124 .priorityIds( "Blocker" )
125 .statusIds( "Resolved" )
126 .build();
127 assertEquals( expected, actual );
128 }
129
130 public void testValueWithSpacesAreQuoted()
131 throws UnsupportedEncodingException
132 {
133 String expected = URLEncoder.encode( "status in (\"In Progress\")",
134 ENCODING );
135
136 String actual = createBuilder()
137 .statusIds( "In Progress" )
138 .build();
139 assertEquals( expected, actual );
140 }
141
142 public void testSortSingleRowAscending()
143 throws UnsupportedEncodingException
144 {
145 String expected = URLEncoder.encode( "project = DOXIA ORDER BY key ASC",
146 ENCODING );
147
148 String actual = createBuilder()
149 .project( "DOXIA" )
150 .sortColumnNames( "key" )
151 .build();
152 assertEquals( expected, actual );
153
154 actual = createBuilder()
155 .project( "DOXIA" )
156 .sortColumnNames( "key ASC" )
157 .build();
158 assertEquals( expected, actual );
159
160 actual = createBuilder()
161 .project( "DOXIA" )
162 .sortColumnNames( " key ASC " )
163 .build();
164 assertEquals( expected, actual );
165 }
166
167 public void testSortSingleDescending()
168 throws UnsupportedEncodingException
169 {
170 String expected = URLEncoder.encode( "project = DOXIA ORDER BY key DESC",
171 ENCODING );
172
173 String actual = createBuilder()
174 .project( "DOXIA" )
175 .sortColumnNames( "key DESC" )
176 .build();
177 assertEquals( expected, actual );
178
179 actual = createBuilder()
180 .project( "DOXIA" )
181 .sortColumnNames( " key DESC " )
182 .build();
183 assertEquals( expected, actual );
184 }
185
186 public void testSortMultipleColumns()
187 throws UnsupportedEncodingException
188 {
189 String expected = URLEncoder.encode( "project = DOXIA ORDER BY key ASC, assignee DESC, reporter ASC",
190 ENCODING );
191
192 String actual = createBuilder()
193 .project( "DOXIA" )
194 .sortColumnNames( "key ASC,assignee DESC, reporter ASC" )
195 .build();
196 assertEquals( expected, actual );
197 }
198
199 public void testOrderByIsLastElement()
200 throws UnsupportedEncodingException
201 {
202 String expected = URLEncoder.encode( "project = DOXIA ORDER BY key ASC, assignee DESC, reporter ASC",
203 ENCODING );
204
205 String actual = createBuilder()
206 .sortColumnNames( "key ASC,assignee DESC, reporter ASC" )
207 .project( "DOXIA" )
208 .build();
209 assertEquals( expected, actual );
210 }
211
212 private JiraQueryBuilder createBuilder()
213 {
214 return new JqlQueryBuilder( new SystemStreamLog() );
215 }
216 }