Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 151896 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/trac/MylarTracPlugin.java (+11 lines)
Lines 23-30 Link Here
23
import javax.net.ssl.HttpsURLConnection;
23
import javax.net.ssl.HttpsURLConnection;
24
import javax.net.ssl.SSLContext;
24
import javax.net.ssl.SSLContext;
25
25
26
import org.apache.commons.httpclient.protocol.Protocol;
26
import org.eclipse.jface.dialogs.MessageDialog;
27
import org.eclipse.jface.dialogs.MessageDialog;
27
import org.eclipse.mylar.context.core.MylarStatusHandler;
28
import org.eclipse.mylar.context.core.MylarStatusHandler;
29
import org.eclipse.mylar.internal.tasks.core.SslProtocolSocketFactory;
28
import org.eclipse.mylar.internal.tasks.ui.views.TaskRepositoriesView;
30
import org.eclipse.mylar.internal.tasks.ui.views.TaskRepositoriesView;
29
import org.eclipse.mylar.internal.trac.core.TracException;
31
import org.eclipse.mylar.internal.trac.core.TracException;
30
import org.eclipse.mylar.internal.trac.core.TracLoginException;
32
import org.eclipse.mylar.internal.trac.core.TracLoginException;
Lines 54-59 Link Here
54
56
55
	public void start(BundleContext context) throws Exception {
57
	public void start(BundleContext context) throws Exception {
56
		super.start(context);
58
		super.start(context);
59
60
		// TODO the protocol configuration of HttpClient should not be registered globally
61
		Protocol acceptAllSsl = new Protocol("https", new SslProtocolSocketFactory(), 443);
62
		Protocol.registerProtocol("https", acceptAllSsl);
63
64
		// TODO the logging configuration of HttpClient should be done elsewhere
65
		System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
66
		System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "off");
67
		System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "off");
57
	}
68
	}
58
69
59
	public void stop(BundleContext context) throws Exception {
70
	public void stop(BundleContext context) throws Exception {
(-)META-INF/MANIFEST.MF (-1 lines)
Lines 10-16 Link Here
10
 org.eclipse.core.runtime,
10
 org.eclipse.core.runtime,
11
 org.eclipse.mylar.context.core,
11
 org.eclipse.mylar.context.core,
12
 org.eclipse.mylar.tasks.ui,
12
 org.eclipse.mylar.tasks.ui,
13
 org.apache.xmlrpc,
14
 org.eclipse.mylar.tasks.core
13
 org.eclipse.mylar.tasks.core
15
Eclipse-LazyStart: true
14
Eclipse-LazyStart: true
16
Export-Package: org.eclipse.mylar.internal.trac,
15
Export-Package: org.eclipse.mylar.internal.trac,
(-)src/org/eclipse/mylar/internal/trac/core/TracXmlRpcClient.java (-165 / +77 lines)
Lines 1-26 Link Here
1
package org.eclipse.mylar.internal.trac.core;
1
package org.eclipse.mylar.internal.trac.core;
2
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.OutputStream;
6
import java.net.HttpURLConnection;
3
import java.net.HttpURLConnection;
7
import java.net.URL;
4
import java.net.URL;
8
import java.util.ArrayList;
5
import java.util.ArrayList;
9
import java.util.Collections;
6
import java.util.Collections;
10
import java.util.Hashtable;
7
import java.util.HashMap;
11
import java.util.List;
8
import java.util.List;
12
import java.util.Vector;
9
import java.util.Map;
13
10
14
import org.apache.xmlrpc.XmlRpc;
15
import org.apache.xmlrpc.XmlRpcClient;
16
import org.apache.xmlrpc.XmlRpcClientException;
17
import org.apache.xmlrpc.XmlRpcException;
11
import org.apache.xmlrpc.XmlRpcException;
18
import org.apache.xmlrpc.XmlRpcTransport;
12
import org.apache.xmlrpc.client.XmlRpcClient;
19
import org.apache.xmlrpc.XmlRpcTransportFactory;
13
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
20
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.OperationCanceledException;
15
import org.eclipse.core.runtime.OperationCanceledException;
22
import org.eclipse.mylar.context.core.MylarStatusHandler;
16
import org.eclipse.mylar.context.core.MylarStatusHandler;
23
import org.eclipse.mylar.internal.trac.MylarTracPlugin;
17
import org.eclipse.mylar.internal.trac.core.TracHttpClientTransportFactory.TracHttpException;
24
import org.eclipse.mylar.internal.trac.model.TracComponent;
18
import org.eclipse.mylar.internal.trac.model.TracComponent;
25
import org.eclipse.mylar.internal.trac.model.TracMilestone;
19
import org.eclipse.mylar.internal.trac.model.TracMilestone;
26
import org.eclipse.mylar.internal.trac.model.TracPriority;
20
import org.eclipse.mylar.internal.trac.model.TracPriority;
Lines 52-60 Link Here
52
			return xmlrpc;
46
			return xmlrpc;
53
		}
47
		}
54
48
55
		// initialize XML-RPC library
49
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
56
		XmlRpc.setDefaultInputEncoding(ITracClient.CHARSET);
50
		config.setEncoding(ITracClient.CHARSET);
51
		config.setBasicUserName(username);
52
		config.setBasicPassword(password);
53
		config.setServerURL(getXmlRpcUrl());
54
		
55
		xmlrpc = new XmlRpcClient();
56
		xmlrpc.setConfig(config);
57
		
58
		TracHttpClientTransportFactory factory = new TracHttpClientTransportFactory(xmlrpc);
59
		xmlrpc.setTransportFactory(factory);
57
60
61
		return xmlrpc;
62
	}
63
64
	private URL getXmlRpcUrl() throws TracException {
58
		try {
65
		try {
59
			String location = repositoryUrl.toString();
66
			String location = repositoryUrl.toString();
60
			if (hasAuthenticationCredentials()) {
67
			if (hasAuthenticationCredentials()) {
Lines 62-90 Link Here
62
			}
69
			}
63
			location += XMLRPC_URL;
70
			location += XMLRPC_URL;
64
71
65
			URL url = new URL(location);
72
			return new URL(location);
66
			TransportFactory transport = new TransportFactory(url);
67
			xmlrpc = new XmlRpcClient(url, transport);
68
		} catch (Exception e) {
73
		} catch (Exception e) {
69
			throw new TracException(e);
74
			throw new TracException(e);
70
		}
75
		}
71
72
		return xmlrpc;
73
	}
76
	}
74
77
75
	private Object call(String method, Object... parameters) throws TracException {
78
	private Object call(String method, Object... parameters) throws TracException {
76
		getClient();
79
		getClient();
77
80
78
		Vector<Object> params = new Vector<Object>();
79
		for (Object parameter : parameters) {
80
			params.add(parameter);
81
		}
82
83
		try {
81
		try {
84
			return xmlrpc.execute(method, params);
82
			return xmlrpc.execute(method, parameters);
85
		} catch (HttpException e) {
83
		} catch (TracHttpException e) {
86
			if (e.responseCode == HttpURLConnection.HTTP_FORBIDDEN
84
			if (e.code == HttpURLConnection.HTTP_FORBIDDEN
87
					|| e.responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
85
					|| e.code == HttpURLConnection.HTTP_UNAUTHORIZED) {
88
				throw new TracLoginException();
86
				throw new TracLoginException();
89
			} else {
87
			} else {
90
				throw new TracException(e);
88
				throw new TracException(e);
Lines 96-103 Link Here
96
		}
94
		}
97
	}
95
	}
98
96
99
	private Vector multicall(Hashtable<String, Object>... calls) throws TracException {
97
	private Object[] multicall(Map<String, Object>... calls) throws TracException {
100
		Vector result = (Vector) call("system.multicall", new Object[] { calls });
98
		Object[] result = (Object[]) call("system.multicall", new Object[] { calls });
101
		for (Object item : result) {
99
		for (Object item : result) {
102
			try {
100
			try {
103
				checkForException(item);
101
				checkForException(item);
Lines 111-118 Link Here
111
	}
109
	}
112
110
113
	private void checkForException(Object result) throws NumberFormatException, XmlRpcException {
111
	private void checkForException(Object result) throws NumberFormatException, XmlRpcException {
114
		if (result instanceof Hashtable) {
112
		if (result instanceof Map) {
115
			Hashtable exceptionData = (Hashtable) result;
113
			Map exceptionData = (Map) result;
116
			if (exceptionData.containsKey("faultCode") && exceptionData.containsKey("faultString")) {
114
			if (exceptionData.containsKey("faultCode") && exceptionData.containsKey("faultString")) {
117
				throw new XmlRpcException(Integer.parseInt(exceptionData.get("faultCode").toString()),
115
				throw new XmlRpcException(Integer.parseInt(exceptionData.get("faultCode").toString()),
118
						(String) exceptionData.get("faultString"));
116
						(String) exceptionData.get("faultString"));
Lines 120-138 Link Here
120
		}
118
		}
121
	}
119
	}
122
120
123
	private Hashtable<String, Object> createMultiCall(String methodName, Object... parameters) throws TracException {
121
	private Map<String, Object> createMultiCall(String methodName, Object... parameters) throws TracException {
124
		Hashtable<String, Object> table = new Hashtable<String, Object>();
122
		Map<String, Object> table = new HashMap<String, Object>();
125
		table.put("methodName", methodName);
123
		table.put("methodName", methodName);
126
		table.put("params", parameters);
124
		table.put("params", parameters);
127
		return table;
125
		return table;
128
	}
126
	}
129
127
130
	private Object getMultiCallResult(Object item) {
128
	private Object getMultiCallResult(Object item) {
131
		return ((Vector) item).get(0);
129
		return ((Object[]) item)[0];
132
	}
130
	}
133
131
134
	public void validate() throws TracException {
132
	public void validate() throws TracException {
135
		Vector result = (Vector) call("system.listMethods");
133
		Object[] result = (Object[]) call("system.listMethods");
136
		boolean hasGetTicket = false, hasQuery = false;
134
		boolean hasGetTicket = false, hasQuery = false;
137
		for (Object methodName : result) {
135
		for (Object methodName : result) {
138
			if ("ticket.get".equals(methodName)) {
136
			if ("ticket.get".equals(methodName)) {
Lines 151-173 Link Here
151
	}
149
	}
152
150
153
	public TracTicket getTicket(int id) throws TracException {
151
	public TracTicket getTicket(int id) throws TracException {
154
		Vector result = (Vector) call("ticket.get", id);
152
		Object[] result = (Object[]) call("ticket.get", id);
155
		return parseTicket(result);
153
		return parseTicket(result);
156
	}
154
	}
157
155
158
	@SuppressWarnings("unchecked")
156
	@SuppressWarnings("unchecked")
159
	public List<TracTicket> getTickets(int[] ids) throws TracException {
157
	public List<TracTicket> getTickets(int[] ids) throws TracException {
160
		Hashtable<String, Object>[] calls = new Hashtable[ids.length];
158
		Map<String, Object>[] calls = new Map[ids.length];
161
		for (int i = 0; i < calls.length; i++) {
159
		for (int i = 0; i < calls.length; i++) {
162
			calls[i] = createMultiCall("ticket.get", ids[i]);
160
			calls[i] = createMultiCall("ticket.get", ids[i]);
163
		}
161
		}
164
162
165
		Vector result = multicall(calls);
163
		Object[] result = multicall(calls);
166
		assert result.size() == ids.length;
164
		assert result.length == ids.length;
167
165
168
		List<TracTicket> tickets = new ArrayList<TracTicket>(result.size());
166
		List<TracTicket> tickets = new ArrayList<TracTicket>(result.length);
169
		for (Object item : result) {
167
		for (Object item : result) {
170
			Vector ticketResult = (Vector) getMultiCallResult(item);
168
			Object[] ticketResult = (Object[]) getMultiCallResult(item);
171
			tickets.add(parseTicket(ticketResult));
169
			tickets.add(parseTicket(ticketResult));
172
		}
170
		}
173
171
Lines 177-201 Link Here
177
	@SuppressWarnings("unchecked")
175
	@SuppressWarnings("unchecked")
178
	public void search(TracSearch query, List<TracTicket> tickets) throws TracException {
176
	public void search(TracSearch query, List<TracTicket> tickets) throws TracException {
179
		// an empty query string is not valid, therefore prepend order
177
		// an empty query string is not valid, therefore prepend order
180
		Vector result = (Vector) call("ticket.query", "order=id" + query.toQuery());
178
		Object[] result = (Object[]) call("ticket.query", "order=id" + query.toQuery());
181
179
182
		Hashtable<String, Object>[] calls = new Hashtable[result.size()];
180
		Map<String, Object>[] calls = new Map[result.length];
183
		for (int i = 0; i < calls.length; i++) {
181
		for (int i = 0; i < calls.length; i++) {
184
			calls[i] = createMultiCall("ticket.get", result.get(i));
182
			calls[i] = createMultiCall("ticket.get", result[i]);
185
		}
183
		}
186
		result = multicall(calls);
184
		result = multicall(calls);
187
185
188
		for (Object item : result) {
186
		for (Object item : result) {
189
			Vector ticketResult = (Vector) getMultiCallResult(item);
187
			Object[] ticketResult = (Object[]) getMultiCallResult(item);
190
			tickets.add(parseTicket(ticketResult));
188
			tickets.add(parseTicket(ticketResult));
191
		}
189
		}
192
	}
190
	}
193
191
194
	private TracTicket parseTicket(Vector result) throws InvalidTicketException {
192
	private TracTicket parseTicket(Object[] ticketResult) throws InvalidTicketException {
195
		TracTicket ticket = new TracTicket((Integer) result.get(0));
193
		TracTicket ticket = new TracTicket((Integer) ticketResult[0]);
196
		ticket.setCreated((Integer) result.get(1));
194
		ticket.setCreated((Integer) ticketResult[1]);
197
		ticket.setLastChanged((Integer) result.get(2));
195
		ticket.setLastChanged((Integer) ticketResult[2]);
198
		Hashtable attributes = (Hashtable) result.get(3);
196
		Map attributes = (Map) ticketResult[3];
199
		for (Object key : attributes.keySet()) {
197
		for (Object key : attributes.keySet()) {
200
			ticket.putTracValue(key.toString(), attributes.get(key).toString());
198
			ticket.putTracValue(key.toString(), attributes.get(key).toString());
201
		}
199
		}
Lines 205-230 Link Here
205
	public synchronized void updateAttributes(IProgressMonitor monitor) throws TracException {
203
	public synchronized void updateAttributes(IProgressMonitor monitor) throws TracException {
206
		monitor.beginTask("Updating attributes", 8);
204
		monitor.beginTask("Updating attributes", 8);
207
205
208
		Vector result = getAttributes("ticket.component");
206
		Object[] result = getAttributes("ticket.component");
209
		components = new ArrayList<TracComponent>(result.size());
207
		components = new ArrayList<TracComponent>(result.length);
210
		for (Object item : result) {
208
		for (Object item : result) {
211
			components.add(parseComponent((Hashtable) getMultiCallResult(item)));
209
			components.add(parseComponent((Map) getMultiCallResult(item)));
212
		}
210
		}
213
		monitor.worked(1);
211
		monitor.worked(1);
214
		if (monitor.isCanceled())
212
		if (monitor.isCanceled())
215
			throw new OperationCanceledException();
213
			throw new OperationCanceledException();
216
214
217
		result = getAttributes("ticket.milestone");
215
		result = getAttributes("ticket.milestone");
218
		milestones = new ArrayList<TracMilestone>(result.size());
216
		milestones = new ArrayList<TracMilestone>(result.length);
219
		for (Object item : result) {
217
		for (Object item : result) {
220
			milestones.add(parseMilestone((Hashtable) getMultiCallResult(item)));
218
			milestones.add(parseMilestone((Map) getMultiCallResult(item)));
221
		}
219
		}
222
		monitor.worked(1);
220
		monitor.worked(1);
223
		if (monitor.isCanceled())
221
		if (monitor.isCanceled())
224
			throw new OperationCanceledException();
222
			throw new OperationCanceledException();
225
223
226
		List<TicketAttributeResult> attributes = getTicketAttributes("ticket.priority");
224
		List<TicketAttributeResult> attributes = getTicketAttributes("ticket.priority");
227
		priorities = new ArrayList<TracPriority>(result.size());
225
		priorities = new ArrayList<TracPriority>(result.length);
228
		for (TicketAttributeResult attribute : attributes) {
226
		for (TicketAttributeResult attribute : attributes) {
229
			priorities.add(new TracPriority(attribute.name, attribute.value));
227
			priorities.add(new TracPriority(attribute.name, attribute.value));
230
		}
228
		}
Lines 234-240 Link Here
234
			throw new OperationCanceledException();
232
			throw new OperationCanceledException();
235
233
236
		attributes = getTicketAttributes("ticket.resolution");
234
		attributes = getTicketAttributes("ticket.resolution");
237
		ticketResolutions = new ArrayList<TracTicketResolution>(result.size());
235
		ticketResolutions = new ArrayList<TracTicketResolution>(result.length);
238
		for (TicketAttributeResult attribute : attributes) {
236
		for (TicketAttributeResult attribute : attributes) {
239
			ticketResolutions.add(new TracTicketResolution(attribute.name, attribute.value));
237
			ticketResolutions.add(new TracTicketResolution(attribute.name, attribute.value));
240
		}
238
		}
Lines 244-250 Link Here
244
			throw new OperationCanceledException();
242
			throw new OperationCanceledException();
245
243
246
		attributes = getTicketAttributes("ticket.severity");
244
		attributes = getTicketAttributes("ticket.severity");
247
		severities = new ArrayList<TracSeverity>(result.size());
245
		severities = new ArrayList<TracSeverity>(result.length);
248
		for (TicketAttributeResult attribute : attributes) {
246
		for (TicketAttributeResult attribute : attributes) {
249
			severities.add(new TracSeverity(attribute.name, attribute.value));
247
			severities.add(new TracSeverity(attribute.name, attribute.value));
250
		}
248
		}
Lines 254-260 Link Here
254
			throw new OperationCanceledException();
252
			throw new OperationCanceledException();
255
253
256
		attributes = getTicketAttributes("ticket.status");
254
		attributes = getTicketAttributes("ticket.status");
257
		ticketStatus = new ArrayList<TracTicketStatus>(result.size());
255
		ticketStatus = new ArrayList<TracTicketStatus>(result.length);
258
		for (TicketAttributeResult attribute : attributes) {
256
		for (TicketAttributeResult attribute : attributes) {
259
			ticketStatus.add(new TracTicketStatus(attribute.name, attribute.value));
257
			ticketStatus.add(new TracTicketStatus(attribute.name, attribute.value));
260
		}
258
		}
Lines 264-270 Link Here
264
			throw new OperationCanceledException();
262
			throw new OperationCanceledException();
265
263
266
		attributes = getTicketAttributes("ticket.type");
264
		attributes = getTicketAttributes("ticket.type");
267
		ticketTypes = new ArrayList<TracTicketType>(result.size());
265
		ticketTypes = new ArrayList<TracTicketType>(result.length);
268
		for (TicketAttributeResult attribute : attributes) {
266
		for (TicketAttributeResult attribute : attributes) {
269
			ticketTypes.add(new TracTicketType(attribute.name, attribute.value));
267
			ticketTypes.add(new TracTicketType(attribute.name, attribute.value));
270
		}
268
		}
Lines 274-296 Link Here
274
			throw new OperationCanceledException();
272
			throw new OperationCanceledException();
275
273
276
		result = getAttributes("ticket.version");
274
		result = getAttributes("ticket.version");
277
		versions = new ArrayList<TracVersion>(result.size());
275
		versions = new ArrayList<TracVersion>(result.length);
278
		for (Object item : result) {
276
		for (Object item : result) {
279
			versions.add(parseVersion((Hashtable) getMultiCallResult(item)));
277
			versions.add(parseVersion((Map) getMultiCallResult(item)));
280
		}
278
		}
281
		monitor.worked(1);
279
		monitor.worked(1);
282
		if (monitor.isCanceled())
280
		if (monitor.isCanceled())
283
			throw new OperationCanceledException();
281
			throw new OperationCanceledException();
284
	}
282
	}
285
283
286
	private TracComponent parseComponent(Hashtable result) {
284
	private TracComponent parseComponent(Map result) {
287
		TracComponent component = new TracComponent((String) result.get("name"));
285
		TracComponent component = new TracComponent((String) result.get("name"));
288
		component.setOwner((String) result.get("owner"));
286
		component.setOwner((String) result.get("owner"));
289
		component.setDescription((String) result.get("description"));
287
		component.setDescription((String) result.get("description"));
290
		return component;
288
		return component;
291
	}
289
	}
292
290
293
	private TracMilestone parseMilestone(Hashtable result) {
291
	private TracMilestone parseMilestone(Map result) {
294
		TracMilestone milestone = new TracMilestone((String) result.get("name"));
292
		TracMilestone milestone = new TracMilestone((String) result.get("name"));
295
		milestone.setCompleted(TracUtils.parseDate((Integer) result.get("completed")));
293
		milestone.setCompleted(TracUtils.parseDate((Integer) result.get("completed")));
296
		milestone.setDue(TracUtils.parseDate((Integer) result.get("due")));
294
		milestone.setDue(TracUtils.parseDate((Integer) result.get("due")));
Lines 298-304 Link Here
298
		return milestone;
296
		return milestone;
299
	}
297
	}
300
298
301
	private TracVersion parseVersion(Hashtable result) {
299
	private TracVersion parseVersion(Map result) {
302
		TracVersion version = new TracVersion((String) result.get("name"));
300
		TracVersion version = new TracVersion((String) result.get("name"));
303
		version.setTime(TracUtils.parseDate((Integer) result.get("time")));
301
		version.setTime(TracUtils.parseDate((Integer) result.get("time")));
304
		version.setDescription((String) result.get("description"));
302
		version.setDescription((String) result.get("description"));
Lines 306-341 Link Here
306
	}
304
	}
307
305
308
	@SuppressWarnings("unchecked")
306
	@SuppressWarnings("unchecked")
309
	private Vector getAttributes(String attributeType) throws TracException {
307
	private Object[] getAttributes(String attributeType) throws TracException {
310
		Vector ids = (Vector) call(attributeType + ".getAll");
308
		Object[] ids = (Object[]) call(attributeType + ".getAll");
311
		Hashtable<String, Object>[] calls = new Hashtable[ids.size()];
309
		Map<String, Object>[] calls = new Map[ids.length];
312
		for (int i = 0; i < calls.length; i++) {
310
		for (int i = 0; i < calls.length; i++) {
313
			calls[i] = createMultiCall(attributeType + ".get", ids.get(i));
311
			calls[i] = createMultiCall(attributeType + ".get", ids[i]);
314
		}
312
		}
315
313
316
		Vector result = multicall(calls);
314
		Object[] result = multicall(calls);
317
		assert result.size() == ids.size();
315
		assert result.length == ids.length;
318
316
319
		return result;
317
		return result;
320
	}
318
	}
321
319
322
	@SuppressWarnings("unchecked")
320
	@SuppressWarnings("unchecked")
323
	private List<TicketAttributeResult> getTicketAttributes(String attributeType) throws TracException {
321
	private List<TicketAttributeResult> getTicketAttributes(String attributeType) throws TracException {
324
		Vector ids = (Vector) call(attributeType + ".getAll");
322
		Object[] ids = (Object[]) call(attributeType + ".getAll");
325
		Hashtable<String, Object>[] calls = new Hashtable[ids.size()];
323
		Map<String, Object>[] calls = new Map[ids.length];
326
		for (int i = 0; i < calls.length; i++) {
324
		for (int i = 0; i < calls.length; i++) {
327
			calls[i] = createMultiCall(attributeType + ".get", ids.get(i));
325
			calls[i] = createMultiCall(attributeType + ".get", ids[i]);
328
		}
326
		}
329
327
330
		Vector result = multicall(calls);
328
		Object[] result = multicall(calls);
331
		assert result.size() == ids.size();
329
		assert result.length == ids.length;
332
330
333
		List<TicketAttributeResult> attributes = new ArrayList<TicketAttributeResult>(result.size());
331
		List<TicketAttributeResult> attributes = new ArrayList<TicketAttributeResult>(result.length);
334
		for (int i = 0; i < calls.length; i++) {
332
		for (int i = 0; i < calls.length; i++) {
335
			try {
333
			try {
336
				TicketAttributeResult attribute = new TicketAttributeResult();
334
				TicketAttributeResult attribute = new TicketAttributeResult();
337
				attribute.name = (String) ids.get(i);
335
				attribute.name = (String) ids[i];
338
				attribute.value = Integer.parseInt((String) getMultiCallResult(result.get(i)));
336
				attribute.value = Integer.parseInt((String) getMultiCallResult(result[i]));
339
				attributes.add(attribute);
337
				attributes.add(attribute);
340
			} catch (NumberFormatException e) {
338
			} catch (NumberFormatException e) {
341
				MylarStatusHandler.log(e, "Invalid response from Trac repository for attribute type: '" + attributeType
339
				MylarStatusHandler.log(e, "Invalid response from Trac repository for attribute type: '" + attributeType
Lines 354-443 Link Here
354
352
355
	}
353
	}
356
354
357
	/**
358
	 * A custom transport factory used to establish XML-RPC connections. Uses
359
	 * the Eclipse proxy settings.
360
	 * 
361
	 * @author Steffen Pingel
362
	 */
363
	private class TransportFactory implements XmlRpcTransportFactory {
364
365
		private URL url;
366
367
		public TransportFactory(URL url) {
368
			assert url != null;
369
370
			this.url = url;
371
		}
372
373
		public XmlRpcTransport createTransport() throws XmlRpcClientException {
374
			return new XmlRpcTransport() {
375
376
				private HttpURLConnection connection;
377
378
				public void endClientRequest() throws XmlRpcClientException {
379
					assert connection != null;
380
381
					try {
382
						connection.getInputStream().close();
383
					} catch (Exception e) {
384
						throw new XmlRpcClientException("Exception closing connection", e);
385
					}
386
				}
387
388
				public InputStream sendXmlRpc(byte[] request) throws IOException, XmlRpcClientException {
389
					try {
390
						connection = MylarTracPlugin.getHttpConnection(url);
391
					} catch (Exception e) {
392
						throw new IOException(e.toString());
393
					}
394
395
					connection.setDoInput(true);
396
					connection.setDoOutput(true);
397
					connection.setUseCaches(false);
398
					connection.setAllowUserInteraction(false);
399
400
					connection.setRequestProperty("Content-Length", request.length + "");
401
					connection.setRequestProperty("Content-Type", "text/xml");
402
					if (hasAuthenticationCredentials()) {
403
						MylarTracPlugin.setAuthCredentials(connection, username, password);
404
					}
405
406
					OutputStream out = connection.getOutputStream();
407
					out.write(request);
408
					out.flush();
409
					out.close();
410
411
					connection.connect();
412
					int responseCode = connection.getResponseCode();
413
					if (responseCode != HttpURLConnection.HTTP_OK) {
414
						throw new HttpException(responseCode);
415
					}
416
417
					return connection.getInputStream();
418
				}
419
420
			};
421
		}
422
423
		public void setProperty(String key, Object value) {
424
			// ignore, this is never called by the library
425
		}
426
427
	}
428
429
	private class HttpException extends IOException {
430
431
		private static final long serialVersionUID = 7083228933121822248L;
432
433
		final int responseCode;
434
435
		public HttpException(int responseCode) {
436
			super("HTTP Error " + responseCode);
437
438
			this.responseCode = responseCode;
439
		}
440
441
	}
442
443
}
355
}
(-)src/org/eclipse/mylar/internal/trac/core/TracHttpClientTransportFactory.java (+105 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Mylar project committers - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.trac.core;
13
14
import java.io.InputStream;
15
import java.lang.reflect.Field;
16
import java.net.HttpURLConnection;
17
import java.net.InetSocketAddress;
18
import java.net.Proxy;
19
20
import org.apache.commons.httpclient.HttpClient;
21
import org.apache.commons.httpclient.methods.PostMethod;
22
import org.apache.xmlrpc.XmlRpcException;
23
import org.apache.xmlrpc.client.XmlRpcClient;
24
import org.apache.xmlrpc.client.XmlRpcCommonsTransport;
25
import org.apache.xmlrpc.client.XmlRpcHttpClientConfig;
26
import org.apache.xmlrpc.client.XmlRpcTransport;
27
import org.apache.xmlrpc.client.XmlRpcTransportFactoryImpl;
28
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
29
30
/**
31
 * @author Steffen Pingel
32
 */
33
public class TracHttpClientTransportFactory extends XmlRpcTransportFactoryImpl {
34
35
	public static class TracHttpException extends XmlRpcException {
36
37
		private static final long serialVersionUID = 9032521978140685830L;
38
39
		public TracHttpException(int responseCode) {
40
			super(responseCode, "HTTP Error " + responseCode);
41
		}
42
43
	}
44
45
	/**
46
	 * A transport that uses the Apache HttpClient library. 
47
	 */
48
	public static class TracHttpClientTransport extends XmlRpcCommonsTransport {
49
50
		public TracHttpClientTransport(XmlRpcClient client) {
51
			super(client);
52
53
			Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings();
54
			if (proxySettings != null && proxySettings.address() instanceof InetSocketAddress) {
55
				InetSocketAddress address = (InetSocketAddress) proxySettings.address();
56
				getHttpClient().getHostConfiguration().setProxy(address.getHostName(), address.getPort());
57
			}
58
59
			XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) client.getConfig();
60
			// this needs to be set to avoid exceptions
61
			getHttpClient().getParams().setAuthenticationPreemptive(config.getBasicUserName() != null);
62
		}
63
64
		public HttpClient getHttpClient() {
65
			return (HttpClient) getValue("client");
66
		}
67
68
		@Override
69
		protected InputStream getInputStream() throws XmlRpcException {
70
			int responseCode = getMethod().getStatusCode();
71
			if (responseCode != HttpURLConnection.HTTP_OK) {
72
				throw new TracHttpException(responseCode);
73
			}
74
75
			return super.getInputStream();
76
		}
77
78
		public PostMethod getMethod() {
79
			return (PostMethod) getValue("method");
80
		}
81
82
		private Object getValue(String name) {
83
			try {
84
				Field field = XmlRpcCommonsTransport.class.getDeclaredField(name);
85
				field.setAccessible(true);
86
				return field.get(this);
87
			} catch (Throwable t) {
88
				throw new RuntimeException("Internal error accessing HttpClient", t);
89
			}
90
		}
91
92
	}
93
94
	private final TracHttpClientTransport transport;
95
96
	public TracHttpClientTransportFactory(XmlRpcClient client) {
97
		super(client);
98
99
		transport = new TracHttpClientTransport(client);
100
	}
101
102
	public XmlRpcTransport getTransport() {
103
		return transport;
104
	}
105
}
(-)src/org/eclipse/mylar/trac/tests/TracXmlRpcClientTest.java (+24 lines)
Lines 12-23 Link Here
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.net.URL;
14
import java.net.URL;
15
import java.util.Arrays;
16
import java.util.Comparator;
17
import java.util.Date;
15
18
19
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.mylar.internal.trac.core.ITracClient;
20
import org.eclipse.mylar.internal.trac.core.ITracClient;
17
import org.eclipse.mylar.internal.trac.core.TracLoginException;
21
import org.eclipse.mylar.internal.trac.core.TracLoginException;
18
import org.eclipse.mylar.internal.trac.core.TracRemoteException;
22
import org.eclipse.mylar.internal.trac.core.TracRemoteException;
19
import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
23
import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
20
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
24
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
25
import org.eclipse.mylar.internal.trac.model.TracVersion;
21
import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
26
import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
22
27
23
/**
28
/**
Lines 51-54 Link Here
51
		}
56
		}
52
	}
57
	}
53
58
59
	public void testUpdateAttributes() throws Exception {
60
		factory.connectRepository1();
61
		assertNull(factory.repository.getMilestones());
62
		factory.repository.updateAttributes(new NullProgressMonitor());
63
		TracVersion[] versions = factory.repository.getVersions();
64
		assertEquals(2, versions.length);
65
		Arrays.sort(versions, new Comparator<TracVersion>() {
66
			public int compare(TracVersion o1, TracVersion o2) {
67
				return o1.getName().compareTo(o2.getName());
68
			}
69
		});
70
		assertEquals("v1", versions[0].getName());
71
		assertEquals("description1", versions[0].getDescription());
72
		assertEquals(new Date(86400 * 1000), versions[0].getTime());
73
		assertEquals("v2", versions[1].getName());
74
		assertEquals("description2", versions[1].getDescription());
75
		assertEquals(new Date(86400 * 2 * 1000), versions[1].getTime());
76
	}
77
54
}
78
}
(-)src/org/eclipse/mylar/trac/tests/TracXmlRpcTest.java (-108 / +91 lines)
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
	}
(-)src/org/eclipse/mylar/trac/tests/AbstractTracClientSearchTest.java (-2 / +1 lines)
Lines 12-18 Link Here
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Hashtable;
16
import java.util.List;
15
import java.util.List;
17
import java.util.Map;
16
import java.util.Map;
18
17
Lines 61-67 Link Here
61
	protected void assertTicketEquals(Ticket ticket, TracTicket tracTicket) throws Exception {
60
	protected void assertTicketEquals(Ticket ticket, TracTicket tracTicket) throws Exception {
62
		assertTrue(tracTicket.isValid());
61
		assertTrue(tracTicket.isValid());
63
62
64
		Hashtable expectedValues = ticket.getValues();
63
		Map expectedValues = ticket.getValues();
65
		Map<String, String> values = tracTicket.getValues();
64
		Map<String, String> values = tracTicket.getValues();
66
		for (String key : values.keySet()) {
65
		for (String key : values.keySet()) {
67
			assertEquals("Values for key '" + key + "' did not match", expectedValues.get(key), values.get(key));
66
			assertEquals("Values for key '" + key + "' did not match", expectedValues.get(key), values.get(key));
(-)src/org/eclipse/mylar/trac/tests/Trac09ClientTest.java (+20 lines)
Lines 12-21 Link Here
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.net.URL;
14
import java.net.URL;
15
import java.util.Arrays;
16
import java.util.Comparator;
15
17
18
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.mylar.internal.trac.core.ITracClient;
19
import org.eclipse.mylar.internal.trac.core.ITracClient;
17
import org.eclipse.mylar.internal.trac.core.Trac09Client;
20
import org.eclipse.mylar.internal.trac.core.Trac09Client;
18
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
21
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
22
import org.eclipse.mylar.internal.trac.model.TracVersion;
19
import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
23
import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
20
24
21
/**
25
/**
Lines 36-39 Link Here
36
		factory.repository.validate();
40
		factory.repository.validate();
37
	}
41
	}
38
42
43
	public void testUpdateAttributes() throws Exception {
44
		factory.connectRepository1();
45
		assertNull(factory.repository.getMilestones());
46
		factory.repository.updateAttributes(new NullProgressMonitor());
47
		TracVersion[] versions = factory.repository.getVersions();
48
		assertEquals(2, versions.length);
49
		Arrays.sort(versions, new Comparator<TracVersion>() {
50
			public int compare(TracVersion o1, TracVersion o2) {
51
				return o1.getName().compareTo(o2.getName());
52
			}
53
		});
54
		assertEquals("v1", versions[0].getName());
55
		assertEquals("v2", versions[1].getName());
56
	}
57
58
39
}
59
}
(-)src/org/eclipse/mylar/trac/tests/AllTracTests.java (-3 / +4 lines)
Lines 22-29 Link Here
22
22
23
	public static Test suite() {
23
	public static Test suite() {
24
		TestSuite suite = new TestSuite("Test for org.eclipse.mylar.trac.tests");
24
		TestSuite suite = new TestSuite("Test for org.eclipse.mylar.trac.tests");
25
		//$JUnit-BEGIN$
25
		// $JUnit-BEGIN$
26
		suite.addTestSuite(TracXmlRpcTest.class);
26
		// suite.addTestSuite(TracXmlRpcTest.class);
27
		suite.addTestSuite(TracSearchTest.class);
27
		suite.addTestSuite(TracSearchTest.class);
28
		suite.addTestSuite(TracTicketTest.class);
28
		suite.addTestSuite(TracTicketTest.class);
29
		suite.addTestSuite(TracXmlRpcClientTest.class);
29
		suite.addTestSuite(TracXmlRpcClientTest.class);
Lines 33-39 Link Here
33
		suite.addTestSuite(TracClientFactoryTest.class);
33
		suite.addTestSuite(TracClientFactoryTest.class);
34
		suite.addTestSuite(TracRepositoryConnectorTest.class);
34
		suite.addTestSuite(TracRepositoryConnectorTest.class);
35
		suite.addTestSuite(TracQueryTest.class);
35
		suite.addTestSuite(TracQueryTest.class);
36
		//$JUnit-END$
36
		suite.addTestSuite(TracRepositoryQueryTest.class);
37
		// $JUnit-END$
37
		return suite;
38
		return suite;
38
	}
39
	}
39
40
(-)src/org/eclipse/mylar/trac/tests/TracClientFactoryTest.java (+10 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.net.Authenticator;
15
14
import junit.framework.TestCase;
16
import junit.framework.TestCase;
15
17
16
import org.eclipse.mylar.internal.trac.core.ITracClient;
18
import org.eclipse.mylar.internal.trac.core.ITracClient;
Lines 26-31 Link Here
26
 */
28
 */
27
public class TracClientFactoryTest extends TestCase {
29
public class TracClientFactoryTest extends TestCase {
28
30
31
	@Override
32
	protected void setUp() throws Exception {
33
		super.setUp();
34
		
35
		// make sure no dialog pops up to prompt for a password
36
		Authenticator.setDefault(null);
37
	}
38
	
29
	public void testCreateClient() throws Exception {
39
	public void testCreateClient() throws Exception {
30
		ITracClient client = TracClientFactory.createClient(Constants.TEST_REPOSITORY1_URL, Version.TRAC_0_9, "user",
40
		ITracClient client = TracClientFactory.createClient(Constants.TEST_REPOSITORY1_URL, Version.TRAC_0_9, "user",
31
				"password");
41
				"password");
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 7-13 Link Here
7
Require-Bundle: org.junit,
7
Require-Bundle: org.junit,
8
 org.eclipse.ui,
8
 org.eclipse.ui,
9
 org.eclipse.core.runtime,
9
 org.eclipse.core.runtime,
10
 org.apache.xmlrpc,
10
 org.eclipse.mylar.context.core,
11
 org.eclipse.mylar.tasks.ui,
11
 org.eclipse.mylar.tasks.ui,
12
 org.eclipse.mylar.trac,
12
 org.eclipse.mylar.trac,
13
 org.eclipse.mylar.tasks.core
13
 org.eclipse.mylar.tasks.core
(-)src/org/eclipse/mylar/trac/tests/support/XmlRpcServer.java (-18 / +11 lines)
Lines 18-27 Link Here
18
import java.util.Arrays;
18
import java.util.Arrays;
19
import java.util.Hashtable;
19
import java.util.Hashtable;
20
import java.util.List;
20
import java.util.List;
21
import java.util.Map;
21
import java.util.Vector;
22
import java.util.Vector;
22
23
23
import org.apache.xmlrpc.XmlRpcClient;
24
import org.apache.xmlrpc.XmlRpcException;
24
import org.apache.xmlrpc.XmlRpcException;
25
import org.apache.xmlrpc.client.XmlRpcClient;
25
import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
26
import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
26
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
27
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
27
28
Lines 80-91 Link Here
80
		}
81
		}
81
82
82
		public ModelEnum deleteAndCreate(Object... params) throws Exception {
83
		public ModelEnum deleteAndCreate(Object... params) throws Exception {
83
			try {
84
			if (Arrays.asList(getAll()).contains(id)) {
84
				if (Arrays.asList(getAll()).contains(id)) {
85
				delete();
85
					delete();
86
				}
87
			} catch (Exception e) {
88
				// ignore
89
			}
86
			}
90
87
91
			return create(params);
88
			return create(params);
Lines 102-108 Link Here
102
99
103
		@SuppressWarnings("unchecked")
100
		@SuppressWarnings("unchecked")
104
		public String[] getAll() throws Exception {
101
		public String[] getAll() throws Exception {
105
			return (String[]) ((Vector) call(module + ".getAll")).toArray(new String[0]);
102
			return Arrays.asList((Object[]) call(module + ".getAll")).toArray(new String[0]);
106
		}
103
		}
107
104
108
		private Hashtable<String, Object> toMap(Object... params) {
105
		private Hashtable<String, Object> toMap(Object... params) {
Lines 178-190 Link Here
178
			return getValues().get(key);
175
			return getValues().get(key);
179
		}
176
		}
180
177
181
		public Hashtable getValues() throws Exception {
178
		public Map getValues() throws Exception {
182
			return (Hashtable) ((Vector) call("ticket.get", id)).get(3);
179
			return (Map) ((Object[]) call("ticket.get", id))[3];
183
		}
180
		}
184
181
185
		@SuppressWarnings("unchecked")
182
		@SuppressWarnings("unchecked")
186
		public Integer[] getAll() throws Exception {
183
		public Integer[] getAll() throws Exception {
187
			return (Integer[]) ((Vector) call("ticket.query", "order=id")).toArray(new Integer[0]);
184
			return Arrays.asList((Object[]) call("ticket.query", "order=id")).toArray(new Integer[0]);
188
		}
185
		}
189
186
190
		public int getId() {
187
		public int getId() {
Lines 245-256 Link Here
245
		}
242
		}
246
243
247
		public TicketEnum deleteAndCreate(String param) throws Exception {
244
		public TicketEnum deleteAndCreate(String param) throws Exception {
248
			try {
245
			if (Arrays.asList(getAll()).contains(id)) {
249
				if (Arrays.asList(getAll()).contains(id)) {
246
				delete();
250
					delete();
251
				}
252
			} catch (Exception e) {
253
				// ignore
254
			}
247
			}
255
248
256
			return create(param);
249
			return create(param);
Lines 262-268 Link Here
262
255
263
		@SuppressWarnings("unchecked")
256
		@SuppressWarnings("unchecked")
264
		public String[] getAll() throws Exception {
257
		public String[] getAll() throws Exception {
265
			return (String[]) ((Vector) call(module + ".getAll")).toArray(new String[0]);
258
			return Arrays.asList((Object[]) call(module + ".getAll")).toArray(new String[0]);
266
		}
259
		}
267
260
268
		public TicketEnum update(String param) throws Exception {
261
		public TicketEnum update(String param) throws Exception {
(-)src/org/eclipse/mylar/trac/tests/support/TestFixture.java (+4 lines)
Lines 30-35 Link Here
30
			XmlRpcServer server = new XmlRpcServer(Constants.TEST_REPOSITORY1_URL,
30
			XmlRpcServer server = new XmlRpcServer(Constants.TEST_REPOSITORY1_URL,
31
					Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
31
					Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
32
32
33
			server.ticketVersion(null).deleteAll();
34
			server.ticketVersion("v1").create(86400, "description1");
35
			server.ticketVersion("v2").create(86400 * 2, "description2");
36
			
33
			server.ticket().deleteAll();
37
			server.ticket().deleteAll();
34
38
35
			server.ticketMilestone("m1").deleteAndCreate();
39
			server.ticketMilestone("m1").deleteAndCreate();
(-)src/org/eclipse/mylar/trac/tests/TracRepositoryQueryTest.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Mylar project committers - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.trac.tests;
13
14
import java.util.Arrays;
15
import java.util.List;
16
17
import junit.framework.TestCase;
18
19
import org.eclipse.mylar.internal.trac.TracRepositoryQuery;
20
import org.eclipse.mylar.internal.trac.core.ITracClient;
21
import org.eclipse.mylar.internal.trac.model.TracSearch;
22
import org.eclipse.mylar.internal.trac.model.TracSearchFilter;
23
24
public class TracRepositoryQueryTest extends TestCase {
25
26
	public void testGetFilterList() {
27
		String repositoryUrl = "https://foo.bar/repo";
28
		String parameterUrl = "&status=new&status=assigned&status=reopened&milestone=0.1";
29
		String queryUrl = repositoryUrl + ITracClient.QUERY_URL + parameterUrl;
30
		TracRepositoryQuery query = new TracRepositoryQuery(repositoryUrl, queryUrl, "description", null);
31
32
		TracSearch filterList = query.getTracSearch();
33
34
		assertEquals(parameterUrl, filterList.toUrl());
35
		assertEquals("&status=new|assigned|reopened&milestone=0.1", filterList.toQuery());
36
37
		List<TracSearchFilter> list = filterList.getFilters();
38
		TracSearchFilter filter = list.get(0);
39
		assertEquals("status", filter.getFieldName());
40
		assertEquals(Arrays.asList("new", "assigned", "reopened"), filter.getValues());
41
		filter = list.get(1);
42
		assertEquals("milestone", filter.getFieldName());
43
		assertEquals(Arrays.asList("0.1"), filter.getValues());
44
	}
45
46
}

Return to bug 151896