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 2013/07/18 03:37:55 UTC

git commit: Added an unit test for CxfConsumerPayload

Updated Branches:
  refs/heads/master 65ed7ff30 -> 907939867


Added an unit test for CxfConsumerPayload


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/90793986
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/90793986
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/90793986

Branch: refs/heads/master
Commit: 907939867156367d5e0c3206b7fa233d1be30216
Parents: 65ed7ff
Author: Willem Jiang <ni...@apache.org>
Authored: Thu Jul 18 09:35:17 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Thu Jul 18 09:36:06 2013 +0800

----------------------------------------------------------------------
 .../cxf/CxfConsumerPayLoadConvertorTest.java    | 67 ++++++++++++++++++++
 .../component/cxf/CxfConsumerPayloadTest.java   | 10 +--
 2 files changed, 72 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/90793986/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadConvertorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadConvertorTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadConvertorTest.java
new file mode 100644
index 0000000..ba72996
--- /dev/null
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadConvertorTest.java
@@ -0,0 +1,67 @@
+/**
+ * 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 java.util.List;
+
+import javax.xml.transform.Source;
+
+import org.w3c.dom.Element;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.converter.jaxp.XmlConverter;
+import org.apache.cxf.binding.soap.SoapHeader;
+
+
+
+public class CxfConsumerPayLoadConvertorTest extends CxfConsumerPayloadTest {
+    
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from(simpleEndpointURI + "&dataFormat=PAYLOAD").to("log:info").process(new Processor() {
+                    @SuppressWarnings("unchecked")
+                    public void process(final Exchange exchange) throws Exception {
+                        CxfPayload<SoapHeader> requestPayload = exchange.getIn().getBody(CxfPayload.class);
+                        List<Source> inElements = requestPayload.getBodySources();
+                        // You can use a customer toStringConverter to turn a CxfPayLoad message into String as you want                        
+                        String request = exchange.getIn().getBody(String.class);
+                        String documentString = ECHO_RESPONSE;
+                        
+                        Element in = new XmlConverter().toDOMElement(inElements.get(0));
+                        // Just check the element namespace
+                        if (!in.getNamespaceURI().equals(ELEMENT_NAMESPACE)) {
+                            throw new IllegalArgumentException("Wrong element namespace");
+                        }
+                        if (in.getLocalName().equals("echoBoolean")) {
+                            documentString = ECHO_BOOLEAN_RESPONSE;
+                            checkRequest("ECHO_BOOLEAN_REQUEST", request);
+                        } else {
+                            documentString = ECHO_RESPONSE;
+                            checkRequest("ECHO_REQUEST", request);
+                        }
+                        // just set the documentString into to the message body
+                        exchange.getOut().setBody(documentString); 
+                    }
+                });
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/90793986/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java
index ec9cf00..01b9e46 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java
@@ -33,18 +33,18 @@ import org.apache.cxf.binding.soap.SoapHeader;
 
 public class CxfConsumerPayloadTest extends CxfConsumerMessageTest {
         
-    private static final String ECHO_RESPONSE = "<ns1:echoResponse xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
+    protected static final String ECHO_RESPONSE = "<ns1:echoResponse xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
             + "<return xmlns=\"http://cxf.component.camel.apache.org/\">echo Hello World!</return>"
             + "</ns1:echoResponse>";
-    private static final String ECHO_BOOLEAN_RESPONSE = "<ns1:echoBooleanResponse xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
+    protected static final String ECHO_BOOLEAN_RESPONSE = "<ns1:echoBooleanResponse xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
             + "<return xmlns=\"http://cxf.component.camel.apache.org/\">true</return>"
             + "</ns1:echoBooleanResponse>";
-    private static final String ECHO_REQUEST = "<ns1:echo xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
+    protected static final String ECHO_REQUEST = "<ns1:echo xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
             + "<arg0 xmlns=\"http://cxf.component.camel.apache.org/\">Hello World!</arg0></ns1:echo>";
-    private static final String ECHO_BOOLEAN_REQUEST = "<ns1:echoBoolean xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
+    protected static final String ECHO_BOOLEAN_REQUEST = "<ns1:echoBoolean xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
             + "<arg0 xmlns=\"http://cxf.component.camel.apache.org/\">true</arg0></ns1:echoBoolean>";
     
-    private static final String ELEMENT_NAMESPACE = "http://cxf.component.camel.apache.org/";
+    protected static final String ELEMENT_NAMESPACE = "http://cxf.component.camel.apache.org/";
     
     protected void checkRequest(String expect, String request) {
         if (expect.equals("ECHO_REQUEST")) {