|
Lines 25-38
Link Here
|
| 25 |
import org.apache.xmlrpc.XmlRpcException; |
25 |
import org.apache.xmlrpc.XmlRpcException; |
| 26 |
import org.apache.xmlrpc.client.XmlRpcClient; |
26 |
import org.apache.xmlrpc.client.XmlRpcClient; |
| 27 |
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; |
27 |
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; |
|
|
28 |
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils; |
| 29 |
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials; |
| 30 |
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.PrivilegeLevel; |
| 28 |
import org.eclipse.mylar.internal.trac.core.TracHttpClientTransportFactory; |
31 |
import org.eclipse.mylar.internal.trac.core.TracHttpClientTransportFactory; |
| 29 |
|
32 |
|
| 30 |
/** |
33 |
/** |
| 31 |
* Test cases for <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">Trac XML-RPC |
34 |
* Test cases for <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">Trac XML-RPC |
| 32 |
* Plugin</a> API. Revision 848 or higher is required. |
35 |
* Plugin</a> API. Revision 1070 or higher is required. |
| 33 |
* |
36 |
* |
| 34 |
* <p> |
37 |
* <p> |
| 35 |
* This class does not depend on any of the Mylar connector classes. |
38 |
* This class does not depend on any Mylar (connector) classes except for |
|
|
39 |
* TracHttpClientTransportFactory which is needed for initialization of |
| 40 |
* HttpClient. |
| 36 |
* |
41 |
* |
| 37 |
* @author Steffen Pingel |
42 |
* @author Steffen Pingel |
| 38 |
*/ |
43 |
*/ |
|
Lines 48-60
Link Here
|
| 48 |
|
53 |
|
| 49 |
private Random random; |
54 |
private Random random; |
| 50 |
|
55 |
|
|
|
56 |
private ArrayList<Integer> tickets; |
| 57 |
|
| 58 |
@Override |
| 51 |
protected void setUp() throws Exception { |
59 |
protected void setUp() throws Exception { |
| 52 |
super.setUp(); |
60 |
super.setUp(); |
| 53 |
|
61 |
|
| 54 |
random = new Random(); |
62 |
random = new Random(); |
| 55 |
|
63 |
|
| 56 |
createConnection(new URL(Constants.TEST_REPOSITORY1_URL + XMLRPC_URL), |
64 |
Credentials credentials = MylarTestUtils.readCredentials(PrivilegeLevel.ADMIN); |
| 57 |
Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD); |
65 |
createConnection(new URL(Constants.TEST_TRAC_010_URL + XMLRPC_URL), credentials.username, credentials.password); |
|
|
66 |
|
| 67 |
tickets = new ArrayList<Integer>(); |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
protected void tearDown() throws Exception { |
| 72 |
super.tearDown(); |
| 73 |
|
| 74 |
for (int id : tickets) { |
| 75 |
call("ticket.delete", id); |
| 76 |
} |
| 58 |
} |
77 |
} |
| 59 |
|
78 |
|
| 60 |
private void createConnection(URL url, String username, String password) throws Exception { |
79 |
private void createConnection(URL url, String username, String password) throws Exception { |
|
Lines 63-72
Link Here
|
| 63 |
config.setBasicUserName(username); |
82 |
config.setBasicUserName(username); |
| 64 |
config.setBasicPassword(password); |
83 |
config.setBasicPassword(password); |
| 65 |
config.setServerURL(url); |
84 |
config.setServerURL(url); |
| 66 |
|
85 |
|
| 67 |
xmlrpc = new XmlRpcClient(); |
86 |
xmlrpc = new XmlRpcClient(); |
| 68 |
xmlrpc.setConfig(config); |
87 |
xmlrpc.setConfig(config); |
| 69 |
|
88 |
|
| 70 |
TracHttpClientTransportFactory factory = new TracHttpClientTransportFactory(xmlrpc); |
89 |
TracHttpClientTransportFactory factory = new TracHttpClientTransportFactory(xmlrpc); |
| 71 |
xmlrpc.setTransportFactory(factory); |
90 |
xmlrpc.setTransportFactory(factory); |
| 72 |
|
91 |
|
|
Lines 74-81
Link Here
|
| 74 |
// this.password = password; |
93 |
// this.password = password; |
| 75 |
} |
94 |
} |
| 76 |
|
95 |
|
| 77 |
protected void tearDown() throws Exception { |
96 |
private int createTicket(String summary, String description, Map attributes) throws XmlRpcException, IOException { |
| 78 |
super.tearDown(); |
97 |
int id = (Integer) call("ticket.create", summary, description, attributes); |
|
|
98 |
tickets.add(id); |
| 99 |
return id; |
| 79 |
} |
100 |
} |
| 80 |
|
101 |
|
| 81 |
private Object call(String method, Object... parameters) throws XmlRpcException, IOException { |
102 |
private Object call(String method, Object... parameters) throws XmlRpcException, IOException { |
|
Lines 101-114
Link Here
|
| 101 |
} |
122 |
} |
| 102 |
|
123 |
|
| 103 |
call(module + ".create", "foo", "bar"); |
124 |
call(module + ".create", "foo", "bar"); |
|
|
125 |
try { |
| 126 |
assertHasValue((Object[]) call(module + ".getAll"), "foo"); |
| 127 |
assertEquals("bar", (String) (call(module + ".get", "foo"))); |
| 104 |
|
128 |
|
| 105 |
assertHasValue((Object[]) call(module + ".getAll"), "foo"); |
129 |
call(module + ".update", "foo", "baz"); |
| 106 |
assertEquals("bar", (String) (call(module + ".get", "foo"))); |
130 |
assertEquals("baz", (String) (call(module + ".get", "foo"))); |
| 107 |
|
131 |
} finally { |
| 108 |
call(module + ".update", "foo", "baz"); |
132 |
call(module + ".delete", "foo"); |
| 109 |
assertEquals("baz", (String) (call(module + ".get", "foo"))); |
133 |
} |
| 110 |
|
|
|
| 111 |
call(module + ".delete", "foo"); |
| 112 |
} |
134 |
} |
| 113 |
|
135 |
|
| 114 |
private Object createValue(Object fieldName, Object clazz) { |
136 |
private Object createValue(Object fieldName, Object clazz) { |
|
Lines 140-162
Link Here
|
| 140 |
|
162 |
|
| 141 |
call(module + ".create", "foo", attributes); |
163 |
call(module + ".create", "foo", attributes); |
| 142 |
|
164 |
|
| 143 |
assertHasValue((Object[]) call(module + ".getAll"), "foo"); |
165 |
try { |
| 144 |
Map values = (Map) call(module + ".get", "foo"); |
166 |
assertHasValue((Object[]) call(module + ".getAll"), "foo"); |
| 145 |
for (String attribute : attributes.keySet()) { |
167 |
Map values = (Map) call(module + ".get", "foo"); |
| 146 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
168 |
for (String attribute : attributes.keySet()) { |
| 147 |
} |
169 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
|
|
170 |
} |
| 148 |
|
171 |
|
| 149 |
for (int i = 0; i < fields.length; i += 2) { |
172 |
for (int i = 0; i < fields.length; i += 2) { |
| 150 |
attributes.put((String) fields[i], createValue(fields[i], fields[i + 1])); |
173 |
attributes.put((String) fields[i], createValue(fields[i], fields[i + 1])); |
| 151 |
} |
174 |
} |
| 152 |
|
175 |
|
| 153 |
call(module + ".update", "foo", attributes); |
176 |
call(module + ".update", "foo", attributes); |
| 154 |
values = (Map) call(module + ".get", "foo"); |
177 |
values = (Map) call(module + ".get", "foo"); |
| 155 |
for (String attribute : attributes.keySet()) { |
178 |
for (String attribute : attributes.keySet()) { |
| 156 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
179 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
|
|
180 |
} |
| 181 |
} finally { |
| 182 |
call(module + ".delete", "foo"); |
| 157 |
} |
183 |
} |
| 158 |
|
|
|
| 159 |
call(module + ".delete", "foo"); |
| 160 |
} |
184 |
} |
| 161 |
|
185 |
|
| 162 |
public void testMilestoneDate() throws XmlRpcException, IOException { |
186 |
public void testMilestoneDate() throws XmlRpcException, IOException { |
|
Lines 195-202
Link Here
|
| 195 |
assertTicketHasAttributes(attributes, id, ticket, true); |
219 |
assertTicketHasAttributes(attributes, id, ticket, true); |
| 196 |
} |
220 |
} |
| 197 |
|
221 |
|
| 198 |
private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket, |
222 |
private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket, boolean newTicket) { |
| 199 |
boolean newTicket) { |
|
|
| 200 |
assertEquals(id, ticket[0]); |
223 |
assertEquals(id, ticket[0]); |
| 201 |
assertTrue(ticket[1] instanceof Integer); // time created |
224 |
assertTrue(ticket[1] instanceof Integer); // time created |
| 202 |
// time changed |
225 |
// time changed |
|
Lines 215-229
Link Here
|
| 215 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
238 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 216 |
attributes.put("type", "task"); |
239 |
attributes.put("type", "task"); |
| 217 |
attributes.put("status", "closed"); |
240 |
attributes.put("status", "closed"); |
| 218 |
int id = (Integer) call("ticket.create", "summary", "description", attributes); |
241 |
int id = createTicket("summary", "description", attributes); |
| 219 |
|
242 |
|
| 220 |
attributes.put("summary", "summary"); |
243 |
attributes.put("summary", "summary"); |
| 221 |
attributes.put("description", "description"); |
244 |
attributes.put("description", "description"); |
| 222 |
|
245 |
|
| 223 |
Object[] ticket = (Object[]) call("ticket.get", id); |
246 |
Object[] ticket = (Object[]) call("ticket.get", id); |
| 224 |
assertTicketHasAttributes(attributes, id, ticket); |
247 |
assertTicketHasAttributes(attributes, id, ticket); |
| 225 |
|
|
|
| 226 |
call("ticket.delete", id); |
| 227 |
} |
248 |
} |
| 228 |
|
249 |
|
| 229 |
public void testGetTicketNonExistant() throws XmlRpcException, IOException { |
250 |
public void testGetTicketNonExistant() throws XmlRpcException, IOException { |
|
Lines 243-261
Link Here
|
| 243 |
|
264 |
|
| 244 |
public void testGetTicketUmlaute() throws XmlRpcException, IOException { |
265 |
public void testGetTicketUmlaute() throws XmlRpcException, IOException { |
| 245 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
266 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 246 |
int id = (Integer) call("ticket.create", "summaryäÖÜ", "ßßß", attributes); |
267 |
int id = createTicket("summaryäÖÜ", "ßßß", attributes); |
| 247 |
|
268 |
|
| 248 |
attributes.put("summary", "summaryäÖÜ"); |
269 |
attributes.put("summary", "summaryäÖÜ"); |
| 249 |
attributes.put("description", "ßßß"); |
270 |
attributes.put("description", "ßßß"); |
| 250 |
|
271 |
|
| 251 |
Object[] ticket = (Object[]) call("ticket.get", id); |
272 |
Object[] ticket = (Object[]) call("ticket.get", id); |
| 252 |
assertTicketHasAttributes(attributes, id, ticket); |
273 |
assertTicketHasAttributes(attributes, id, ticket); |
| 253 |
|
|
|
| 254 |
call("ticket.delete", id); |
| 255 |
} |
274 |
} |
| 256 |
|
275 |
|
| 257 |
public void testUpdateTicket() throws XmlRpcException, IOException { |
276 |
public void testUpdateTicket() throws XmlRpcException, IOException { |
| 258 |
int id = (Integer) call("ticket.create", "summary", "description", new Hashtable()); |
277 |
int id = createTicket("summary", "description", new Hashtable()); |
| 259 |
|
278 |
|
| 260 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
279 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 261 |
attributes.put("summary", "changed"); |
280 |
attributes.put("summary", "changed"); |
|
Lines 268-281
Link Here
|
| 268 |
for (String attribute : attributes.keySet()) { |
287 |
for (String attribute : attributes.keySet()) { |
| 269 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
288 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
| 270 |
} |
289 |
} |
| 271 |
|
|
|
| 272 |
call("ticket.delete", id); |
| 273 |
} |
290 |
} |
| 274 |
|
291 |
|
| 275 |
public void testTicketCustomFields() throws XmlRpcException, IOException { |
292 |
public void testTicketCustomFields() throws XmlRpcException, IOException { |
| 276 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
293 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 277 |
attributes.put("custom_text_field", "myvalue"); |
294 |
attributes.put("custom_text_field", "myvalue"); |
| 278 |
int id = (Integer) call("ticket.create", "summary", "description", attributes); |
295 |
int id = createTicket("summary", "description", attributes); |
| 279 |
|
296 |
|
| 280 |
// check for default values |
297 |
// check for default values |
| 281 |
attributes.put("custom_checkbox_field", "1"); |
298 |
attributes.put("custom_checkbox_field", "1"); |
|
Lines 296-307
Link Here
|
| 296 |
|
313 |
|
| 297 |
ticket = (Object[]) call("ticket.get", id); |
314 |
ticket = (Object[]) call("ticket.get", id); |
| 298 |
assertTicketHasAttributes(attributes, id, ticket, false); |
315 |
assertTicketHasAttributes(attributes, id, ticket, false); |
| 299 |
|
|
|
| 300 |
call("ticket.delete", id); |
| 301 |
} |
316 |
} |
| 302 |
|
317 |
|
| 303 |
public void testGetChangeLog() throws XmlRpcException, IOException { |
318 |
public void testGetChangeLog() throws XmlRpcException, IOException { |
| 304 |
int id = (Integer) call("ticket.create", "summary", "description", new Hashtable()); |
319 |
int id = createTicket("summary", "description", new Hashtable()); |
| 305 |
|
320 |
|
| 306 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
321 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 307 |
attributes.put("summary", "changed"); |
322 |
attributes.put("summary", "changed"); |
|
Lines 314-326
Link Here
|
| 314 |
assertEquals("summary", entry[2]); // field |
329 |
assertEquals("summary", entry[2]); // field |
| 315 |
assertEquals("summary", entry[3]); // old value |
330 |
assertEquals("summary", entry[3]); // old value |
| 316 |
assertEquals("changed", entry[4]); // new value |
331 |
assertEquals("changed", entry[4]); // new value |
| 317 |
|
|
|
| 318 |
call("ticket.delete", id); |
| 319 |
} |
332 |
} |
| 320 |
|
333 |
|
| 321 |
public void testMultiGetTicket() throws XmlRpcException, IOException { |
334 |
public void testMultiGetTicket() throws XmlRpcException, IOException { |
| 322 |
int id1 = (Integer) call("ticket.create", "summary1", "description1", new Hashtable()); |
335 |
int id1 = createTicket("summary1", "description1", new Hashtable()); |
| 323 |
int id2 = (Integer) call("ticket.create", "summary2", "description2", new Hashtable()); |
336 |
int id2 = createTicket("summary2", "description2", new Hashtable()); |
| 324 |
|
337 |
|
| 325 |
List<Map> calls = new ArrayList<Map>(); |
338 |
List<Map> calls = new ArrayList<Map>(); |
| 326 |
calls.add(createMultiCall("ticket.get", id1)); |
339 |
calls.add(createMultiCall("ticket.get", id1)); |
|
Lines 338-350
Link Here
|
| 338 |
attributes.put("summary", "summary2"); |
351 |
attributes.put("summary", "summary2"); |
| 339 |
attributes.put("description", "description2"); |
352 |
attributes.put("description", "description2"); |
| 340 |
assertTicketHasAttributes(attributes, id2, ticket); |
353 |
assertTicketHasAttributes(attributes, id2, ticket); |
| 341 |
|
|
|
| 342 |
call("ticket.delete", id1); |
| 343 |
call("ticket.delete", id2); |
| 344 |
} |
354 |
} |
| 345 |
|
355 |
|
| 346 |
public void testAttachment() throws XmlRpcException, IOException { |
356 |
public void testAttachment() throws XmlRpcException, IOException { |
| 347 |
int id = (Integer) call("ticket.create", "summary", "description", new Hashtable()); |
357 |
int id = createTicket("summary", "description", new Hashtable()); |
| 348 |
|
358 |
|
| 349 |
String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true); |
359 |
String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true); |
| 350 |
// the returned filename may differ, since another ticket may have an |
360 |
// the returned filename may differ, since another ticket may have an |
|
Lines 371-382
Link Here
|
| 371 |
assertEquals(2, ret.length); |
381 |
assertEquals(2, ret.length); |
| 372 |
assertHasValue(ret, filename); |
382 |
assertHasValue(ret, filename); |
| 373 |
assertHasValue(ret, filename3); |
383 |
assertHasValue(ret, filename3); |
| 374 |
|
|
|
| 375 |
call("ticket.delete", id); |
| 376 |
} |
384 |
} |
| 377 |
|
385 |
|
| 378 |
public void testDeleteAttachment() throws XmlRpcException, IOException { |
386 |
public void testDeleteAttachment() throws XmlRpcException, IOException { |
| 379 |
int id = (Integer) call("ticket.create", "summary", "description", new Hashtable()); |
387 |
int id = createTicket("summary", "description", new Hashtable()); |
| 380 |
|
388 |
|
| 381 |
String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true); |
389 |
String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true); |
| 382 |
|
390 |
|
|
Lines 388-440
Link Here
|
| 388 |
|
396 |
|
| 389 |
ret = (Object[]) call("ticket.listAttachments", id); |
397 |
ret = (Object[]) call("ticket.listAttachments", id); |
| 390 |
assertEquals(0, ret.length); |
398 |
assertEquals(0, ret.length); |
| 391 |
|
|
|
| 392 |
call("ticket.delete", id); |
| 393 |
} |
399 |
} |
| 394 |
|
400 |
|
| 395 |
public void testQuery() throws XmlRpcException, IOException { |
401 |
public void testQuery() throws XmlRpcException, IOException { |
| 396 |
Object[] ret = (Object[]) call("ticket.query", "summary~=foo|bar|baz|summary|ticket"); |
402 |
Object[] ret = (Object[]) call("ticket.query", "summary~=foo|bar|baz"); |
| 397 |
for (Object id : ret) { |
403 |
for (Object id : ret) { |
| 398 |
call("ticket.delete", (Integer) id); |
404 |
call("ticket.delete", (Integer) id); |
| 399 |
} |
405 |
} |
| 400 |
|
406 |
|
| 401 |
int id1 = (Integer) call("ticket.create", "foobarsummary1", "description", new Hashtable()); |
407 |
int id1 = createTicket("foobarsum1", "description", new Hashtable()); |
| 402 |
int id2 = (Integer) call("ticket.create", "foobaz summary2", "description", new Hashtable()); |
408 |
int id2 = createTicket("foobaz sum2", "description", new Hashtable()); |
| 403 |
int id3 = (Integer) call("ticket.create", "ticket3", "description3", new Hashtable()); |
409 |
int id3 = createTicket("foobarbaz3", "foobarbaz description3", new Hashtable()); |
| 404 |
|
410 |
|
| 405 |
ret = (Object[]) call("ticket.query", "summary=foobarsummary1|foobaz summary2"); |
411 |
ret = (Object[]) call("ticket.query", "summary=foobarsum1|foobaz sum2"); |
| 406 |
assertEquals(2, ret.length); |
412 |
assertEquals(2, ret.length); |
| 407 |
assertEquals(id1, ret[0]); |
413 |
assertEquals(id1, ret[0]); |
| 408 |
assertEquals(id2, ret[1]); |
414 |
assertEquals(id2, ret[1]); |
| 409 |
|
415 |
|
| 410 |
ret = (Object[]) call("ticket.query", "summary~=fooba&summary~=summary"); |
416 |
// the first criterium is ignored |
| 411 |
assertEquals(2, ret.length); |
417 |
ret = (Object[]) call("ticket.query", "summary~=foobarsum1&summary~=foobaz sum2"); |
| 412 |
assertEquals(id1, ret[0]); |
418 |
assertEquals(1, ret.length); |
| 413 |
assertEquals(id2, ret[1]); |
419 |
assertEquals(id2, ret[0]); |
| 414 |
|
|
|
| 415 |
// ret = (Vector) call("ticket.query", "summary~=bar&summary~=baz"); |
| 416 |
// assertEquals(0, ret.size()); |
| 417 |
|
420 |
|
| 418 |
ret = (Object[]) call("ticket.query", "summary~=bar|baz"); |
421 |
ret = (Object[]) call("ticket.query", "summary~=bar|baz"); |
| 419 |
assertEquals(2, ret.length); |
422 |
assertEquals(3, ret.length); |
| 420 |
|
423 |
|
| 421 |
ret = (Object[]) call("ticket.query", "description~=description3"); |
424 |
ret = (Object[]) call("ticket.query", "description~=foobarbaz description3"); |
| 422 |
assertEquals(1, ret.length); |
425 |
assertEquals(1, ret.length); |
| 423 |
assertEquals(id3, ret[0]); |
426 |
assertEquals(id3, ret[0]); |
| 424 |
|
|
|
| 425 |
call("ticket.delete", id1); |
| 426 |
call("ticket.delete", id2); |
| 427 |
call("ticket.delete", id3); |
| 428 |
} |
427 |
} |
| 429 |
|
428 |
|
| 430 |
public void testQueryAll() throws XmlRpcException, IOException { |
429 |
public void testQueryAll() throws XmlRpcException, IOException { |
| 431 |
int id = (Integer) call("ticket.create", "foo", "description", new Hashtable()); |
430 |
int id = createTicket("foo", "description", new Hashtable()); |
| 432 |
|
431 |
|
| 433 |
Object[] ret = (Object[]) call("ticket.query", "order=id"); |
432 |
Object[] ret = (Object[]) call("ticket.query", "order=id"); |
| 434 |
assertTrue(ret.length > 0); |
433 |
assertTrue(ret.length > 0); |
| 435 |
assertHasValue(ret, id); |
434 |
assertHasValue(ret, id); |
| 436 |
|
|
|
| 437 |
call("ticket.delete", id); |
| 438 |
} |
435 |
} |
| 439 |
|
436 |
|
| 440 |
public void testPriorities() throws XmlRpcException, IOException { |
437 |
public void testPriorities() throws XmlRpcException, IOException { |