|
Lines 13-33
Link Here
|
| 13 |
|
13 |
|
| 14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
| 15 |
import java.net.URL; |
15 |
import java.net.URL; |
|
|
16 |
import java.util.ArrayList; |
| 16 |
import java.util.Date; |
17 |
import java.util.Date; |
| 17 |
import java.util.Hashtable; |
18 |
import java.util.Hashtable; |
|
|
19 |
import java.util.List; |
| 20 |
import java.util.Map; |
| 18 |
import java.util.Random; |
21 |
import java.util.Random; |
| 19 |
import java.util.Vector; |
|
|
| 20 |
|
| 21 |
import javax.net.ssl.HttpsURLConnection; |
| 22 |
import javax.net.ssl.SSLContext; |
| 23 |
|
22 |
|
| 24 |
import junit.framework.TestCase; |
23 |
import junit.framework.TestCase; |
| 25 |
|
24 |
|
| 26 |
import org.apache.xmlrpc.DefaultXmlRpcTransportFactory; |
|
|
| 27 |
import org.apache.xmlrpc.XmlRpc; |
| 28 |
import org.apache.xmlrpc.XmlRpcClient; |
| 29 |
import org.apache.xmlrpc.XmlRpcException; |
25 |
import org.apache.xmlrpc.XmlRpcException; |
| 30 |
import org.eclipse.mylar.internal.trac.TrustAll; |
26 |
import org.apache.xmlrpc.client.XmlRpcClient; |
|
|
27 |
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; |
| 28 |
import org.eclipse.mylar.internal.trac.core.TracHttpClientTransportFactory; |
| 31 |
|
29 |
|
| 32 |
/** |
30 |
/** |
| 33 |
* Test cases for <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">Trac XML-RPC |
31 |
* Test cases for <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">Trac XML-RPC |
|
Lines 55-87
Link Here
|
| 55 |
|
53 |
|
| 56 |
random = new Random(); |
54 |
random = new Random(); |
| 57 |
|
55 |
|
| 58 |
XmlRpc.setDefaultInputEncoding("UTF-8"); |
|
|
| 59 |
|
| 60 |
createConnection(new URL(Constants.TEST_REPOSITORY1_URL + XMLRPC_URL), |
56 |
createConnection(new URL(Constants.TEST_REPOSITORY1_URL + XMLRPC_URL), |
| 61 |
Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD); |
57 |
Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD); |
| 62 |
} |
58 |
} |
| 63 |
|
59 |
|
| 64 |
@SuppressWarnings("deprecation") |
60 |
@SuppressWarnings("deprecation") |
| 65 |
private void createConnection(URL url, String username, String password) throws Exception { |
61 |
private void createConnection(URL url, String username, String password) throws Exception { |
| 66 |
if (url.toString().startsWith("https")) { |
62 |
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); |
| 67 |
DefaultXmlRpcTransportFactory transport = new DefaultXmlRpcTransportFactory(url); |
63 |
config.setEncoding("UTF-8"); |
| 68 |
transport.setBasicAuthentication(username, password); |
64 |
config.setBasicUserName(username); |
| 69 |
|
65 |
config.setBasicPassword(password); |
| 70 |
SSLContext ctx = SSLContext.getInstance("TLS"); |
66 |
config.setServerURL(url); |
| 71 |
|
67 |
|
| 72 |
javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[] { new TrustAll() }; |
68 |
xmlrpc = new XmlRpcClient(); |
| 73 |
ctx.init(null, tm, null); |
69 |
xmlrpc.setConfig(config); |
| 74 |
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); |
70 |
|
| 75 |
|
71 |
TracHttpClientTransportFactory factory = new TracHttpClientTransportFactory(xmlrpc); |
| 76 |
xmlrpc = new XmlRpcClient(url, transport); |
72 |
xmlrpc.setTransportFactory(factory); |
| 77 |
} else { |
|
|
| 78 |
xmlrpc = new XmlRpcClient(url); |
| 79 |
|
| 80 |
// the XML-RPC library is kind of broken: setting authentication |
| 81 |
// credentials for |
| 82 |
// http connections is only possible through a deprecated method |
| 83 |
xmlrpc.setBasicAuthentication(username, password); |
| 84 |
} |
| 85 |
|
73 |
|
| 86 |
this.username = username; |
74 |
this.username = username; |
| 87 |
// this.password = password; |
75 |
// this.password = password; |
|
Lines 92-112
Link Here
|
| 92 |
} |
80 |
} |
| 93 |
|
81 |
|
| 94 |
private Object call(String method, Object... parameters) throws XmlRpcException, IOException { |
82 |
private Object call(String method, Object... parameters) throws XmlRpcException, IOException { |
| 95 |
Vector<Object> params = new Vector<Object>(); |
83 |
Object result = xmlrpc.execute(method, parameters); |
| 96 |
for (Object parameter : parameters) { |
|
|
| 97 |
params.add(parameter); |
| 98 |
} |
| 99 |
|
| 100 |
Object result = xmlrpc.execute(method, params); |
| 101 |
if (result instanceof XmlRpcException) { |
84 |
if (result instanceof XmlRpcException) { |
| 102 |
throw (XmlRpcException) result; |
85 |
throw (XmlRpcException) result; |
| 103 |
} |
86 |
} |
| 104 |
return result; |
87 |
return result; |
| 105 |
} |
88 |
} |
| 106 |
|
89 |
|
| 107 |
public Hashtable<String, Object> createMultiCall(String methodName, Object... parameters) throws XmlRpcException, |
90 |
public Map<String, Object> createMultiCall(String methodName, Object... parameters) throws XmlRpcException, |
| 108 |
IOException { |
91 |
IOException { |
| 109 |
Hashtable<String, Object> table = new Hashtable<String, Object>(); |
92 |
Map<String, Object> table = new Hashtable<String, Object>(); |
| 110 |
table.put("methodName", methodName); |
93 |
table.put("methodName", methodName); |
| 111 |
table.put("params", parameters); |
94 |
table.put("params", parameters); |
| 112 |
return table; |
95 |
return table; |
|
Lines 120-126
Link Here
|
| 120 |
|
103 |
|
| 121 |
call(module + ".create", "foo", "bar"); |
104 |
call(module + ".create", "foo", "bar"); |
| 122 |
|
105 |
|
| 123 |
assertHasValue(((Vector) call(module + ".getAll")).toArray(), "foo"); |
106 |
assertHasValue((Object[]) call(module + ".getAll"), "foo"); |
| 124 |
assertEquals("bar", (String) (call(module + ".get", "foo"))); |
107 |
assertEquals("bar", (String) (call(module + ".get", "foo"))); |
| 125 |
|
108 |
|
| 126 |
call(module + ".update", "foo", "baz"); |
109 |
call(module + ".update", "foo", "baz"); |
|
Lines 151-165
Link Here
|
| 151 |
} catch (XmlRpcException e) { |
134 |
} catch (XmlRpcException e) { |
| 152 |
} |
135 |
} |
| 153 |
|
136 |
|
| 154 |
Hashtable<String, Object> attributes = new Hashtable<String, Object>(); |
137 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 155 |
for (int i = 0; i < fields.length; i += 2) { |
138 |
for (int i = 0; i < fields.length; i += 2) { |
| 156 |
attributes.put((String) fields[i], createValue(fields[i], fields[i + 1])); |
139 |
attributes.put((String) fields[i], createValue(fields[i], fields[i + 1])); |
| 157 |
} |
140 |
} |
| 158 |
|
141 |
|
| 159 |
call(module + ".create", "foo", attributes); |
142 |
call(module + ".create", "foo", attributes); |
| 160 |
|
143 |
|
| 161 |
assertHasValue(((Vector) call(module + ".getAll")).toArray(), "foo"); |
144 |
assertHasValue((Object[]) call(module + ".getAll"), "foo"); |
| 162 |
Hashtable values = (Hashtable) call(module + ".get", "foo"); |
145 |
Map values = (Map) call(module + ".get", "foo"); |
| 163 |
for (String attribute : attributes.keySet()) { |
146 |
for (String attribute : attributes.keySet()) { |
| 164 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
147 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
| 165 |
} |
148 |
} |
|
Lines 169-175
Link Here
|
| 169 |
} |
152 |
} |
| 170 |
|
153 |
|
| 171 |
call(module + ".update", "foo", attributes); |
154 |
call(module + ".update", "foo", attributes); |
| 172 |
values = (Hashtable) call(module + ".get", "foo"); |
155 |
values = (Map) call(module + ".get", "foo"); |
| 173 |
for (String attribute : attributes.keySet()) { |
156 |
for (String attribute : attributes.keySet()) { |
| 174 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
157 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
| 175 |
} |
158 |
} |
|
Lines 186-199
Link Here
|
| 186 |
int due = (int) (System.currentTimeMillis() / 1000) + 1000; |
169 |
int due = (int) (System.currentTimeMillis() / 1000) + 1000; |
| 187 |
int completed = (int) (System.currentTimeMillis() / 1000); |
170 |
int completed = (int) (System.currentTimeMillis() / 1000); |
| 188 |
|
171 |
|
| 189 |
Hashtable<String, Object> attributes = new Hashtable<String, Object>(); |
172 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 190 |
attributes.put("description", "description"); |
173 |
attributes.put("description", "description"); |
| 191 |
attributes.put("due", due); |
174 |
attributes.put("due", due); |
| 192 |
attributes.put("completed", completed); |
175 |
attributes.put("completed", completed); |
| 193 |
|
176 |
|
| 194 |
call("ticket.milestone.create", "foo", attributes); |
177 |
call("ticket.milestone.create", "foo", attributes); |
| 195 |
|
178 |
|
| 196 |
Hashtable values = (Hashtable) call("ticket.milestone.get", "foo"); |
179 |
Map values = (Map) call("ticket.milestone.get", "foo"); |
| 197 |
assertEquals(new Integer(due), (Integer) values.get("due")); |
180 |
assertEquals(new Integer(due), (Integer) values.get("due")); |
| 198 |
assertEquals(new Integer(completed), (Integer) values.get("completed")); |
181 |
assertEquals(new Integer(completed), (Integer) values.get("completed")); |
| 199 |
|
182 |
|
|
Lines 209-236
Link Here
|
| 209 |
fail("Could not find expected value: " + value); |
192 |
fail("Could not find expected value: " + value); |
| 210 |
} |
193 |
} |
| 211 |
|
194 |
|
| 212 |
private void assertTicketHasAttributes(Hashtable<String, Object> attributes, int id, Vector ticket) { |
195 |
private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket) { |
| 213 |
assertTicketHasAttributes(attributes, id, ticket, true); |
196 |
assertTicketHasAttributes(attributes, id, ticket, true); |
| 214 |
} |
197 |
} |
| 215 |
|
198 |
|
| 216 |
private void assertTicketHasAttributes(Hashtable<String, Object> attributes, int id, Vector ticket, |
199 |
private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket, |
| 217 |
boolean newTicket) { |
200 |
boolean newTicket) { |
| 218 |
assertEquals(id, ticket.get(0)); |
201 |
assertEquals(id, ticket[0]); |
| 219 |
assertTrue(ticket.get(1) instanceof Integer); // time created |
202 |
assertTrue(ticket[1] instanceof Integer); // time created |
| 220 |
// time changed |
203 |
// time changed |
| 221 |
if (newTicket) { |
204 |
if (newTicket) { |
| 222 |
assertEquals(ticket.get(1), ticket.get(2)); |
205 |
assertEquals(ticket[1], ticket[2]); |
| 223 |
} else { |
206 |
} else { |
| 224 |
assertTrue((Integer) ticket.get(2) >= (Integer) ticket.get(1)); |
207 |
assertTrue((Integer) ticket[2] >= (Integer) ticket[1]); |
| 225 |
} |
208 |
} |
| 226 |
Hashtable values = (Hashtable) ticket.get(3); |
209 |
Map values = (Map) ticket[3]; |
| 227 |
for (String attribute : attributes.keySet()) { |
210 |
for (String attribute : attributes.keySet()) { |
| 228 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
211 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
| 229 |
} |
212 |
} |
| 230 |
} |
213 |
} |
| 231 |
|
214 |
|
| 232 |
public void testGetTicket() throws XmlRpcException, IOException { |
215 |
public void testGetTicket() throws XmlRpcException, IOException { |
| 233 |
Hashtable<String, Object> attributes = new Hashtable<String, Object>(); |
216 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 234 |
attributes.put("type", "task"); |
217 |
attributes.put("type", "task"); |
| 235 |
attributes.put("status", "closed"); |
218 |
attributes.put("status", "closed"); |
| 236 |
int id = (Integer) call("ticket.create", "summary", "description", attributes); |
219 |
int id = (Integer) call("ticket.create", "summary", "description", attributes); |
|
Lines 238-244
Link Here
|
| 238 |
attributes.put("summary", "summary"); |
221 |
attributes.put("summary", "summary"); |
| 239 |
attributes.put("description", "description"); |
222 |
attributes.put("description", "description"); |
| 240 |
|
223 |
|
| 241 |
Vector ticket = (Vector) call("ticket.get", id); |
224 |
Object[] ticket = (Object[]) call("ticket.get", id); |
| 242 |
assertTicketHasAttributes(attributes, id, ticket); |
225 |
assertTicketHasAttributes(attributes, id, ticket); |
| 243 |
|
226 |
|
| 244 |
call("ticket.delete", id); |
227 |
call("ticket.delete", id); |
|
Lines 252-258
Link Here
|
| 252 |
} |
235 |
} |
| 253 |
|
236 |
|
| 254 |
try { |
237 |
try { |
| 255 |
Vector ticket = (Vector) call("ticket.get", Integer.MAX_VALUE); |
238 |
List ticket = (List) call("ticket.get", Integer.MAX_VALUE); |
| 256 |
fail("Expected XmlRpcException, got ticket instead: " + ticket); |
239 |
fail("Expected XmlRpcException, got ticket instead: " + ticket); |
| 257 |
} catch (XmlRpcException e) { |
240 |
} catch (XmlRpcException e) { |
| 258 |
// ignore |
241 |
// ignore |
|
Lines 260-272
Link Here
|
| 260 |
} |
243 |
} |
| 261 |
|
244 |
|
| 262 |
public void testGetTicketUmlaute() throws XmlRpcException, IOException { |
245 |
public void testGetTicketUmlaute() throws XmlRpcException, IOException { |
| 263 |
Hashtable<String, Object> attributes = new Hashtable<String, Object>(); |
246 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 264 |
int id = (Integer) call("ticket.create", "summaryäÖÜ", "ßßß", attributes); |
247 |
int id = (Integer) call("ticket.create", "summaryäÖÜ", "ßßß", attributes); |
| 265 |
|
248 |
|
| 266 |
attributes.put("summary", "summaryäÖÜ"); |
249 |
attributes.put("summary", "summaryäÖÜ"); |
| 267 |
attributes.put("description", "ßßß"); |
250 |
attributes.put("description", "ßßß"); |
| 268 |
|
251 |
|
| 269 |
Vector ticket = (Vector) call("ticket.get", id); |
252 |
Object[] ticket = (Object[]) call("ticket.get", id); |
| 270 |
assertTicketHasAttributes(attributes, id, ticket); |
253 |
assertTicketHasAttributes(attributes, id, ticket); |
| 271 |
|
254 |
|
| 272 |
call("ticket.delete", id); |
255 |
call("ticket.delete", id); |
|
Lines 275-288
Link Here
|
| 275 |
public void testUpdateTicket() throws XmlRpcException, IOException { |
258 |
public void testUpdateTicket() throws XmlRpcException, IOException { |
| 276 |
int id = (Integer) call("ticket.create", "summary", "description", new Hashtable()); |
259 |
int id = (Integer) call("ticket.create", "summary", "description", new Hashtable()); |
| 277 |
|
260 |
|
| 278 |
Hashtable<String, Object> attributes = new Hashtable<String, Object>(); |
261 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 279 |
attributes.put("summary", "changed"); |
262 |
attributes.put("summary", "changed"); |
| 280 |
call("ticket.update", id, "my comment", attributes); |
263 |
call("ticket.update", id, "my comment", attributes); |
| 281 |
|
264 |
|
| 282 |
attributes.put("description", "description"); |
265 |
attributes.put("description", "description"); |
| 283 |
|
266 |
|
| 284 |
Vector ticket = (Vector) call("ticket.get", id); |
267 |
Object[] ticket = (Object[]) call("ticket.get", id); |
| 285 |
Hashtable values = (Hashtable) ticket.get(3); |
268 |
Map values = (Map) ticket[3]; |
| 286 |
for (String attribute : attributes.keySet()) { |
269 |
for (String attribute : attributes.keySet()) { |
| 287 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
270 |
assertEquals(attributes.get(attribute), values.get(attribute)); |
| 288 |
} |
271 |
} |
|
Lines 291-297
Link Here
|
| 291 |
} |
274 |
} |
| 292 |
|
275 |
|
| 293 |
public void testTicketCustomFields() throws XmlRpcException, IOException { |
276 |
public void testTicketCustomFields() throws XmlRpcException, IOException { |
| 294 |
Hashtable<String, Object> attributes = new Hashtable<String, Object>(); |
277 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 295 |
attributes.put("custom_text_field", "myvalue"); |
278 |
attributes.put("custom_text_field", "myvalue"); |
| 296 |
int id = (Integer) call("ticket.create", "summary", "description", attributes); |
279 |
int id = (Integer) call("ticket.create", "summary", "description", attributes); |
| 297 |
|
280 |
|
|
Lines 301-307
Link Here
|
| 301 |
attributes.put("custom_radio_field", "baz"); |
284 |
attributes.put("custom_radio_field", "baz"); |
| 302 |
attributes.put("custom_textarea_field", "default text"); |
285 |
attributes.put("custom_textarea_field", "default text"); |
| 303 |
|
286 |
|
| 304 |
Vector ticket = (Vector) call("ticket.get", id); |
287 |
Object[] ticket = (Object[]) call("ticket.get", id); |
| 305 |
assertTicketHasAttributes(attributes, id, ticket); |
288 |
assertTicketHasAttributes(attributes, id, ticket); |
| 306 |
|
289 |
|
| 307 |
attributes.put("custom_text_field", "myvalue2"); |
290 |
attributes.put("custom_text_field", "myvalue2"); |
|
Lines 312-318
Link Here
|
| 312 |
|
295 |
|
| 313 |
call("ticket.update", id, "my comment", attributes); |
296 |
call("ticket.update", id, "my comment", attributes); |
| 314 |
|
297 |
|
| 315 |
ticket = (Vector) call("ticket.get", id); |
298 |
ticket = (Object[]) call("ticket.get", id); |
| 316 |
assertTicketHasAttributes(attributes, id, ticket, false); |
299 |
assertTicketHasAttributes(attributes, id, ticket, false); |
| 317 |
|
300 |
|
| 318 |
call("ticket.delete", id); |
301 |
call("ticket.delete", id); |
|
Lines 321-337
Link Here
|
| 321 |
public void testGetChangeLog() throws XmlRpcException, IOException { |
304 |
public void testGetChangeLog() throws XmlRpcException, IOException { |
| 322 |
int id = (Integer) call("ticket.create", "summary", "description", new Hashtable()); |
305 |
int id = (Integer) call("ticket.create", "summary", "description", new Hashtable()); |
| 323 |
|
306 |
|
| 324 |
Hashtable<String, Object> attributes = new Hashtable<String, Object>(); |
307 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 325 |
attributes.put("summary", "changed"); |
308 |
attributes.put("summary", "changed"); |
| 326 |
call("ticket.update", id, "my comment", attributes); |
309 |
call("ticket.update", id, "my comment", attributes); |
| 327 |
|
310 |
|
| 328 |
Vector log = (Vector) call("ticket.changeLog", id, 0); |
311 |
Object[] log = (Object[]) call("ticket.changeLog", id, 0); |
| 329 |
Vector entry = (Vector) log.get(0); |
312 |
Object[] entry = (Object[]) log[0]; |
| 330 |
assertTrue(entry.get(0) instanceof Integer); // time |
313 |
assertTrue(entry[0] instanceof Integer); // time |
| 331 |
assertEquals(username, entry.get(1)); // author |
314 |
assertEquals(username, entry[1]); // author |
| 332 |
assertEquals("summary", entry.get(2)); // field |
315 |
assertEquals("summary", entry[2]); // field |
| 333 |
assertEquals("summary", entry.get(3)); // old value |
316 |
assertEquals("summary", entry[3]); // old value |
| 334 |
assertEquals("changed", entry.get(4)); // new value |
317 |
assertEquals("changed", entry[4]); // new value |
| 335 |
|
318 |
|
| 336 |
call("ticket.delete", id); |
319 |
call("ticket.delete", id); |
| 337 |
} |
320 |
} |
|
Lines 340-357
Link Here
|
| 340 |
int id1 = (Integer) call("ticket.create", "summary1", "description1", new Hashtable()); |
323 |
int id1 = (Integer) call("ticket.create", "summary1", "description1", new Hashtable()); |
| 341 |
int id2 = (Integer) call("ticket.create", "summary2", "description2", new Hashtable()); |
324 |
int id2 = (Integer) call("ticket.create", "summary2", "description2", new Hashtable()); |
| 342 |
|
325 |
|
| 343 |
Vector<Hashtable> calls = new Vector<Hashtable>(); |
326 |
List<Map> calls = new ArrayList<Map>(); |
| 344 |
calls.add(createMultiCall("ticket.get", id1)); |
327 |
calls.add(createMultiCall("ticket.get", id1)); |
| 345 |
calls.add(createMultiCall("ticket.get", id2)); |
328 |
calls.add(createMultiCall("ticket.get", id2)); |
| 346 |
Vector ret = (Vector) call("system.multicall", calls); |
329 |
Object[] ret = (Object[]) call("system.multicall", calls); |
| 347 |
|
330 |
|
| 348 |
Vector ticket = (Vector) ((Vector) ret.get(0)).get(0); |
331 |
Object[] ticket = (Object[]) ((Object[]) ret[0])[0]; |
| 349 |
Hashtable<String, Object> attributes = new Hashtable<String, Object>(); |
332 |
Map<String, Object> attributes = new Hashtable<String, Object>(); |
| 350 |
attributes.put("summary", "summary1"); |
333 |
attributes.put("summary", "summary1"); |
| 351 |
attributes.put("description", "description1"); |
334 |
attributes.put("description", "description1"); |
| 352 |
assertTicketHasAttributes(attributes, id1, ticket); |
335 |
assertTicketHasAttributes(attributes, id1, ticket); |
| 353 |
|
336 |
|
| 354 |
ticket = (Vector) ((Vector) ret.get(1)).get(0); |
337 |
ticket = (Object[]) ((Object[]) ret[1])[0]; |
| 355 |
attributes.clear(); |
338 |
attributes.clear(); |
| 356 |
attributes.put("summary", "summary2"); |
339 |
attributes.put("summary", "summary2"); |
| 357 |
attributes.put("description", "description2"); |
340 |
attributes.put("description", "description2"); |
|
Lines 369-377
Link Here
|
| 369 |
// attachment named "attach.txt" |
352 |
// attachment named "attach.txt" |
| 370 |
// assertEquals("attach.txt", filename); |
353 |
// assertEquals("attach.txt", filename); |
| 371 |
|
354 |
|
| 372 |
Vector ret = (Vector) call("ticket.listAttachments", id); |
355 |
Object[] ret = (Object[]) call("ticket.listAttachments", id); |
| 373 |
assertEquals(1, ret.size()); |
356 |
assertEquals(1, ret.length); |
| 374 |
assertHasValue(ret.toArray(), filename); |
357 |
assertHasValue(ret, filename); |
| 375 |
|
358 |
|
| 376 |
byte[] bytes = (byte[]) call("ticket.getAttachment", id, filename); |
359 |
byte[] bytes = (byte[]) call("ticket.getAttachment", id, filename); |
| 377 |
String data = new String(bytes); |
360 |
String data = new String(bytes); |
|
Lines 379-394
Link Here
|
| 379 |
|
362 |
|
| 380 |
String filename2 = (String) call("ticket.putAttachment", id, filename, "data".getBytes(), true); |
363 |
String filename2 = (String) call("ticket.putAttachment", id, filename, "data".getBytes(), true); |
| 381 |
assertEquals(filename, filename2); |
364 |
assertEquals(filename, filename2); |
| 382 |
ret = (Vector) call("ticket.listAttachments", id); |
365 |
ret = (Object[]) call("ticket.listAttachments", id); |
| 383 |
assertEquals(1, ret.size()); |
366 |
assertEquals(1, ret.length); |
| 384 |
assertHasValue(ret.toArray(), filename); |
367 |
assertHasValue(ret, filename); |
| 385 |
|
368 |
|
| 386 |
String filename3 = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), false); |
369 |
String filename3 = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), false); |
| 387 |
assertFalse("attach.txt".equals(filename3)); |
370 |
assertFalse("attach.txt".equals(filename3)); |
| 388 |
ret = (Vector) call("ticket.listAttachments", id); |
371 |
ret = (Object[]) call("ticket.listAttachments", id); |
| 389 |
assertEquals(2, ret.size()); |
372 |
assertEquals(2, ret.length); |
| 390 |
assertHasValue(ret.toArray(), filename); |
373 |
assertHasValue(ret, filename); |
| 391 |
assertHasValue(ret.toArray(), filename3); |
374 |
assertHasValue(ret, filename3); |
| 392 |
|
375 |
|
| 393 |
call("ticket.delete", id); |
376 |
call("ticket.delete", id); |
| 394 |
} |
377 |
} |
|
Lines 398-417
Link Here
|
| 398 |
|
381 |
|
| 399 |
String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true); |
382 |
String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true); |
| 400 |
|
383 |
|
| 401 |
Vector ret = (Vector) call("ticket.listAttachments", id); |
384 |
Object[] ret = (Object[]) call("ticket.listAttachments", id); |
| 402 |
assertEquals(1, ret.size()); |
385 |
assertEquals(1, ret.length); |
| 403 |
assertHasValue(ret.toArray(), filename); |
386 |
assertHasValue(ret, filename); |
| 404 |
|
387 |
|
| 405 |
call("ticket.deleteAttachment", id, filename); |
388 |
call("ticket.deleteAttachment", id, filename); |
| 406 |
|
389 |
|
| 407 |
ret = (Vector) call("ticket.listAttachments", id); |
390 |
ret = (Object[]) call("ticket.listAttachments", id); |
| 408 |
assertEquals(0, ret.size()); |
391 |
assertEquals(0, ret.length); |
| 409 |
|
392 |
|
| 410 |
call("ticket.delete", id); |
393 |
call("ticket.delete", id); |
| 411 |
} |
394 |
} |
| 412 |
|
395 |
|
| 413 |
public void testQuery() throws XmlRpcException, IOException { |
396 |
public void testQuery() throws XmlRpcException, IOException { |
| 414 |
Vector ret = (Vector) call("ticket.query", "summary~=foo|bar|baz|summary|ticket"); |
397 |
Object[] ret = (Object[]) call("ticket.query", "summary~=foo|bar|baz|summary|ticket"); |
| 415 |
for (Object id : ret) { |
398 |
for (Object id : ret) { |
| 416 |
call("ticket.delete", (Integer) id); |
399 |
call("ticket.delete", (Integer) id); |
| 417 |
} |
400 |
} |
|
Lines 420-444
Link Here
|
| 420 |
int id2 = (Integer) call("ticket.create", "foobaz summary2", "description", new Hashtable()); |
403 |
int id2 = (Integer) call("ticket.create", "foobaz summary2", "description", new Hashtable()); |
| 421 |
int id3 = (Integer) call("ticket.create", "ticket3", "description3", new Hashtable()); |
404 |
int id3 = (Integer) call("ticket.create", "ticket3", "description3", new Hashtable()); |
| 422 |
|
405 |
|
| 423 |
ret = (Vector) call("ticket.query", "summary=foobarsummary1|foobaz summary2"); |
406 |
ret = (Object[]) call("ticket.query", "summary=foobarsummary1|foobaz summary2"); |
| 424 |
assertEquals(2, ret.size()); |
407 |
assertEquals(2, ret.length); |
| 425 |
assertEquals(ret.get(0), id1); |
408 |
assertEquals(id1, ret[0]); |
| 426 |
assertEquals(ret.get(1), id2); |
409 |
assertEquals(id2, ret[1]); |
| 427 |
|
410 |
|
| 428 |
ret = (Vector) call("ticket.query", "summary~=fooba&summary~=summary"); |
411 |
ret = (Object[]) call("ticket.query", "summary~=fooba&summary~=summary"); |
| 429 |
assertEquals(2, ret.size()); |
412 |
assertEquals(2, ret.length); |
| 430 |
assertEquals(ret.get(0), id1); |
413 |
assertEquals(id1, ret[0]); |
| 431 |
assertEquals(ret.get(1), id2); |
414 |
assertEquals(id2, ret[1]); |
| 432 |
|
415 |
|
| 433 |
// ret = (Vector) call("ticket.query", "summary~=bar&summary~=baz"); |
416 |
// ret = (Vector) call("ticket.query", "summary~=bar&summary~=baz"); |
| 434 |
// assertEquals(0, ret.size()); |
417 |
// assertEquals(0, ret.size()); |
| 435 |
|
418 |
|
| 436 |
ret = (Vector) call("ticket.query", "summary~=bar|baz"); |
419 |
ret = (Object[]) call("ticket.query", "summary~=bar|baz"); |
| 437 |
assertEquals(2, ret.size()); |
420 |
assertEquals(2, ret.length); |
| 438 |
|
421 |
|
| 439 |
ret = (Vector) call("ticket.query", "description~=description3"); |
422 |
ret = (Object[]) call("ticket.query", "description~=description3"); |
| 440 |
assertEquals(1, ret.size()); |
423 |
assertEquals(1, ret.length); |
| 441 |
assertEquals(ret.get(0), id3); |
424 |
assertEquals(id3, ret[0]); |
| 442 |
|
425 |
|
| 443 |
call("ticket.delete", id1); |
426 |
call("ticket.delete", id1); |
| 444 |
call("ticket.delete", id2); |
427 |
call("ticket.delete", id2); |
|
Lines 448-456
Link Here
|
| 448 |
public void testQueryAll() throws XmlRpcException, IOException { |
431 |
public void testQueryAll() throws XmlRpcException, IOException { |
| 449 |
int id = (Integer) call("ticket.create", "foo", "description", new Hashtable()); |
432 |
int id = (Integer) call("ticket.create", "foo", "description", new Hashtable()); |
| 450 |
|
433 |
|
| 451 |
Vector ret = (Vector) call("ticket.query", "order=id"); |
434 |
Object[] ret = (Object[]) call("ticket.query", "order=id"); |
| 452 |
assertTrue(ret.size() > 0); |
435 |
assertTrue(ret.length > 0); |
| 453 |
assertHasValue(ret.toArray(), id); |
436 |
assertHasValue(ret, id); |
| 454 |
|
437 |
|
| 455 |
call("ticket.delete", id); |
438 |
call("ticket.delete", id); |
| 456 |
} |
439 |
} |