cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r903283 - in /cxf/dosgi/trunk/systests2: ./ src/test/java/org/apache/cxf/dosgi/systests2/basic/ src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/ src/test/java/org/apache/cxf/dosgi/systests2/common/ src/test/resources/
Date Tue, 26 Jan 2010 15:46:46 GMT
Author: davidb
Date: Tue Jan 26 15:46:45 2010
New Revision: 903283

URL: http://svn.apache.org/viewvc?rev=903283&view=rev
Log:
Additional system test. This one is for the client.

Added:
    cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/
    cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/Streams.java
      - copied, changed from r902847, cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/common/Streams.java
    cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestExportService.java
      - copied, changed from r902847, cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/common/TestExportService.java
    cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestImportService.java
  (with props)
    cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/
    cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyActivator.java
  (with props)
    cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyServiceTracker.java
  (with props)
    cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/StartServiceTracker.java
  (with props)
    cxf/dosgi/trunk/systests2/src/test/resources/
    cxf/dosgi/trunk/systests2/src/test/resources/rs-test1.xml   (with props)
Removed:
    cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/common/
Modified:
    cxf/dosgi/trunk/systests2/pom.xml

Modified: cxf/dosgi/trunk/systests2/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/pom.xml?rev=903283&r1=903282&r2=903283&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/pom.xml (original)
+++ cxf/dosgi/trunk/systests2/pom.xml Tue Jan 26 15:46:45 2010
@@ -37,6 +37,11 @@
             <version>1.2.0</version>
         </dependency>
         <dependency>
+            <groupId>org.ops4j.pax.swissbox</groupId>
+            <artifactId>pax-swissbox-tinybundles</artifactId>
+            <version>1.2.0</version>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <version>4.1.0</version>
@@ -53,6 +58,7 @@
             <artifactId>cxf-dosgi-ri-singlebundle-distribution</artifactId>
             <version>${pom.version}</version>
             <scope>test</scope>
+            <!-- can we avoid transitive dependencies here? -->
         </dependency>
         <dependency>
             <groupId>org.apache.cxf.dosgi.samples</groupId>
@@ -80,6 +86,10 @@
         </dependency> 
     </dependencies>
 
+    <!-- <modules>
+        <module>systest-greeter-client</module>
+    </modules> -->
+
     <build>
         <plugins>
             <!-- use pax exam maven plugin -->

Copied: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/Streams.java
(from r902847, cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/common/Streams.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/Streams.java?p2=cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/Streams.java&p1=cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/common/Streams.java&r1=902847&r2=903283&rev=903283&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/common/Streams.java
(original)
+++ cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/Streams.java
Tue Jan 26 15:46:45 2010
@@ -1,4 +1,4 @@
-package org.apache.cxf.dosgi.systests2.common;
+package org.apache.cxf.dosgi.systests2.basic;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;

Copied: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestExportService.java
(from r902847, cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/common/TestExportService.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestExportService.java?p2=cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestExportService.java&p1=cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/common/TestExportService.java&r1=902847&r2=903283&rev=903283&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/common/TestExportService.java
(original)
+++ cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestExportService.java
Tue Jan 26 15:46:45 2010
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations 
  * under the License. 
  */
-package org.apache.cxf.dosgi.systests2.common;
+package org.apache.cxf.dosgi.systests2.basic;
 
 import java.io.IOException;
 import java.net.Socket;
@@ -40,18 +40,12 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 
 @RunWith( JUnit4TestRunner.class )
 public class TestExportService {
-    @Inject
-    BundleContext bundleContext = null;
-
     @Configuration
     public static Option[] configure() {
         return CoreOptions.options(
@@ -70,11 +64,6 @@
     
     @Test
     public void testCreateEndpoint() throws Exception {
-        for( Bundle b : bundleContext.getBundles() )
-        {
-            System.out.println( "Bundle " + b.getBundleId() + " : " + b.getSymbolicName()
);
-        }        
-
         waitPort(9090);
         URL wsdlURL = new URL("http://localhost:9090/greeter?wsdl");
         
@@ -138,7 +127,7 @@
     }
 
     private void waitPort(int port) throws Exception {
-        for (int i = 0; i < 10; i++) {
+        for (int i = 0; i < 20; i++) {
             Socket s = null;
             try {
                 s = new Socket((String) null, port);

Added: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestImportService.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestImportService.java?rev=903283&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestImportService.java
(added)
+++ cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestImportService.java
Tue Jan 26 15:46:45 2010
@@ -0,0 +1,111 @@
+package org.apache.cxf.dosgi.systests2.basic;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+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.basic.test1.MyActivator;
+import org.apache.cxf.dosgi.systests2.basic.test1.MyServiceTracker;
+import org.apache.cxf.dosgi.systests2.basic.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.CoreOptions;
+import org.ops4j.pax.exam.Inject;
+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.framework.ServiceReference;
+
+@RunWith( JUnit4TestRunner.class )
+public class TestImportService {
+    @Inject
+    BundleContext bundleContext = null;
+
+    @Configuration
+    public static Option[] configure() {
+        InputStream testClientBundle = TinyBundles.newBundle()
+            .add(MyActivator.class)
+            .add(MyServiceTracker.class)
+            .add(StartServiceTracker.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());
+        
+        return CoreOptions.options(
+                CoreOptions.mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").versionAsInProject(),
+                CoreOptions.mavenBundle().groupId("org.apache.cxf.dosgi").artifactId("cxf-dosgi-ri-singlebundle-distribution").versionAsInProject(),
+                CoreOptions.mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject(),
+                CoreOptions.provision(testClientBundle)
+        );
+    }
+
+    @Test
+    public void testClientConsumer() throws Exception {
+        // 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();
+        } finally {
+            Thread.currentThread().setContextClassLoader(cl);
+        }
+        
+//        JOptionPane.showMessageDialog(null, factory.getAddress());
+        
+        Hashtable<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(String.class.getName(), "(testResult=test1)");
+        Assert.assertEquals("HiOSGi", ref.getProperty("result"));
+        server.stop(); // in finally !!!
+    }
+    
+    private ServiceReference waitService(String cls, String filter) throws Exception {  
     
+        ServiceReference[] refs = null;
+        for (int i=0; i < 20; i++) {
+            refs = bundleContext.getServiceReferences(cls, 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);
+    }
+    
+    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");
+        }      
+    }
+}

Propchange: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestImportService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/TestImportService.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyActivator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyActivator.java?rev=903283&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyActivator.java
(added)
+++ cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyActivator.java
Tue Jan 26 15:46:45 2010
@@ -0,0 +1,25 @@
+package org.apache.cxf.dosgi.systests2.basic.test1;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class MyActivator implements BundleActivator {    
+    private ServiceTracker startTracker, tracker;
+
+    public void start(final BundleContext bc) throws Exception {
+        Filter filter = bc.createFilter("(&(objectClass=java.lang.Object)(testName=test1))");
+        tracker = new MyServiceTracker(bc);
+        
+        // The start tracker waits until a service from the test class is set before the

+        // 'MyServiceTracker' is activated.
+        startTracker = new StartServiceTracker(bc, filter, tracker);
+        startTracker.open();
+    }
+    
+    public void stop(BundleContext bc) throws Exception {
+        startTracker.close();
+        tracker.close();
+    }
+}

Propchange: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyActivator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyServiceTracker.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyServiceTracker.java?rev=903283&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyServiceTracker.java
(added)
+++ cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyServiceTracker.java
Tue Jan 26 15:46:45 2010
@@ -0,0 +1,44 @@
+package org.apache.cxf.dosgi.systests2.basic.test1;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.cxf.dosgi.samples.greeter.GreeterService;
+import org.apache.cxf.dosgi.samples.greeter.GreetingPhrase;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class MyServiceTracker extends ServiceTracker {
+    private static StringBuffer invocationResult = new StringBuffer();
+
+    public MyServiceTracker(BundleContext context) {
+        super(context, GreeterService.class.getName(), null);
+    }
+
+    public Object addingService(ServiceReference reference) {
+        Object svc = super.addingService(reference);
+        if (svc instanceof GreeterService) {
+            invokeGreeter((GreeterService) svc);
+        }
+        return svc;
+    }
+    
+    public static String getResult() {
+        return invocationResult.toString();
+    }
+
+    private void invokeGreeter(GreeterService svc) {
+        Map<GreetingPhrase, String> result = svc.greetMe("OSGi");
+        for (Map.Entry<GreetingPhrase, String> e : result.entrySet()) {
+            GreetingPhrase key = e.getKey();
+            invocationResult.append(key.getPhrase());
+            invocationResult.append(e.getValue());
+        }
+        
+        Hashtable<String, Object> props = new Hashtable<String, Object>();
+        props.put("result", invocationResult.toString());
+        props.put("testResult", "test1");
+        context.registerService(String.class.getName(), "test1", props);
+    }    
+}
\ No newline at end of file

Propchange: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyServiceTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/MyServiceTracker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/StartServiceTracker.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/StartServiceTracker.java?rev=903283&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/StartServiceTracker.java
(added)
+++ cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/StartServiceTracker.java
Tue Jan 26 15:46:45 2010
@@ -0,0 +1,21 @@
+package org.apache.cxf.dosgi.systests2.basic.test1;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class StartServiceTracker extends ServiceTracker {
+    private ServiceTracker tracker;
+
+    public StartServiceTracker(BundleContext context, Filter filter, ServiceTracker tracker)
{
+        super(context, filter, null);
+        this.tracker = tracker;
+    }
+
+    @Override
+    public Object addingService(ServiceReference reference) {
+        tracker.open();
+        return super.addingService(reference);
+    }
+}

Propchange: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/StartServiceTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/systests2/src/test/java/org/apache/cxf/dosgi/systests2/basic/test1/StartServiceTracker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/systests2/src/test/resources/rs-test1.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/src/test/resources/rs-test1.xml?rev=903283&view=auto
==============================================================================
--- cxf/dosgi/trunk/systests2/src/test/resources/rs-test1.xml (added)
+++ cxf/dosgi/trunk/systests2/src/test/resources/rs-test1.xml Tue Jan 26 15:46:45 2010
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <!--
+    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.
+  -->
+<rsa:endpoint-descriptions xmlns:rsa="http://www.osgi.org/xmlns/rsa/v1.0.0"
+  xmlns:other="http://www.acme.org/xmlns/other/v1.0.0">
+  <endpoint-description>
+    <property name="objectClass">
+      <array>
+        <value>org.apache.cxf.dosgi.samples.greeter.GreeterService</value>
+      </array>
+    </property>
+    <property name="endpoint.id">http://localhost:9191/grrr</property>
+    <property name="service.imported.configs">org.apache.cxf.ws</property>
+  </endpoint-description>
+</rsa:endpoint-descriptions>
+

Propchange: cxf/dosgi/trunk/systests2/src/test/resources/rs-test1.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/systests2/src/test/resources/rs-test1.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/dosgi/trunk/systests2/src/test/resources/rs-test1.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message