You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/11/12 09:34:22 UTC

svn commit: r1408185 - in /camel/trunk/components/camel-cxf/src/test: java/org/apache/camel/component/cxf/ java/org/apache/camel/component/cxf/jaxrs/ resources/org/apache/camel/component/cxf/jaxrs/

Author: davsclaus
Date: Mon Nov 12 08:34:21 2012
New Revision: 1408185

URL: http://svn.apache.org/viewvc?rev=1408185&view=rev
Log:
Fixed test and polished

Added:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java
      - copied, changed from r1408176, camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest.java
Modified:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerResponseTest.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest.java
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerResponseTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerResponseTest.java?rev=1408185&r1=1408184&r2=1408185&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerResponseTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerResponseTest.java Mon Nov 12 08:34:21 2012
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.cxf;
 
 import java.util.HashMap;
@@ -35,7 +34,6 @@ import org.apache.cxf.frontend.ClientFac
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.junit.Test;
 
-
 public class CxfConsumerResponseTest extends CamelTestSupport {
     
     private static final String ECHO_OPERATION = "echo";
@@ -44,9 +42,9 @@ public class CxfConsumerResponseTest ext
     private static final String TEST_MESSAGE = "Hello World!";
     private static int pingCounter;
 
-    
     protected final String simpleEndpointAddress = "http://localhost:"
         + CXFTestSupport.getPort1() + "/" + getClass().getSimpleName() + "/test";
+
     protected final String simpleEndpointURI = "cxf://" + simpleEndpointAddress
         + "?serviceClass=org.apache.camel.component.cxf.HelloService"
         + "&publishedEndpointUrl=http://www.simple.com/services/test";
@@ -56,48 +54,50 @@ public class CxfConsumerResponseTest ext
     public boolean isCreateCamelContextPerClass() {
         return true;
     }
+
     // START SNIPPET: example
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from(simpleEndpointURI).inOnly("log:test").choice().when(header(CxfConstants.OPERATION_NAME).isEqualTo(ECHO_OPERATION)).process(new Processor() {
-                    public void process(final Exchange exchange) {
-                        assertEquals(DataFormat.POJO, exchange.getProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.class));
-                        Message in = exchange.getIn();
-                        // check the remote IP from the cxfMessage
-                        org.apache.cxf.message.Message cxfMessage = in.getHeader(CxfConstants.CAMEL_CXF_MESSAGE, org.apache.cxf.message.Message.class);
-                        assertNotNull("Should get the cxfMessage instance from message header", cxfMessage);
-                        ServletRequest request = (ServletRequest)cxfMessage.get("HTTP.REQUEST");
-                        assertNotNull("Should get the ServletRequest", request);
-                        assertNotNull("Should get the RemoteAddress" + request.getRemoteAddr());
-                        // Get the parameter list
-                        List<?> parameter = in.getBody(List.class);
-                        // Get the operation name
-                        String operation = (String)in.getHeader(CxfConstants.OPERATION_NAME);
-                        Object result = operation + " " + (String)parameter.get(0);
-                        // Put the result back
-                        exchange.getIn().setBody(result);
-                        // set up the response context which force start document
-                        Map<String, Object> map = new HashMap<String, Object>();
-                        map.put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);
-                        exchange.getIn().setHeader(Client.RESPONSE_CONTEXT, map);
-                    }
-                })
-                .when(header(CxfConstants.OPERATION_NAME).isEqualTo(ECHO_BOOLEAN_OPERATION)).process(new Processor() {
-                    public void process(final Exchange exchange) {
-                        Message in = exchange.getIn();
-                        // Get the parameter list
-                        List<?> parameter = in.getBody(List.class);
-                        // Put the result back
-                        exchange.getOut().setBody(parameter.get(0));
-                    }
-                })
-                .when(header(CxfConstants.OPERATION_NAME).isEqualTo(PING_OPERATION)).process(new Processor() {
-                    public void process(final Exchange exchange) {
-                        pingCounter++;
-                    }
-                    
-                });
+                from(simpleEndpointURI).inOnly("log:test")
+                    .choice().when(header(CxfConstants.OPERATION_NAME).isEqualTo(ECHO_OPERATION)).process(new Processor() {
+                        public void process(final Exchange exchange) {
+                            assertEquals(DataFormat.POJO, exchange.getProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.class));
+                            Message in = exchange.getIn();
+                            // check the remote IP from the cxfMessage
+                            org.apache.cxf.message.Message cxfMessage = in.getHeader(CxfConstants.CAMEL_CXF_MESSAGE, org.apache.cxf.message.Message.class);
+                            assertNotNull("Should get the cxfMessage instance from message header", cxfMessage);
+                            ServletRequest request = (ServletRequest)cxfMessage.get("HTTP.REQUEST");
+                            assertNotNull("Should get the ServletRequest", request);
+                            assertNotNull("Should get the RemoteAddress" + request.getRemoteAddr());
+                            // Get the parameter list
+                            List<?> parameter = in.getBody(List.class);
+                            // Get the operation name
+                            String operation = (String)in.getHeader(CxfConstants.OPERATION_NAME);
+                            Object result = operation + " " + (String)parameter.get(0);
+                            // Put the result back
+                            exchange.getIn().setBody(result);
+                            // set up the response context which force start document
+                            Map<String, Object> map = new HashMap<String, Object>();
+                            map.put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);
+                            exchange.getIn().setHeader(Client.RESPONSE_CONTEXT, map);
+                        }
+                    })
+                    .when(header(CxfConstants.OPERATION_NAME).isEqualTo(ECHO_BOOLEAN_OPERATION)).process(new Processor() {
+                        public void process(final Exchange exchange) {
+                            Message in = exchange.getIn();
+                            // Get the parameter list
+                            List<?> parameter = in.getBody(List.class);
+                            // Put the result back
+                            exchange.getOut().setBody(parameter.get(0));
+                        }
+                    })
+                    .when(header(CxfConstants.OPERATION_NAME).isEqualTo(PING_OPERATION)).process(new Processor() {
+                        public void process(final Exchange exchange) {
+                            pingCounter++;
+                        }
+
+                    });
 
             }
         };
@@ -113,6 +113,7 @@ public class CxfConsumerResponseTest ext
         clientBean.setBus(BusFactory.getDefaultBus());
 
         HelloService client = (HelloService) proxyFactory.create();
+        assertNotNull(client);
 
         String result = client.echo(TEST_MESSAGE);
         assertEquals("We should get the echo string result from router", result, "echo " + TEST_MESSAGE);

Copied: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java (from r1408176, camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java?p2=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java&p1=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest.java&r1=1408176&r2=1408185&rev=1408185&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java Mon Nov 12 08:34:21 2012
@@ -36,24 +36,15 @@ import org.springframework.context.suppo
 /**
  *
  */
-public class CxfRsProducerClientFactoryCacheTest extends Assert {
-    private static int port1 = CXFTestSupport.getPort1(); 
-    private static int port2 = CXFTestSupport.getPort2();
+public class CxfRsProducerClientFactoryCache2Test extends Assert {
+    private static int port2 = CXFTestSupport.getPort("mySecurePort");
 
-    private CamelContext context1;
     private CamelContext context2;
-    private ProducerTemplate template1;
     private ProducerTemplate template2;
 
     @Before
     public void setUp() throws Exception {
-        AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest1.xml");
-        context1 = SpringCamelContext.springCamelContext(ac, false);
-        context1.start();
-        template1 = context1.createProducerTemplate();
-        template1.start();
-
-        ac = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml");
+        AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml");
         context2 = SpringCamelContext.springCamelContext(ac, false);
         context2.start();
 
@@ -63,11 +54,6 @@ public class CxfRsProducerClientFactoryC
     
     @After
     public void tearDown() throws Exception {
-        if (context1 != null) {
-            context1.stop();
-            template1.stop();
-        }
-
         if (context2 != null) {
             context2.stop();
             template2.stop();
@@ -76,11 +62,10 @@ public class CxfRsProducerClientFactoryC
     
     @Test
     public void testGetCostumerWithHttpCentralClientAPI() throws Exception {
-        doRunTest(template2);
-        doRunTest(template1);
+        doRunTest(template2, getPort2());
     }
 
-    private void doRunTest(ProducerTemplate template) {
+    private void doRunTest(ProducerTemplate template, final int clientPort) {
         Exchange exchange = template.send("direct://http", new Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.setPattern(ExchangePattern.InOut);
@@ -89,7 +74,7 @@ public class CxfRsProducerClientFactoryC
                 inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
                 inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");                
                 inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
-                inMessage.setHeader("port", getPort2());
+                inMessage.setHeader("clientPort", clientPort);
                 inMessage.setBody(null);                
             }
         });
@@ -103,10 +88,6 @@ public class CxfRsProducerClientFactoryC
         assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
     }
 
-    public int getPort1() {
-        return port1;
-    }
-
     public int getPort2() {
         return port2;
     }

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest.java?rev=1408185&r1=1408184&r2=1408185&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest.java Mon Nov 12 08:34:21 2012
@@ -38,12 +38,9 @@ import org.springframework.context.suppo
  */
 public class CxfRsProducerClientFactoryCacheTest extends Assert {
     private static int port1 = CXFTestSupport.getPort1(); 
-    private static int port2 = CXFTestSupport.getPort2();
 
     private CamelContext context1;
-    private CamelContext context2;
     private ProducerTemplate template1;
-    private ProducerTemplate template2;
 
     @Before
     public void setUp() throws Exception {
@@ -52,13 +49,6 @@ public class CxfRsProducerClientFactoryC
         context1.start();
         template1 = context1.createProducerTemplate();
         template1.start();
-
-        ac = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml");
-        context2 = SpringCamelContext.springCamelContext(ac, false);
-        context2.start();
-
-        template2 = context2.createProducerTemplate();
-        template2.start();
     }
     
     @After
@@ -67,20 +57,14 @@ public class CxfRsProducerClientFactoryC
             context1.stop();
             template1.stop();
         }
-
-        if (context2 != null) {
-            context2.stop();
-            template2.stop();
-        }
     }
     
     @Test
     public void testGetCostumerWithHttpCentralClientAPI() throws Exception {
-        doRunTest(template2);
-        doRunTest(template1);
+        doRunTest(template1, getPort1());
     }
 
-    private void doRunTest(ProducerTemplate template) {
+    private void doRunTest(ProducerTemplate template, final int clientPort) {
         Exchange exchange = template.send("direct://http", new Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.setPattern(ExchangePattern.InOut);
@@ -89,7 +73,7 @@ public class CxfRsProducerClientFactoryC
                 inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
                 inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");                
                 inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
-                inMessage.setHeader("port", getPort2());
+                inMessage.setHeader("clientPort", clientPort);
                 inMessage.setBody(null);                
             }
         });
@@ -107,7 +91,4 @@ public class CxfRsProducerClientFactoryC
         return port1;
     }
 
-    public int getPort2() {
-        return port2;
-    }
 }

Modified: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml?rev=1408185&r1=1408184&r2=1408185&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml (original)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml Mon Nov 12 08:34:21 2012
@@ -28,7 +28,7 @@
 	http://cxf.apache.org/schemas/configuration/http-conf.xsd ">
 	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
 
-	<jaxrs:server id="restService" address="https://localhost:${CXFTestSupport.port2}/CxfRsProducerTest/"
+	<jaxrs:server id="restService" address="https://localhost:${mySecurePort}/CxfRsProducerTest/"
 		staticSubresourceResolution="true">
 		<jaxrs:serviceBeans>
 			<ref bean="customerService"/>
@@ -41,13 +41,13 @@
 		<route>
 			<from uri="direct://http"/>
 			<recipientList>
-				<simple>cxfrs://https://localhost:${header.port}/CxfRsProducerTest/</simple>
+				<simple>cxfrs://https://localhost:${header.clientPort}/CxfRsProducerTest/</simple>
 			</recipientList>
 		</route>
 	</camelContext>
 
 	<httpj:engine-factory id="tls-config">
-		<httpj:engine port="${CXFTestSupport.port2}">
+		<httpj:engine port="${mySecurePort}">
 			<httpj:tlsServerParameters>
 				<sec:keyManagers keyPassword="password">
 					<sec:keyStore type="JKS" password="password"  file="src/test/resources/org/apache/camel/component/cxf/jaxrs/Bethal.jks"/>