camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r885720 - /camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
Date Tue, 01 Dec 2009 10:19:41 GMT
Author: ningjiang
Date: Tue Dec  1 10:19:41 2009
New Revision: 885720

URL: http://svn.apache.org/viewvc?rev=885720&view=rev
Log:
CAMEL-2239 committed the unit test to show how to get the the response entity

Modified:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java?rev=885720&r1=885719&r2=885720&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
Tue Dec  1 10:19:41 2009
@@ -20,6 +20,8 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+import javax.ws.rs.core.Response;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
@@ -135,6 +137,36 @@
     }
     
     @Test
+    public void testAddCustomerUniqueResponseCode() {
+        Exchange exchange = template.send("cxfrs://http://localhost:9002?httpClientAPI=true",
new Processor() {
+            
+            public void process(Exchange exchange) throws Exception {
+                exchange.setPattern(ExchangePattern.InOut);
+                Message inMessage = exchange.getIn();
+                // set the Http method
+                inMessage.setHeader(Exchange.HTTP_METHOD, "POST");
+                // set the relative path
+                inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customersUniqueResponseCode");
               
+                // put the response's entity into out message body
+                inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
+                // create a new customer object
+                Customer customer = new Customer();
+                customer.setId(8888);
+                customer.setName("Willem");
+                inMessage.setBody(customer);                
+            }
+            
+        });
+        
+        // get the response message 
+        Customer response = (Customer) exchange.getOut().getBody();
+        
+        assertNotNull("The response should not be null ", response);
+        assertTrue("Get a wrong customer id ", response.getId() != 8888);
+        assertEquals("Get a wrong customer name", response.getName(), "Willem");
+    }
+    
+    @Test
     public void testProducerWithQueryParameters() {
         // START SNIPPET: QueryExample
         Exchange exchange = template.send("cxfrs://http://localhost:9003/testQuery?httpClientAPI=true&q1=12&q2=13"



Mime
View raw message