Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a40acf618dbe01d8dea06e181ad128956aba86b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/****************************************************************************
 * Copyright (c) 2009 EclipseSource and others.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * Contributors:
 *   EclipseSource - initial API and implementation
 *
 * SPDX-License-Identifier: EPL-2.0
 *****************************************************************************/
package org.eclipse.ecf.tests.remoteservice.rest;

import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.remoteservice.IRemoteCallListener;
import org.eclipse.ecf.remoteservice.IRemoteService;
import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
import org.eclipse.ecf.remoteservice.client.IRemoteCallable;
import org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent;
import org.eclipse.ecf.remoteservice.events.IRemoteCallEvent;
import org.eclipse.ecf.remoteservice.rest.IRestCall;
import org.eclipse.ecf.remoteservice.rest.RestCallFactory;
import org.eclipse.ecf.remoteservice.rest.RestCallableFactory;
import org.eclipse.equinox.concurrent.future.IFuture;
import org.w3c.dom.Document;

public class RestRemoteServiceTest extends AbstractRestTestCase {

	IContainer container;
	IRemoteServiceRegistration registration;
	
	protected void setUp() throws Exception {
		container = createRestContainer(RestConstants.TEST_TWITTER_TARGET);
		IRemoteCallable callable = RestCallableFactory.createCallable(RestConstants.TEST_TWITTER_RESOURCEPATH);
		registration = registerCallable(container, callable, null);
	}

	protected void tearDown() throws Exception {
		registration.unregister();
		container.disconnect();
	}

	
	public void testSyncCall() {
		// XXX Removed test because it depends upon twitter service, which has changed
//		IRemoteService restClientService = getRemoteServiceClientContainerAdapter(container).getRemoteService(registration.getReference());
//		try {
//			Object result = restClientService.callSync(getRestXMLCall());
//			assertNotNull(result);
//		} catch (ECFException e) {
//			fail("Could not contact the service");
//		}
	}

	public void testAsynCall() {
		// XXX Removed test because it depends upon twitter service, which has changed
//		IRemoteService restClientService = getRemoteServiceClientContainerAdapter(container).getRemoteService(registration.getReference());
//		IFuture future = restClientService.callAsync(getRestXMLCall());
//		try {
//			Object response = future.get();
//			assertTrue(response instanceof Document);
//		} catch (OperationCanceledException e) {
//			fail(e.getMessage());
//		} catch (InterruptedException e) {
//			fail(e.getMessage());
//		}
	}

	public void testAsyncCallWithListener() throws Exception {
		// XXX Removed test because it depends upon twitter service, which has changed
//		IRemoteService restClientService = getRemoteServiceClientContainerAdapter(container).getRemoteService(registration.getReference());
//		restClientService.callAsync(getRestXMLCall(), new IRemoteCallListener() {
//			public void handleEvent(IRemoteCallEvent event) {
//				if (event instanceof IRemoteCallCompleteEvent) {
//					IRemoteCallCompleteEvent cce = (IRemoteCallCompleteEvent) event;
//					Object response = cce.getResponse();
//					assertTrue(response instanceof Document);
//					syncNotify();
//				}
//			}
//		});
//		syncWaitForNotify(10000);
	}


	private IRestCall getRestXMLCall() {
		return RestCallFactory.createRestCall(RestConstants.TEST_TWITTER_RESOURCEPATH);
	}

}

Back to the top