You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2013/05/14 22:51:29 UTC

svn commit: r1482581 - in /cxf/dosgi/trunk/systests2: common/src/main/java/org/apache/cxf/dosgi/systests2/common/ multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/ single-bundle/

Author: cschneider
Date: Tue May 14 20:51:29 2013
New Revision: 1482581

URL: http://svn.apache.org/r1482581
Log:
DOSGI-181 Consolidate system tests

Added:
    cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java   (with props)
Removed:
    cxf/dosgi/trunk/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/AbstractTestDiscoveryRoundtrip.java
    cxf/dosgi/trunk/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/AbstractTestExportService.java
    cxf/dosgi/trunk/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/AbstractTestImportService.java
    cxf/dosgi/trunk/systests2/single-bundle/
Modified:
    cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java
    cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java
    cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java
    cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
    cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java

Added: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java?rev=1482581&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java (added)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java Tue May 14 20:51:29 2013
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.dosgi.systests2.multi;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.dosgi.samples.greeter.GreeterService;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class AbstractDosgiTest {
+
+	protected ServiceReference waitService(BundleContext bc, Class<?> cls,
+			String filter, int timeout) throws Exception {
+		ServiceReference[] refs = null;
+		for (int i = 0; i < timeout; i++) {
+			refs = bc.getServiceReferences(cls.getName(), filter);
+			if (refs != null && refs.length > 0) {
+				return refs[0];
+			}
+			System.out.println("Waiting for service: " + cls + filter);
+			Thread.sleep(1000);
+		}
+		throw new Exception("Service not found: " + cls + filter);
+	}
+
+	protected int getIntSysProperty(String key, int defaultValue) {
+		String valueSt = System.getProperty(key);
+        int value = valueSt == null ? 0 : Integer.valueOf(valueSt);
+        return (value > 0) ? value : defaultValue;
+	}
+	
+	protected void waitPort(int port) throws Exception {
+	    for (int i = 0; i < 20; i++) {
+	        Socket s = null;
+	        try {
+	            s = new Socket((String) null, port);
+	            // yep, its available
+	            return;
+	        } catch (IOException e) {
+	            // wait 
+	        } finally {
+	            if (s != null) {
+	                try {
+	                    s.close();
+	                } catch (IOException e) {
+	                    //ignore
+	                }
+	            }
+	        }
+	        System.out.println("Waiting for server to appear on port: " + port);
+	        Thread.sleep(1000);            
+	    }
+	    throw new TimeoutException();
+	}
+
+	protected GreeterService createGreeterServiceProxy(String serviceUri) {
+		ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
+		factory.setServiceClass(GreeterService.class);
+		factory.setAddress(serviceUri);
+		factory.getServiceFactory().setDataBinding(new AegisDatabinding());
+		return (GreeterService)factory.create();
+	}
+
+	protected Bundle getBundleByName(BundleContext bc, String sn) {
+	    for (Bundle bundle : bc.getBundles()) {
+	        if (bundle.getSymbolicName().equals(sn)) {
+	            return bundle;
+	        }
+	    }
+	    return null;
+	}
+
+	protected int getFreePort() throws IOException {
+	    ServerSocket socket = new ServerSocket(0);
+	    try {
+	        return socket.getLocalPort();
+	    } finally {
+	        socket.close();
+	    }
+	}
+
+}

Propchange: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java?rev=1482581&r1=1482580&r2=1482581&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java (original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java Tue May 14 20:51:29 2013
@@ -18,20 +18,21 @@
  */
 package org.apache.cxf.dosgi.systests2.multi;
 
-import java.io.IOException;
+import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
 import java.io.InputStream;
-import java.net.Socket;
 import java.util.Map;
-import java.util.concurrent.TimeoutException;
 
 import javax.inject.Inject;
 
 import junit.framework.Assert;
 
-import org.apache.cxf.aegis.databinding.AegisDatabinding;
 import org.apache.cxf.dosgi.samples.greeter.GreeterService;
 import org.apache.cxf.dosgi.samples.greeter.GreetingPhrase;
-import org.apache.cxf.dosgi.systests2.common.AbstractTestExportService;
 import org.apache.cxf.dosgi.systests2.multi.customintent.AddGreetingPhraseInterceptor;
 import org.apache.cxf.dosgi.systests2.multi.customintent.CustomFeature;
 import org.apache.cxf.dosgi.systests2.multi.customintent.CustomIntentActivator;
@@ -44,19 +45,12 @@ import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 
-import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.provision;
-import static org.ops4j.pax.exam.CoreOptions.streamBundle;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-
 
 @RunWith(JUnit4TestRunner.class)
-public class TestCustomIntent extends AbstractTestExportService {
+public class TestCustomIntent extends AbstractDosgiTest {
     @Inject
     BundleContext bundleContext;
 
@@ -100,16 +94,11 @@ public class TestCustomIntent extends Ab
         Thread.sleep(2000);
         getBundleByName(bundleContext, "CustomIntent").start();
         waitPort(9090);
-        ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
-        factory.setServiceClass(GreeterService.class);
-        factory.setAddress("http://localhost:9090/greeter");
-        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
-        factory.setServiceClass(GreeterService.class);
 
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(ClientProxyFactoryBean.class.getClassLoader());
         try {
-            GreeterService greeterService = (GreeterService) factory.create();
+            GreeterService greeterService = createGreeterServiceProxy("http://localhost:9090/greeter");
             Map<GreetingPhrase, String> result = greeterService.greetMe("Chris");
             Assert.assertEquals(1, result.size());
             GreetingPhrase phrase = result.keySet().iterator().next();
@@ -118,37 +107,5 @@ public class TestCustomIntent extends Ab
             Thread.currentThread().setContextClassLoader(cl);
         }
     }
-    
-    private Bundle getBundleByName(BundleContext bc, String sn) {
-        for (Bundle bundle : bc.getBundles()) {
-            if (bundle.getSymbolicName().equals(sn)) {
-                return bundle;
-            }
-        }
-        return null;
-    }
 
-    private void waitPort(int port) throws Exception {
-        for (int i = 0; i < 20; i++) {
-            Socket s = null;
-            try {
-                s = new Socket((String) null, port);
-                // yep, its available
-                return;
-            } catch (IOException e) {
-                // wait 
-            } finally {
-                if (s != null) {
-                    try {
-                        s.close();
-                    } catch (IOException e) {
-                        //ignore
-                    }
-                }
-            }
-            System.out.println("Waiting for server to appear on port: " + port);
-            Thread.sleep(10000);            
-        }
-        throw new TimeoutException();
-    }
 }

Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java?rev=1482581&r1=1482580&r2=1482581&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java (original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java Tue May 14 20:51:29 2013
@@ -19,13 +19,19 @@
 package org.apache.cxf.dosgi.systests2.multi;
 
 import java.io.IOException;
-import java.net.ServerSocket;
+import java.io.InputStream;
+import java.util.Dictionary;
+import java.util.Hashtable;
 
 import javax.inject.Inject;
 
 import junit.framework.Assert;
 
-import org.apache.cxf.dosgi.systests2.common.AbstractTestDiscoveryRoundtrip;
+import org.apache.cxf.dosgi.systests2.common.test2.Test2Service;
+import org.apache.cxf.dosgi.systests2.common.test2.client.ClientActivator;
+import org.apache.cxf.dosgi.systests2.common.test2.client.Test2ServiceTracker;
+import org.apache.cxf.dosgi.systests2.common.test2.server.ServerActivator;
+import org.apache.cxf.dosgi.systests2.common.test2.server.Test2ServiceImpl;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
 import org.junit.Test;
@@ -33,7 +39,9 @@ import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.service.cm.ConfigurationAdmin;
 
 import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
@@ -42,9 +50,11 @@ import static org.ops4j.pax.exam.CoreOpt
 
 
 @RunWith(JUnit4TestRunner.class)
-public class TestDiscoveryExport extends AbstractTestDiscoveryRoundtrip {
+public class TestDiscoveryExport extends AbstractDosgiTest {
 
-    @Inject
+    private static final String GREETER_ZOOKEEPER_NODE = "/osgi/service_registry/org/apache/cxf/dosgi/samples/greeter/GreeterService/localhost#9090##greeter";
+
+	@Inject
     BundleContext bundleContext;
 
     @Inject
@@ -72,13 +82,11 @@ public class TestDiscoveryExport extends
         final int zkPort = getFreePort();
         configureZookeeper(configAdmin, zkPort);
         ZooKeeper zk = new ZooKeeper("localhost:" + zkPort, 1000, null);
-        assertExists(zk, 
-            "/osgi/service_registry/org/apache/cxf/dosgi/samples/greeter/GreeterService/localhost#9090##greeter",
-            4000);
+        assertNodeExists(zk, GREETER_ZOOKEEPER_NODE, 4000);
         zk.close();
     }
 
-    private void assertExists(ZooKeeper zk, String zNode, int timeout) {
+    private void assertNodeExists(ZooKeeper zk, String zNode, int timeout) {
         long endTime = System.currentTimeMillis() + timeout;
         Stat stat = null;
         while (stat == null  && System.currentTimeMillis() < endTime) {
@@ -92,12 +100,43 @@ public class TestDiscoveryExport extends
         Assert.assertNotNull("Zookeeper node " + zNode + " was not found", stat);
     }
 
-    private int getFreePort() throws IOException {
-        ServerSocket socket = new ServerSocket(0);
-        try {
-            return socket.getLocalPort();
-        } finally {
-            socket.close();
-        }
+    protected static InputStream getClientBundle() {
+        return TinyBundles.newBundle()
+            .add(ClientActivator.class)
+            .add(Test2Service.class)
+            .add(Test2ServiceTracker.class)
+            .set(Constants.BUNDLE_SYMBOLICNAME, "test2ClientBundle")
+            .set(Constants.BUNDLE_ACTIVATOR, ClientActivator.class.getName())
+            .build(TinyBundles.withBnd());
+    }
+
+    protected static InputStream getServerBundle() {
+        return TinyBundles.newBundle()
+            .add(ServerActivator.class)
+            .add(Test2Service.class)
+            .add(Test2ServiceImpl.class)
+            .set(Constants.BUNDLE_SYMBOLICNAME, "test2ServerBundle")
+            .set(Constants.BUNDLE_ACTIVATOR, ServerActivator.class.getName())
+            .build(TinyBundles.withBnd());
+    }
+
+    protected void configureZookeeper(ConfigurationAdmin configAdmin, int zkPort) throws IOException {
+        System.out.println("*** Port for Zookeeper Server: " + zkPort);
+        updateZkServerConfig(zkPort, configAdmin);                            
+        updateZkClientConfig(zkPort, configAdmin);
+    }
+    
+    protected void updateZkClientConfig(final int zkPort, ConfigurationAdmin cadmin) throws IOException {
+        Dictionary<String, Object> cliProps = new Hashtable<String, Object>();
+        cliProps.put("zookeeper.host", "127.0.0.1");
+        cliProps.put("zookeeper.port", "" + zkPort);
+        cadmin.getConfiguration("org.apache.cxf.dosgi.discovery.zookeeper", null).update(cliProps);
+    }
+
+    protected void updateZkServerConfig(final int zkPort, ConfigurationAdmin cadmin) throws IOException {
+        Dictionary<String, Object> svrProps = new Hashtable<String, Object>();
+        svrProps.put("clientPort", zkPort);
+        cadmin.getConfiguration("org.apache.cxf.dosgi.discovery.zookeeper.server", null).update(svrProps);
     }
+    
 }

Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java?rev=1482581&r1=1482580&r2=1482581&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java (original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java Tue May 14 20:51:29 2013
@@ -19,9 +19,9 @@
 package org.apache.cxf.dosgi.systests2.multi;
 
 
-import java.io.IOException;
-import java.net.Socket;
-import java.util.concurrent.TimeoutException;
+import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
 import javax.inject.Inject;
 
@@ -32,12 +32,8 @@ import org.ops4j.pax.exam.junit.Configur
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.BundleContext;
 
-import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-
 @RunWith(JUnit4TestRunner.class)
-public class TestExportRestService {
+public class TestExportRestService extends AbstractDosgiTest {
     @Inject
     BundleContext bundleContext;
 
@@ -52,39 +48,13 @@ public class TestExportRestService {
                     .artifactId("cxf-dosgi-ri-samples-greeter-rest-interface").versionAsInProject(),
                 mavenBundle().groupId("org.apache.cxf.dosgi.samples")
                     .artifactId("cxf-dosgi-ri-samples-greeter-rest-impl").versionAsInProject(),
-                //mavenBundle().groupId("org.apache.cxf.dosgi.systests")
-                //    .artifactId("cxf-dosgi-ri-systests2-common").versionAsInProject(),
                 frameworkStartLevel(100)
         };
     }
     
     @Test
-    public void testAccessEndpoint() throws Exception {
-        // call into base test. Inheriting the test doesn't properly report failures.
+    public void testEndpointAvailable() throws Exception {
         waitPort(8080);
     }
-    
-    private void waitPort(int port) throws Exception {
-        for (int i = 0; i < 20; i++) {
-            Socket s = null;
-            try {
-                s = new Socket((String) null, port);
-                // yep, its available
-                return;
-            } catch (IOException e) {
-                // wait 
-            } finally {
-                if (s != null) {
-                    try {
-                        s.close();
-                    } catch (IOException e) {
-                        //ignore
-                    }
-                }
-            }
-            System.out.println("Waiting for server to appear on port: " + port);
-            Thread.sleep(1000);            
-        }
-        throw new TimeoutException();
-    }
+
 }

Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java?rev=1482581&r1=1482580&r2=1482581&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java (original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java Tue May 14 20:51:29 2013
@@ -18,15 +18,30 @@
  */
 package org.apache.cxf.dosgi.systests2.multi;
 
-import javax.inject.Inject;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
 
-import org.apache.cxf.dosgi.systests2.common.AbstractTestExportService;
+import javax.inject.Inject;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.cxf.dosgi.samples.greeter.GreeterData;
+import org.apache.cxf.dosgi.samples.greeter.GreeterException;
+import org.apache.cxf.dosgi.samples.greeter.GreeterService;
+import org.apache.cxf.dosgi.samples.greeter.GreetingPhrase;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.BundleContext;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
 
 import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
@@ -34,7 +49,7 @@ import static org.ops4j.pax.exam.CoreOpt
 
 
 @RunWith(JUnit4TestRunner.class)
-public class TestExportService extends AbstractTestExportService {
+public class TestExportService extends AbstractDosgiTest {
     @Inject
     BundleContext bundleContext;
 
@@ -58,7 +73,71 @@ public class TestExportService extends A
     
     @Test
     public void testAccessEndpoint() throws Exception {
-        // call into base test. Inheriting the test doesn't properly report failures.
-        baseTestAccessEndpoint();
+        waitPort(9090);
+
+        checkWsdl(new URL("http://localhost:9090/greeter?wsdl"));
+        
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(ClientProxyFactoryBean.class.getClassLoader());        
+        try {
+            checkServiceCall("http://localhost:9090/greeter");
+        } finally {
+            Thread.currentThread().setContextClassLoader(cl);            
+        } 
+    }
+
+	private void checkServiceCall(String serviceUri) {
+		GreeterService client = createGreeterServiceProxy(serviceUri);
+
+		Map<GreetingPhrase, String> greetings = client.greetMe("Fred");
+		Assert.assertEquals("Fred", greetings.get(new GreetingPhrase("Hello")));
+		System.out.println("Invocation result: " + greetings);
+
+		try {
+		    GreeterData gd = new GreeterDataImpl("Stranger", 11, true);
+		    client.greetMe(gd);
+		    Assert.fail("GreeterException has to be thrown");
+		} catch (GreeterException ex) {
+		    Assert.assertEquals("Wrong exception message", 
+		                 "GreeterService can not greet Stranger", 
+		                 ex.toString());
+		}
+	}
+
+	private void checkWsdl(URL wsdlURL) throws ParserConfigurationException,
+			SAXException, IOException {
+		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        dbf.setValidating(false);
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        Document doc = db.parse(wsdlURL.openStream());
+        Element el = doc.getDocumentElement();
+        Assert.assertEquals("definitions", el.getLocalName());
+        Assert.assertEquals("http://schemas.xmlsoap.org/wsdl/", el.getNamespaceURI());
+        Assert.assertEquals("GreeterService", el.getAttribute("name"));
+	}
+
+    class GreeterDataImpl implements GreeterData {
+        private String name;
+        private int age;
+        private boolean exception;
+
+        GreeterDataImpl(String n, int a, boolean ex) {
+            name = n;
+            age = a;
+            exception = ex;
+        }
+        
+        public String getName() {
+            return name;
+        }
+
+        public int getAge() {
+            return age;
+        }
+
+        public boolean isException() {
+            return exception;
+        }                
     }
 }

Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java?rev=1482581&r1=1482580&r2=1482581&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java (original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java Tue May 14 20:51:29 2013
@@ -19,23 +19,43 @@
 package org.apache.cxf.dosgi.systests2.multi;
 
 
+import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.io.InputStream;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
 import javax.inject.Inject;
 
-import org.apache.cxf.dosgi.systests2.common.AbstractTestImportService;
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.dosgi.samples.greeter.GreeterData;
+import org.apache.cxf.dosgi.samples.greeter.GreeterException;
+import org.apache.cxf.dosgi.samples.greeter.GreeterService;
+import org.apache.cxf.dosgi.samples.greeter.GreetingPhrase;
+import org.apache.cxf.dosgi.systests2.common.test1.GreeterDataImpl;
+import org.apache.cxf.dosgi.systests2.common.test1.MyActivator;
+import org.apache.cxf.dosgi.systests2.common.test1.MyServiceTracker;
+import org.apache.cxf.dosgi.systests2.common.test1.StartServiceTracker;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
 import org.osgi.framework.BundleContext;
-
-import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.provision;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 
 @RunWith(JUnit4TestRunner.class)
-public class TestImportService extends AbstractTestImportService {
+public class TestImportService extends AbstractDosgiTest {
     @Inject
     BundleContext bundleContext;
 
@@ -50,7 +70,7 @@ public class TestImportService extends A
                     .artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"),
                 mavenBundle().groupId("org.apache.cxf.dosgi.systests")
                     .artifactId("cxf-dosgi-ri-systests2-common").versionAsInProject(),
-                provision(getTestClientBundle()),
+                provision(createServiceConsumerBundle()),
                 // increase for debugging
                 systemProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout").value(
                         System.getProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout", "20")), 
@@ -58,15 +78,74 @@ public class TestImportService extends A
         };
     }
     
-    protected BundleContext getBundleContext() {
-        return bundleContext;
+    protected static InputStream createServiceConsumerBundle() {
+        return TinyBundles.newBundle()
+            .add(MyActivator.class)
+            .add(MyServiceTracker.class)
+            .add(StartServiceTracker.class)
+            .add(GreeterDataImpl.class)
+            .add("OSGI-INF/remote-service/remote-services.xml", TestImportService.class.getResource("/rs-test1.xml"))
+            .set(Constants.BUNDLE_SYMBOLICNAME, "testClientBundle")
+            .set(Constants.EXPORT_PACKAGE, "org.apache.cxf.dosgi.systests2.common.test1")
+            .set(Constants.BUNDLE_ACTIVATOR, MyActivator.class.getName())
+            .build(TinyBundles.withBnd());        
     }
-
+    
     @Test
     public void testClientConsumer() throws Exception {
-//        for( Bundle b : bundleContext.getBundles() ) {
-//            System.out.println( "*** Bundle " + b.getBundleId() + " : " + b.getSymbolicName() + "/" + b.getState());
-//        }
-        baseTestClientConsumer();
-    }    
+        // This test tests the consumer side of Distributed OSGi. It works as follows:
+        // 1. It creates a little test bundle on the fly and starts that in the framework 
+        //    (this happens in the configure() method above). The test bundle waits until its 
+        //    instructed to start doing stuff. It's give this instruction via a service that is 
+        //    registered by this test (the service is of type java.lang.Object and has testName=test1).
+        // 2. The test manually creates a CXF server of the appropriate type (using ServerFactoryBean)
+        // 3. It signals the client bundle by registering a service to start doing its work.
+        //    This registers a ServiceTracker in the client bundle for the remote service that is created 
+        //    by the test in step 2. The client bundle knows about the address through the 
+        //    remote-services.xml file.
+        // 4. The client bundle will invoke the remote service and record the results in a service that it
+        //    registers in the Service Registry.
+        // 5. The test waits for this service to appear and then checks the results which are available as
+        //    a service property.
+        
+        // Set up a Server in the test
+        ServerFactoryBean factory = new ServerFactoryBean();
+        factory.setServiceClass(GreeterService.class);
+        factory.setAddress("http://localhost:9191/grrr");
+        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
+        factory.setServiceBean(new TestGreeter());
+        
+        Server server = null;
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
+            server = factory.create();
+            
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            props.put("testName", "test1");
+            bundleContext.registerService(Object.class.getName(), new Object(), props);
+    
+            // Wait for the service tracker in the test bundle to register a service with the test result
+            ServiceReference ref = waitService(bundleContext, String.class, "(testResult=test1)", 20);
+            Assert.assertEquals("HiOSGi;exception", ref.getProperty("result"));
+        } finally {
+            if (server != null) {
+                server.stop();
+            } 
+            Thread.currentThread().setContextClassLoader(cl);
+        }
+    }
+    
+    public static class TestGreeter implements GreeterService {
+        public Map<GreetingPhrase, String> greetMe(String name) {
+            Map<GreetingPhrase, String> m = new HashMap<GreetingPhrase, String>();
+            GreetingPhrase gp = new GreetingPhrase("Hi");
+            m.put(gp, name);
+            return m;
+        }
+
+        public GreetingPhrase[] greetMe(GreeterData gd) throws GreeterException {
+            throw new GreeterException("TestGreeter");
+        }      
+    }
 }