Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2011-01-09 22:36:03 -0500
committerslewis2011-01-09 22:36:03 -0500
commit2573731bf982d74dade98043cd778a8129fec2e9 (patch)
treefb0cdefe152bed9e130ae06be375f000106a9629 /incubation
parentd968b1bba5ec4d158156d75c89be610fb578504e (diff)
downloadorg.eclipse.ecf-2573731bf982d74dade98043cd778a8129fec2e9.tar.gz
org.eclipse.ecf-2573731bf982d74dade98043cd778a8129fec2e9.tar.xz
org.eclipse.ecf-2573731bf982d74dade98043cd778a8129fec2e9.zip
Fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=333818 and
addition of test cases.
Diffstat (limited to 'incubation')
-rw-r--r--incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF2
-rw-r--r--incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractDistributionTest.java3
-rw-r--r--incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionWriterTest.java92
-rw-r--r--incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractMetadataFactoryTest.java7
-rw-r--r--incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractRemoteServiceAccessTest.java3
-rw-r--r--incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractTwoRemoteServiceAccessTest.java158
-rw-r--r--incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestService1.java6
-rw-r--r--incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestServiceInterface2.java7
8 files changed, 263 insertions, 15 deletions
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
index 5ca436286..53aec2392 100644
--- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
+++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
@@ -24,4 +24,4 @@ Import-Package: org.eclipse.ecf.core,
Require-Bundle: org.eclipse.equinox.common;bundle-version="3.6.0",
org.junit;bundle-version="4.8.1",
org.eclipse.ecf.tests;bundle-version="2.1.0"
-Export-Package: org.eclipse.ecf.tests.osgi.services.remoteserviceadmin
+Export-Package: org.eclipse.ecf.tests.osgi.services.remoteserviceadmin;version="1.1.1"
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractDistributionTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractDistributionTest.java
index 0b2be69ea..64d5247cc 100644
--- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractDistributionTest.java
+++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractDistributionTest.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin;
+import java.util.Arrays;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Properties;
@@ -181,7 +182,7 @@ public abstract class AbstractDistributionTest extends
.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
assertTrue(classes != null);
// Check object class
- assertTrue(classname.equals(classes[0]));
+ assertTrue(Arrays.asList(classes).contains(classname));
}
protected void assertReferencesValidAndFirstHasCorrectType(
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionWriterTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionWriterTest.java
new file mode 100644
index 000000000..c4effd789
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionWriterTest.java
@@ -0,0 +1,92 @@
+package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionWriter;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionAdvertiser;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+public abstract class AbstractEndpointDescriptionWriterTest extends
+ AbstractDistributionTest {
+
+ protected static final int REGISTER_WAIT = 2000;
+ private ServiceRegistration registration;
+
+ private ServiceRegistration writerEndpointDescriptionAdvertiser;
+ private EndpointDescriptionWriter writer;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ writer = new EndpointDescriptionWriter();
+ writerEndpointDescriptionAdvertiser = getContext().registerService(IEndpointDescriptionAdvertiser.class.getName(), createStandardOutputWriterServiceInfoFactory(), null);
+ }
+
+ private IEndpointDescriptionAdvertiser createStandardOutputWriterServiceInfoFactory() {
+ return new IEndpointDescriptionAdvertiser() {
+
+ @Override
+ public IStatus advertise(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
+ // TODO Auto-generated method stub
+ try {
+ StringWriter sr = new StringWriter();
+ sr.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\n");
+ writer.writeEndpointDescriptions(sr, new EndpointDescription[] { (EndpointDescription) endpointDescription });
+ System.out.print(sr.toString());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ public IStatus unadvertise(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
+ // TODO Auto-generated method stub
+ return Status.OK_STATUS;
+ }
+ };
+ }
+
+ protected void tearDown() throws Exception {
+ if (registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ if (writerEndpointDescriptionAdvertiser != null) {
+ writerEndpointDescriptionAdvertiser.unregister();
+ writerEndpointDescriptionAdvertiser = null;
+ }
+ super.tearDown();
+ }
+
+ public void testRegisterOnCreatedServer() throws Exception {
+ Properties props = getServiceProperties();
+ // Actually register with default service (IConcatService)
+ registration = registerDefaultService(props);
+ // Wait a while
+ Thread.sleep(REGISTER_WAIT);
+ }
+
+ protected abstract String getServerContainerTypeName();
+
+ private Properties getServiceProperties() {
+ Properties props = new Properties();
+ // Set config to the server container name/provider config name (e.g.
+ // ecf.generic.server)
+ props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS,
+ getServerContainerTypeName());
+ // Set the service exported interfaces to all
+ props.put(RemoteConstants.SERVICE_EXPORTED_INTERFACES, "*");
+ return props;
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractMetadataFactoryTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractMetadataFactoryTest.java
index 51ec506a2..727ad91f4 100644
--- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractMetadataFactoryTest.java
+++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractMetadataFactoryTest.java
@@ -94,7 +94,6 @@ public abstract class AbstractMetadataFactoryTest extends ECFAbstractTestCase {
Map<String,Object> props = new HashMap<String,Object>();
// Add required OSGi properties
addRequiredOSGiProperties(props);
- ID containerID = createECFContainerID(props);
createECFRemoteServiceId(props);
// Add extra properties
addExtraProperties(props);
@@ -108,11 +107,6 @@ public abstract class AbstractMetadataFactoryTest extends ECFAbstractTestCase {
// Add full OSGi properties
addOptionalOSGiProperties(props);
// required ECF properties
- ID containerID = createECFContainerID(props);
- createECFRemoteServiceId(props);
- ID targetID = createECFTargetID(props);
- ID[] idFilter = createECFIDFilterIDs(props);
- String rsFilter = createECFRSFilter(props);
// Add extra properties
addExtraProperties(props);
return new EndpointDescription(props);
@@ -127,7 +121,6 @@ public abstract class AbstractMetadataFactoryTest extends ECFAbstractTestCase {
Map<String,Object> props = new HashMap<String,Object>();
// Add only ECF properties
// no OSGi properties
- ID containerID = createECFContainerID(props);
createECFRemoteServiceId(props);
// This should throw a runtime exception
return new EndpointDescription(props);
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractRemoteServiceAccessTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractRemoteServiceAccessTest.java
index 8038947eb..b4815dd81 100644
--- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractRemoteServiceAccessTest.java
+++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractRemoteServiceAccessTest.java
@@ -18,9 +18,6 @@ import org.eclipse.ecf.remoteservice.IRemoteService;
import org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent;
import org.eclipse.ecf.remoteservice.events.IRemoteCallEvent;
import org.eclipse.equinox.concurrent.future.IFuture;
-import org.osgi.framework.AllServiceListener;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.remoteserviceadmin.RemoteConstants;
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractTwoRemoteServiceAccessTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractTwoRemoteServiceAccessTest.java
new file mode 100644
index 000000000..54add6c4b
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractTwoRemoteServiceAccessTest.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Composent and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin;
+
+import java.util.Properties;
+
+import org.eclipse.ecf.core.util.Trace;
+import org.eclipse.ecf.remoteservice.IRemoteCall;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+import org.osgi.util.tracker.ServiceTracker;
+
+public abstract class AbstractTwoRemoteServiceAccessTest extends
+ AbstractDistributionTest {
+
+ protected static final int REGISTER_WAIT = Integer.parseInt(System.getProperty("waittime","15000"));
+
+ private final String[] classes = new String[] { TestServiceInterface1.class.getName(), TestServiceInterface2.class.getName() };
+
+ private ServiceTracker st;
+ private ServiceRegistration registration;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.tests.osgi.services.distribution.AbstractDistributionTest#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ // Unregister on server
+ if (registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ if (st != null) {
+ st.close();
+ st = null;
+ }
+ Thread.sleep(REGISTER_WAIT);
+
+ super.tearDown();
+ }
+
+ protected void createServiceTrackerAndRegister(String lookupClass, final Properties props) throws Exception {
+ // Setup service tracker for client
+ st = createProxyServiceTracker(lookupClass);
+
+ // Actually register
+ registration = registerService(classes,
+ new TestService1(), props);
+
+ // Wait
+ Thread.sleep(REGISTER_WAIT);
+ }
+
+ protected void createServiceTrackerAndRegister(String lookupClass) throws Exception {
+ createServiceTrackerAndRegister(lookupClass, getServiceProperties());
+ }
+
+ protected Properties getServiceProperties() {
+ final Properties props = new Properties();
+ props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, getServerContainerName());
+ props.put(RemoteConstants.SERVICE_EXPORTED_INTERFACES, "*");
+ return props;
+ }
+
+ protected IRemoteCall createRemoteCall() {
+ return new IRemoteCall() {
+
+ public String getMethod() {
+ return "doStuff1";
+ }
+
+ public Object[] getParameters() {
+ return new Object[] {};
+ }
+
+ public long getTimeout() {
+ return 30000;
+ }
+
+ };
+ }
+
+
+ public void testGetRemoteService1Reference() throws Exception {
+ String lookupClass = TestServiceInterface1.class.getName();
+ createServiceTrackerAndRegister(lookupClass);
+
+ // Service Consumer - Get (remote) ervice references
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
+ assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass);
+ // Spec requires that the 'service.imported' property be set
+ assertTrue(remoteReferences[0].getProperty(RemoteConstants.SERVICE_IMPORTED) != null);
+ }
+
+ public void testGetRemoteService2Reference() throws Exception {
+ String lookupClass = TestServiceInterface2.class.getName();
+ createServiceTrackerAndRegister(lookupClass);
+
+ // Service Consumer - Get (remote) ervice references
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
+ assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass);
+ // Spec requires that the 'service.imported' property be set
+ assertTrue(remoteReferences[0].getProperty(RemoteConstants.SERVICE_IMPORTED) != null);
+ }
+
+
+ public void testProxyWithService1() throws Exception {
+ String lookupClass = TestServiceInterface1.class.getName();
+ createServiceTrackerAndRegister(lookupClass);
+
+ // Client - Get service references from service tracker
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
+ assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass);
+
+ // Get proxy/service
+ final TestServiceInterface1 proxy = (TestServiceInterface1) getContext()
+ .getService(remoteReferences[0]);
+ assertNotNull(proxy);
+ // Now use proxy
+ final String result = proxy.doStuff1();
+ Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff1 result=" + result);
+ assertTrue(TestServiceInterface1.TEST_SERVICE_STRING1.equals(result));
+ }
+
+ public void testProxyWithService2() throws Exception {
+
+ String lookupClass = TestServiceInterface2.class.getName();
+
+ createServiceTrackerAndRegister(lookupClass);
+
+ // Client - Get service references from service tracker
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
+ assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass);
+
+ // Get proxy/service
+ final TestServiceInterface2 proxy = (TestServiceInterface2) getContext()
+ .getService(remoteReferences[0]);
+ assertNotNull(proxy);
+ // Now use proxy
+ String result = proxy.doStuff1();
+ Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff1 result=" + result);
+ assertTrue(TestServiceInterface1.TEST_SERVICE_STRING1.equals(result));
+
+ // Now use proxy
+ result = proxy.doStuff2();
+ Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff2 result=" + result);
+ assertTrue(TestServiceInterface2.TEST_SERVICE_STRING2.equals(result));
+
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestService1.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestService1.java
index d1bfb7770..40644d7d1 100644
--- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestService1.java
+++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestService1.java
@@ -10,10 +10,14 @@
*****************************************************************************/
package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin;
-public final class TestService1 implements TestServiceInterface1 {
+public final class TestService1 implements TestServiceInterface1, TestServiceInterface2 {
public String doStuff1() {
return TestServiceInterface1.TEST_SERVICE_STRING1;
}
+ public String doStuff2() {
+ return TestServiceInterface2.TEST_SERVICE_STRING2;
+ }
+
}
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestServiceInterface2.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestServiceInterface2.java
index e078e56c5..313d22410 100644
--- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestServiceInterface2.java
+++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestServiceInterface2.java
@@ -10,8 +10,11 @@
*****************************************************************************/
package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin;
-public interface TestServiceInterface2 {
+public interface TestServiceInterface2 extends TestServiceInterface1 {
- void doStuff2();
+ public static final String TEST_SERVICE_STRING2 = "TestService2";
+
+
+ String doStuff2();
}

Back to the top