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