You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2008/11/12 07:42:33 UTC

svn commit: r713273 - /activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/

Author: ningjiang
Date: Tue Nov 11 22:42:32 2008
New Revision: 713273

URL: http://svn.apache.org/viewvc?rev=713273&view=rev
Log:
Clean up the CXF Greeter unit tests

Added:
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTestSupport.java   (contents, props changed)
      - copied, changed from r713242, activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSimpleRouterTest.java   (with props)
Removed:
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java
Modified:
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFGreeterRouterTest.java
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterPayLoadRouterTest.java
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRawMessageRouterTest.java
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringRouterTest.java

Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFGreeterRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFGreeterRouterTest.java?rev=713273&r1=713272&r2=713273&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFGreeterRouterTest.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFGreeterRouterTest.java Tue Nov 11 22:42:32 2008
@@ -22,25 +22,50 @@
 import javax.xml.ws.Endpoint;
 import javax.xml.ws.Service;
 
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
 import org.apache.camel.CamelContext;
+import org.apache.camel.spring.SpringCamelContext;
 import org.apache.camel.spring.processor.SpringTestHelper;
+import org.apache.cxf.jaxws.EndpointImpl;
 import org.apache.hello_world_soap_http.Greeter;
 import org.apache.hello_world_soap_http.GreeterImpl;
 import org.apache.hello_world_soap_http.NoSuchCodeLitFault;
 
-public class CXFGreeterRouterTest extends CxfSpringRouterTest {
+public class CXFGreeterRouterTest extends CxfRouterTestSupport {
+    protected AbstractXmlApplicationContext applicationContext;
+    
     private final QName serviceName = new QName("http://apache.org/hello_world_soap_http",
                                                 "SOAPService");
     private final QName routerPortName = new QName("http://apache.org/hello_world_soap_http",
                                                 "RouterPort");
+
+    @Override
+    protected void setUp() throws Exception {
+        applicationContext = createApplicationContext();
+        super.setUp();
+        assertNotNull("Should have created a valid spring context", applicationContext);
+
+
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (applicationContext != null) {
+            applicationContext.destroy();
+        }
+        super.tearDown();
+    }
     @Override
     protected void startService() {
         Object implementor = new GreeterImpl();
         String address = "http://localhost:9000/SoapContext/SoapPort";
-        Endpoint.publish(address, implementor);
+        EndpointImpl endpoint = (EndpointImpl)Endpoint.publish(address, implementor);
+        server = endpoint.getServer();
     }
 
-    @Override
+    
     public void testInvokingServiceFromCXFClient() throws Exception {
         Service service = Service.create(serviceName);
         service.addPort(routerPortName, "http://schemas.xmlsoap.org/soap/",
@@ -67,20 +92,17 @@
         }
 
     }
-
+    
     @Override
-    public void testOnwayInvocation() throws Exception {
-        Service service = Service.create(serviceName);
-        service.addPort(routerPortName, "http://schemas.xmlsoap.org/soap/",
-                        "http://localhost:9003/CamelContext/RouterPort");
-        Greeter greeter = service.getPort(routerPortName, Greeter.class);
-        greeter.greetMeOneWay("call greetMe OneWay !");
+    protected CamelContext createCamelContext() throws Exception {
+        return SpringCamelContext.springCamelContext(applicationContext);
     }
 
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        return SpringTestHelper.createSpringCamelContext(this, "org/apache/camel/component/cxf/GreeterEndpointsRouterContext.xml");
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/GreeterEndpointsRouterContext.xml");
     }
+   
 }
 
 

Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java?rev=713273&r1=713272&r2=713273&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java Tue Nov 11 22:42:32 2008
@@ -34,12 +34,7 @@
             }
         };
     }
-
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        return SpringCamelContext.springCamelContext(applicationContext);
-    }
-
+    
     @Override
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/GreeterEndpointBeans.xml");

Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterPayLoadRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterPayLoadRouterTest.java?rev=713273&r1=713272&r2=713273&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterPayLoadRouterTest.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterPayLoadRouterTest.java Tue Nov 11 22:42:32 2008
@@ -35,11 +35,7 @@
         };
     }
 
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        return SpringCamelContext.springCamelContext(applicationContext);
-    }
-
+    
     @Override
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/GreeterEndpointBeans.xml");

Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java?rev=713273&r1=713272&r2=713273&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java Tue Nov 11 22:42:32 2008
@@ -18,7 +18,7 @@
 
 import org.apache.camel.builder.RouteBuilder;
 
-public class CxfPayLoadMessageRouterTest extends CxfRouterTest {
+public class CxfPayLoadMessageRouterTest extends CxfSimpleRouterTest {
     private String routerEndpointURI = "cxf://" + ROUTER_ADDRESS + "?" + SERVICE_CLASS + "&dataFormat=PAYLOAD";
     private String serviceEndpointURI = "cxf://" + SERVICE_ADDRESS + "?" + SERVICE_CLASS + "&dataFormat=PAYLOAD";
     protected RouteBuilder createRouteBuilder() {

Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRawMessageRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRawMessageRouterTest.java?rev=713273&r1=713272&r2=713273&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRawMessageRouterTest.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRawMessageRouterTest.java Tue Nov 11 22:42:32 2008
@@ -18,7 +18,7 @@
 
 import org.apache.camel.builder.RouteBuilder;
 
-public class CxfRawMessageRouterTest extends CxfRouterTest {
+public class CxfRawMessageRouterTest extends CxfSimpleRouterTest {
     private String routerEndpointURI = "cxf://" + ROUTER_ADDRESS + "?" + SERVICE_CLASS + "&dataFormat=MESSAGE";
     private String serviceEndpointURI = "cxf://" + SERVICE_ADDRESS + "?" + SERVICE_CLASS + "&dataFormat=MESSAGE";
     protected RouteBuilder createRouteBuilder() {

Copied: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTestSupport.java (from r713242, activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTestSupport.java?p2=activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTestSupport.java&p1=activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java&r1=713242&r2=713273&rev=713273&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTestSupport.java Tue Nov 11 22:42:32 2008
@@ -22,22 +22,17 @@
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.endpoint.ServerImpl;
 import org.apache.cxf.frontend.ClientFactoryBean;
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.frontend.ServerFactoryBean;
 
 
-public class CxfRouterTest extends ContextTestSupport {
-    protected static final String ROUTER_ADDRESS = "http://localhost:9000/router";
-    protected static final String SERVICE_ADDRESS = "http://localhost:9002/helloworld";
-    protected static final String SERVICE_CLASS = "serviceClass=org.apache.camel.component.cxf.HelloService";
+public abstract class CxfRouterTestSupport extends ContextTestSupport {    
 
-    private String routerEndpointURI = "cxf://" + ROUTER_ADDRESS + "?" + SERVICE_CLASS + "&dataFormat=POJO";
-    private String serviceEndpointURI = "cxf://" + SERVICE_ADDRESS + "?" + SERVICE_CLASS + "&dataFormat=POJO";
-
-    private ServerImpl server;
-    private Bus bus;
+    protected Server server;
+    protected Bus bus;
 
 
     @Override
@@ -49,18 +44,8 @@
         startService();
     }
 
-    protected void startService() {
-        //start a service
-        ServerFactoryBean svrBean = new ServerFactoryBean();
-
-        svrBean.setAddress(SERVICE_ADDRESS);
-        svrBean.setServiceClass(HelloService.class);
-        svrBean.setServiceBean(new HelloServiceImpl());
-        svrBean.setBus(bus);
-
-        server = (ServerImpl)svrBean.create();
-        server.start();
-    }
+    protected abstract void startService();
+       
 
     @Override
     protected void tearDown() throws Exception {
@@ -71,44 +56,5 @@
         BusFactory.setDefaultBus(null);
     }
 
-    protected RouteBuilder createRouteBuilder() {
-        return new RouteBuilder() {
-            public void configure() {
-                errorHandler(noErrorHandler());
-                from(routerEndpointURI).to("log:org.apache.camel?level=DEBUG").to(serviceEndpointURI);
-            }
-        };
-    }
-
-    protected CamelContext createCamelContext() throws Exception {
-        return new DefaultCamelContext();
-    }
-
-
-    public void testInvokingServiceFromCXFClient() throws Exception {
-        ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
-        ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
-        clientBean.setAddress(ROUTER_ADDRESS);
-        clientBean.setServiceClass(HelloService.class);
-        clientBean.setBus(bus);
-
-        HelloService client = (HelloService) proxyFactory.create();
-
-        String result = client.echo("hello world");
-        assertEquals("we should get the right answer from router", result, "echo hello world");
-
-    }
-
-    public void testOnwayInvocation() throws Exception {
-        ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
-        ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
-        clientBean.setAddress(ROUTER_ADDRESS);
-        clientBean.setServiceClass(HelloService.class);
-        clientBean.setBus(bus);
-        HelloService client = (HelloService) proxyFactory.create();
-        int count = client.getInvocationCount();
-        client.ping();
-        //oneway ping invoked, so invocationCount ++
-        assertEquals("The ping should be invocated", client.getInvocationCount(), ++count);
-    }
+    
 }

Propchange: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTestSupport.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSimpleRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSimpleRouterTest.java?rev=713273&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSimpleRouterTest.java (added)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSimpleRouterTest.java Tue Nov 11 22:42:32 2008
@@ -0,0 +1,90 @@
+/**
+ * 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.camel.component.cxf;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.cxf.endpoint.ServerImpl;
+import org.apache.cxf.frontend.ClientFactoryBean;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.frontend.ServerFactoryBean;
+
+public class CxfSimpleRouterTest extends CxfRouterTestSupport {    
+    protected static final String ROUTER_ADDRESS = "http://localhost:9000/router";
+    protected static final String SERVICE_ADDRESS = "http://localhost:9002/helloworld";
+    protected static final String SERVICE_CLASS = "serviceClass=org.apache.camel.component.cxf.HelloService";
+
+    private String routerEndpointURI = "cxf://" + ROUTER_ADDRESS + "?" + SERVICE_CLASS + "&dataFormat=POJO";
+    private String serviceEndpointURI = "cxf://" + SERVICE_ADDRESS + "?" + SERVICE_CLASS + "&dataFormat=POJO";
+    
+    protected void startService() {
+        //start a service
+        ServerFactoryBean svrBean = new ServerFactoryBean();
+    
+        svrBean.setAddress(SERVICE_ADDRESS);
+        svrBean.setServiceClass(HelloService.class);
+        svrBean.setServiceBean(new HelloServiceImpl());
+        svrBean.setBus(bus);
+    
+        server = svrBean.create();
+        server.start();
+    }
+    
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                errorHandler(noErrorHandler());
+                from(routerEndpointURI).to("log:org.apache.camel?level=DEBUG").to(serviceEndpointURI);
+            }
+        };
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        return new DefaultCamelContext();
+    }
+
+
+    public void testInvokingServiceFromCXFClient() throws Exception {
+        ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
+        ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
+        clientBean.setAddress(ROUTER_ADDRESS);
+        clientBean.setServiceClass(HelloService.class);
+        clientBean.setBus(bus);
+
+        HelloService client = (HelloService) proxyFactory.create();
+
+        String result = client.echo("hello world");
+        assertEquals("we should get the right answer from router", result, "echo hello world");
+
+    }
+
+    public void testOnwayInvocation() throws Exception {
+        ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
+        ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
+        clientBean.setAddress(ROUTER_ADDRESS);
+        clientBean.setServiceClass(HelloService.class);
+        clientBean.setBus(bus);
+        HelloService client = (HelloService) proxyFactory.create();
+        int count = client.getInvocationCount();
+        client.ping();
+        //oneway ping invoked, so invocationCount ++
+        assertEquals("The ping should be invocated", client.getInvocationCount(), ++count);
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSimpleRouterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSimpleRouterTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringRouterTest.java?rev=713273&r1=713272&r2=713273&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringRouterTest.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringRouterTest.java Tue Nov 11 22:42:32 2008
@@ -23,7 +23,7 @@
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-public class CxfSpringRouterTest extends CxfRouterTest {
+public class CxfSpringRouterTest extends CxfSimpleRouterTest {
     protected AbstractXmlApplicationContext applicationContext;
 
     @Override