svn commit: r1057151 - in /camel/trunk/tests/camel-itest/src/test: java/org/apache/camel/itest/greeter/CxfToJmsInOutTest.java resources/org/apache/camel/itest/greeter/CxfToJmsInOutTest-context.xml

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1057151 - in /camel/trunk/tests/camel-itest/src/test: java/org/apache/camel/itest/greeter/CxfToJmsInOutTest.java resources/org/apache/camel/itest/greeter/CxfToJmsInOutTest-context.xml

davsclaus-2
Author: davsclaus
Date: Mon Jan 10 11:10:49 2011
New Revision: 1057151

URL: http://svn.apache.org/viewvc?rev=1057151&view=rev
Log:
Added test based on user forum issue

Added:
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CxfToJmsInOutTest.java
      - copied, changed from r1057139, camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelGreeterTest.java
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CxfToJmsInOutTest-context.xml
      - copied, changed from r1057139, camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelGreeterTest-context.xml

Copied: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CxfToJmsInOutTest.java (from r1057139, camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelGreeterTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CxfToJmsInOutTest.java?p2=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CxfToJmsInOutTest.java&p1=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelGreeterTest.java&r1=1057139&r2=1057151&rev=1057151&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelGreeterTest.java (original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CxfToJmsInOutTest.java Mon Jan 10 11:10:49 2011
@@ -16,19 +16,10 @@
  */
 package org.apache.camel.itest.greeter;
 
-import java.util.List;
-import javax.xml.ws.Endpoint;
-
-import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointInject;
-import org.apache.camel.Exchange;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.cxf.CxfConstants;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
@@ -36,56 +27,33 @@ import org.springframework.test.context.
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 @ContextConfiguration
-public class CamelGreeterTest extends AbstractJUnit4SpringContextTests {
-    private static final transient Log LOG = LogFactory.getLog(CamelGreeterTest.class);
-    
-    private static Endpoint endpoint;
-    @Autowired
-    protected CamelContext camelContext;
+public class CxfToJmsInOutTest extends AbstractJUnit4SpringContextTests {
 
-    @EndpointInject(uri = "mock:resultEndpoint")
-    protected MockEndpoint resultEndpoint;
+    @Autowired
+    protected ProducerTemplate template;
 
-    @BeforeClass
-    public static void startServer() throws Exception {
-        // Start the Greeter Server
-        Object implementor = new GreeterImpl();
-        String address = "http://localhost:9000/SoapContext/SoapPort";
-        endpoint = Endpoint.publish(address, implementor);
-        LOG.info("The WS endpoint is published! ");
-    }
+    @EndpointInject(uri = "mock:cxf.input")
+    protected MockEndpoint inputEndpoint;
 
-    @AfterClass
-    public static void stopServer() throws Exception {
-        // Shutdown the Greeter Server
-        if (endpoint != null) {
-            endpoint.stop();
-            endpoint = null;
-        }
-    }
+    @EndpointInject(uri = "mock:jms.output")
+    protected MockEndpoint outputEndpoint;
 
     @Test
-    public void testMocksAreValid() throws Exception {
-        assertNotNull(camelContext);
-        assertNotNull(resultEndpoint);
-
-        ProducerTemplate template = camelContext.createProducerTemplate();
-        template.sendBodyAndHeader("jms:requestQueue", "Willem", CxfConstants.OPERATION_NAME, "greetMe");
-
-        // Sleep a while and wait for the message whole processing
-        Thread.sleep(4000);
-        template.stop();
-
-        MockEndpoint.assertIsSatisfied(camelContext);
-        List<Exchange> list = resultEndpoint.getReceivedExchanges();
-        assertEquals("Should get one message", list.size(), 1);
-        for (Exchange exchange : list) {
-            String result = (String) exchange.getIn().getBody();
-            assertEquals("Get the wrong result ", result, "Hello Willem");
-        }
+    public void testCxfToJmsInOut() throws Exception {
+        assertNotNull(template);
+        assertNotNull(inputEndpoint);
+        assertNotNull(outputEndpoint);
+
+        inputEndpoint.expectedBodiesReceived("Willem");
+        outputEndpoint.expectedBodiesReceived("Hello Willem");
+
+        String out = template.requestBodyAndHeader("cxf://bean:serviceEndpoint", "Willem", CxfConstants.OPERATION_NAME, "greetMe", String.class);
+        assertEquals("Hello Willem", out);
+
+        inputEndpoint.assertIsSatisfied();
+        outputEndpoint.assertIsSatisfied();
     }
 
 }

Copied: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CxfToJmsInOutTest-context.xml (from r1057139, camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelGreeterTest-context.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CxfToJmsInOutTest-context.xml?p2=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CxfToJmsInOutTest-context.xml&p1=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelGreeterTest-context.xml&r1=1057139&r2=1057151&rev=1057151&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelGreeterTest-context.xml (original)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CxfToJmsInOutTest-context.xml Mon Jan 10 11:10:49 2011
@@ -18,46 +18,53 @@
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:cxf="http://camel.apache.org/schema/cxf"
-
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
- <import resource="classpath:META-INF/cxf/cxf.xml"/>
- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
- <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
-
- <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/SoapContext/SoapPort"
-            wsdlURL="wsdl/hello_world.wsdl"
-     serviceClass="org.apache.hello_world_soap_http.Greeter"
-     endpointName="s:SoapOverHttp"
-     serviceName="s:SOAPService"
-        xmlns:s="http://apache.org/hello_world_soap_http">
-    <cxf:properties>
-      <entry key="setDefaultBus" value="false"/>
-    </cxf:properties>
- </cxf:cxfEndpoint>
+    <import resource="classpath:META-INF/cxf/cxf.xml"/>
+    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
+    <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml"/>
+
+    <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/SoapContext/SoapPort"
+                     wsdlURL="wsdl/hello_world.wsdl"
+                     serviceClass="org.apache.hello_world_soap_http.Greeter"
+                     endpointName="s:SoapOverHttp"
+                     serviceName="s:SOAPService"
+                     xmlns:s="http://apache.org/hello_world_soap_http">
+        <cxf:properties>
+            <entry key="setDefaultBus" value="false"/>
+        </cxf:properties>
+    </cxf:cxfEndpoint>
 
-  <bean id="prepareRequest" class="org.apache.camel.itest.greeter.PrepareRequest"/>
-  <bean id="prepareResponse" class="org.apache.camel.itest.greeter.PrepareResponse"/>
+    <bean id="prepareRequest" class="org.apache.camel.itest.greeter.PrepareRequest"/>
+    <bean id="prepareResponse" class="org.apache.camel.itest.greeter.PrepareResponse"/>
 
     <bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
         <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
     </bean>
 
-  <!-- START SNIPPET: example -->
-  <camelContext xmlns="http://camel.apache.org/schema/spring">
-    <route>
-        <from uri="jms:requestQueue"/>
-        <process ref="prepareRequest"/>
-        <to uri="cxf://bean:serviceEndpoint"/>
-        <process ref="prepareResponse"/>
-        <to uri="jms:responseQueue"/>
-        <to uri="mock:resultEndpoint"/>
-    </route>
-  </camelContext>
-  <!-- END SNIPPET: example -->
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+        <route>
+            <from uri="cxf://bean:serviceEndpoint"/>
+            <to uri="log:input"/>
+            <to uri="mock:cxf.input"/>
+            <to uri="jms:queue:bridge.output?replyTo=output.reply"/>
+            <to uri="log:reply"/>
+        </route>
+
+        <route>
+            <from uri="jms:queue:bridge.output"/>
+            <to uri="log:jms"/>
+            <setBody>
+                <simple>Hello ${body}</simple>
+            </setBody>
+            <to uri="mock:jms.output"/>
+        </route>
+
+    </camelContext>
 
 </beans>