servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r359888 - in /incubator/servicemix/trunk/servicemix-components/src/test: java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java resources/org/apache/servicemix/components/http/soap-response.xml
Date Thu, 29 Dec 2005 20:19:09 GMT
Author: gnodet
Date: Thu Dec 29 12:19:00 2005
New Revision: 359888

URL: http://svn.apache.org/viewcvs?rev=359888&view=rev
Log:
Update HttpSoapAndSaaj test to use a mock webservice to check that namespaces are correctly
handled

Added:
    incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-response.xml
Modified:
    incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java

Modified: incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java?rev=359888&r1=359887&r2=359888&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
Thu Dec 29 12:19:00 2005
@@ -23,6 +23,7 @@
 
 import javax.xml.messaging.URLEndpoint;
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.TransformerException;
 
 import junit.framework.TestCase;
@@ -30,14 +31,18 @@
 import org.activemq.broker.BrokerService;
 import org.activemq.xbean.BrokerFactoryBean;
 import org.apache.servicemix.components.saaj.SaajBinding;
+import org.apache.servicemix.components.util.MockServiceComponent;
 import org.apache.servicemix.jbi.container.ActivationSpec;
 import org.apache.servicemix.jbi.container.JBIContainer;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.jbi.util.DOMUtil;
 import org.apache.servicemix.jbi.util.FileUtil;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
 import org.apache.xpath.CachedXPathAPI;
 import org.springframework.core.io.ClassPathResource;
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.traversal.NodeIterator;
@@ -45,6 +50,7 @@
 public class HttpSoapAndSaajTest extends TestCase {
     
     private static final int PORT = 7012;
+    private static final int PORT_WS = 7013;
 
     protected JBIContainer container;
 	protected BrokerService broker;
@@ -77,7 +83,7 @@
         ActivationSpec as = new ActivationSpec();
         as.setId("saaj");
         SaajBinding saaj = new SaajBinding();
-        saaj.setSoapEndpoint(new URLEndpoint("http://64.124.140.30/soap")); 
+        saaj.setSoapEndpoint(new URLEndpoint("http://localhost:" + PORT_WS)); 
         as.setComponent(saaj);
         as.setService(new QName("saaj"));
         container.activateComponent(as);
@@ -87,6 +93,20 @@
         as.setComponent(new HttpSoapConnector(null, PORT, true));
         as.setDestinationService(new QName("saaj"));
         container.activateComponent(as);
+        
+        as = new ActivationSpec();
+        as.setId("webservice");
+        as.setComponent(new HttpConnector(null, PORT_WS));
+        as.setDestinationService(new QName("mock"));
+        container.activateComponent(as);
+        
+        as = new ActivationSpec();
+        as.setId("mock");
+        MockServiceComponent mock = new MockServiceComponent();
+        mock.setResponseResource(new ClassPathResource("soap-response.xml", getClass()));
+        as.setComponent(mock);
+        as.setService(new QName("mock"));
+        container.activateComponent(as);
 
         URLConnection connection = new URL("http://localhost:" + PORT).openConnection();
         connection.setDoOutput(true);
@@ -99,16 +119,25 @@
         InputStream is = connection.getInputStream();
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         FileUtil.copyInputStream(is, baos);
-        System.out.println(baos.toString());
         
         // Check xml validity
         Node node = new SourceTransformer().toDOMNode(new StringSource(baos.toString()));
-        
-        String text = textValueOfXPath(node, "//Result").trim();
-
-        System.out.println("Found price: " + text);
 
-        assertTrue("price text should not be empty", text.length() > 0);
+        OutputFormat format = new OutputFormat((Document) node);
+        format.setLineWidth(65);
+        format.setIndenting(true);
+        format.setIndent(2);
+        XMLSerializer serializer = new XMLSerializer(System.err, format);
+        System.err.println();
+        serializer.serialize((Document) node);
+        
+        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+        NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name()
= 'userId']");
+        Element root = (Element) iterator.nextNode();
+        QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance",
"type"));
+        assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
+        assertEquals("string", qname.getLocalPart());
+        
     }
 
     protected String textValueOfXPath(Node node, String xpath) throws TransformerException
{

Added: incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-response.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-response.xml?rev=359888&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-response.xml
(added)
+++ incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-response.xml
Thu Dec 29 12:19:00 2005
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<e:Envelope xmlns:e="http://schemas.xmlsoap.org/soap/envelope/"
+xmlns:d="http://www.w3.org/2001/XMLSchema"
+xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
+xmlns:wn0="http://systinet.com/xsd/SchemaTypes/"
+xmlns:wn1="http://systinet.com/wsdl/com/cexp/coe/bob/ws/customer/"
+xmlns:wn2="http://systinet.com/soap-jta/"
+xmlns:wn3="http://systinet.com/wsdl/com/cexp/coe/bob/services/order/pojo/">
+  <e:Body>
+    <wn1:getCustomerInfo>
+      <wn1:userId i:type="d:string">akayali</wn1:userId>
+    </wn1:getCustomerInfo>
+  </e:Body>
+</e:Envelope>



Mime
View raw message