cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject git commit: Update the ws-specs tests to use xpaths instead of direct string compares when possible.
Date Fri, 28 Mar 2014 16:13:02 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 4c5a7fa80 -> 974526c29


Update the ws-specs tests to use xpaths instead of direct string compares when possible.


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

Branch: refs/heads/master
Commit: 974526c297395b83a524bf2db6b16237c4ef6c6b
Parents: 4c5a7fa
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Mar 28 12:12:34 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Mar 28 12:12:58 2014 -0400

----------------------------------------------------------------------
 .../cxf/systest/ws/AbstractWSATestBase.java     | 34 ++++++++++++++++++++
 .../systest/ws/addr_disable/WSADisableTest.java |  5 ++-
 .../ws/addr_feature/WSAClientServerTest.java    | 25 ++++++--------
 .../ws/addr_fromjava/WSAFromJavaTest.java       |  3 +-
 .../systest/ws/addr_wsdl/WSAPureWsdlTest.java   | 33 +++++++------------
 5 files changed, 58 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/974526c2/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/AbstractWSATestBase.java
----------------------------------------------------------------------
diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/AbstractWSATestBase.java
b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/AbstractWSATestBase.java
index 400647d..7d2fbed 100644
--- a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/AbstractWSATestBase.java
+++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/AbstractWSATestBase.java
@@ -21,9 +21,18 @@ package org.apache.cxf.systest.ws;
 
 import java.io.ByteArrayOutputStream;
 import java.io.PrintWriter;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
 
+import javax.xml.stream.XMLStreamException;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.helpers.XPathUtils;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 public class AbstractWSATestBase extends AbstractBusClientServerTestBase {
@@ -45,4 +54,29 @@ public class AbstractWSATestBase extends AbstractBusClientServerTestBase
{
 
         return bos;
     }
+    
+    
+    protected String getLogValue(String log, String xpath) throws XMLStreamException {
+        String s = log.substring(log.indexOf("Payload: ") + 9);
+        Document doc = StaxUtils.read(new StringReader(s));
+        
+        Map<String, String> ns = new HashMap<String, String>();
+        ns.put("wsa", "http://www.w3.org/2005/08/addressing");
+        ns.put("soap", "http://schemas.xmlsoap.org/soap/envelope/");
+        XPathUtils xpathu = new XPathUtils(ns);
+        return xpathu.getValueString(xpath, doc.getDocumentElement());
+    }
+    protected void assertLogNotContains(String log, String xpath) throws XMLStreamException
{
+        String s = log.substring(log.indexOf("Payload: ") + 9);
+        Document doc = StaxUtils.read(new StringReader(s));
+        
+        Map<String, String> ns = new HashMap<String, String>();
+        ns.put("wsa", "http://www.w3.org/2005/08/addressing");
+        ns.put("soap", "http://schemas.xmlsoap.org/soap/envelope/");
+        XPathUtils xpathu = new XPathUtils(ns);
+        assertNull(xpathu.getValueNode(xpath, doc.getDocumentElement()));
+    }
+    protected void assertLogContains(String log, String xpath, String value) throws XMLStreamException
{
+        assertEquals(value, getLogValue(log, xpath));
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/974526c2/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_disable/WSADisableTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_disable/WSADisableTest.java
b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_disable/WSADisableTest.java
index 4424230..6aab05b 100644
--- a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_disable/WSADisableTest.java
+++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_disable/WSADisableTest.java
@@ -68,11 +68,10 @@ public class WSADisableTest extends AbstractWSATestBase {
 
         assertEquals(3, port.addNumbers(1, 2));
 
-        String base = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/";
-        String expectedOut = base + "addNumbersRequest</Action>";
+        String expectedOut = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/addNumbersRequest";
         String expectedIn = "http://www.w3.org/2005/08/addressing";
         
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
+        assertLogContains(output.toString(), "//wsa:Action", expectedOut);
         assertTrue(input.toString().indexOf(expectedIn) == -1);
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/974526c2/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
index 49f848f..8ad0764 100644
--- a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
+++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
@@ -69,11 +69,8 @@ public class WSAClientServerTest extends AbstractWSATestBase {
 
         assertEquals(3, port.addNumbers(1, 2));
         
-        String expectedOut = "<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>";
-        String expectedIn = "<RelatesTo xmlns=\"http://www.w3.org/2005/08/addressing\">";
-
-        assertTrue(output.toString().indexOf(expectedOut) == -1);
-        assertTrue(input.toString().indexOf(expectedIn) == -1);
+        assertLogNotContains(output.toString(), "//wsa:Address");
+        assertLogNotContains(input.toString(), "//wsa:RelatesTo");
     }
 
     @Test
@@ -88,12 +85,10 @@ public class WSAClientServerTest extends AbstractWSATestBase {
         AddNumbersPortType port = (AddNumbersPortType) factory.create();
         ((BindingProvider)port).getRequestContext().put("ws-addressing.write.optional.replyto",
Boolean.TRUE);
         assertEquals(3, port.addNumbers(1, 2));
-
-        String expectedOut = "<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>";
-        String expectedIn = "<RelatesTo xmlns=\"http://www.w3.org/2005/08/addressing\">";
-
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
-        assertTrue(input.toString().indexOf(expectedIn) != -1);
+        
+        assertLogContains(output.toString(), "//wsa:Address", "http://www.w3.org/2005/08/addressing/anonymous");
+        assertLogContains(input.toString(), "//wsa:RelatesTo", 
+                          getLogValue(output.toString(), "//wsa:MessageID"));
     }
 
     @Test
@@ -106,11 +101,9 @@ public class WSAClientServerTest extends AbstractWSATestBase {
 
         assertEquals(3, port.addNumbers(1, 2));
 
-        String expectedOut = "<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>";
-        String expectedIn = "<RelatesTo xmlns=\"http://www.w3.org/2005/08/addressing\">";
-
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
-        assertTrue(input.toString().indexOf(expectedIn) != -1);
+        assertLogContains(output.toString(), "//wsa:Address", "http://www.w3.org/2005/08/addressing/anonymous");
+        assertLogContains(input.toString(), "//wsa:RelatesTo", 
+                          getLogValue(output.toString(), "//wsa:MessageID"));
     }
     
     //CXF-3456

http://git-wip-us.apache.org/repos/asf/cxf/blob/974526c2/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java
b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java
index cfe66d4..ebde8e6 100644
--- a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java
+++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java
@@ -151,8 +151,7 @@ public class WSAFromJavaTest extends AbstractWSATestBase {
         } catch (SOAPFaultException ex) {
             //expected
         }
-        String expectedOut = "cxf</Action>";
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
+        assertLogContains(output.toString(), "//wsa:Action", "cxf");
         assertTrue(output.toString().indexOf("SOAPAction=[\"cxf\"]") != -1);
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/974526c2/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java
b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java
index 7d9b8ee..51e333b 100644
--- a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java
+++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java
@@ -80,13 +80,10 @@ public class WSAPureWsdlTest extends AbstractWSATestBase {
         assertEquals(3, port.addNumbers(1, 2));
 
         String base = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/";
-        String expectedOut = base + "addNumbersRequest</Action>";
-        String expectedIn = base + "addNumbersResponse</Action>";
 
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
-        assertTrue(input.toString().indexOf(expectedIn) != -1);
-        
-        
+        assertLogContains(output.toString(), "//wsa:Action", base + "addNumbersRequest");
+        assertLogContains(input.toString(), "//wsa:Action", base + "addNumbersResponse");
+
         resp = port.addNumbers3Async(1, 2);
         assertEquals(3, resp.get().getReturn());
 
@@ -108,8 +105,6 @@ public class WSAPureWsdlTest extends AbstractWSATestBase {
     @Test
     public void testProviderEndpoint() throws Exception {
         String base = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/";
-        String expectedOut = base + "addNumbersRequest</Action>";
-        String expectedIn = base + "addNumbersResponse</Action>";
 
         ByteArrayOutputStream input = setupInLogging();
         ByteArrayOutputStream output = setupOutLogging();
@@ -120,8 +115,8 @@ public class WSAPureWsdlTest extends AbstractWSATestBase {
         assertEquals(3, port.addNumbers(1, 2));
 
 
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
-        assertTrue(input.toString().indexOf(expectedIn) != -1);
+        assertLogContains(output.toString(), "//wsa:Action", base + "addNumbersRequest");
+        assertLogContains(input.toString(), "//wsa:Action", base + "addNumbersResponse");
 
         output.reset();
         input.reset();
@@ -130,8 +125,8 @@ public class WSAPureWsdlTest extends AbstractWSATestBase {
             "http://localhost:" + PORT + "/jaxws/add-providernows");
         assertEquals(3, port.addNumbers(1, 2));
 
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
-        assertTrue(input.toString().indexOf(expectedIn) != -1);
+        assertLogContains(output.toString(), "//wsa:Action", base + "addNumbersRequest");
+        assertLogContains(input.toString(), "//wsa:Action", base + "addNumbersResponse");
     }
 
     @Test
@@ -139,9 +134,6 @@ public class WSAPureWsdlTest extends AbstractWSATestBase {
         String req = "<addNumbers xmlns=\"http://apache.org/cxf/systest/ws/addr_feature/\">"
             + "<number1>1</number1><number2>2</number2></addNumbers>";
         String base = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/";
-        String expectedOut = base + "addNumbersRequest";
-        String expectedIn = base + "addNumbersResponse</Action>";
-
         
         ByteArrayOutputStream input = setupInLogging();
         ByteArrayOutputStream output = setupOutLogging();
@@ -159,8 +151,9 @@ public class WSAPureWsdlTest extends AbstractWSATestBase {
 
         disp.invoke(new StreamSource(new StringReader(req)));
         
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
-        assertTrue(input.toString().indexOf(expectedIn) != -1);
+        
+        assertLogContains(output.toString(), "//wsa:Action", base + "addNumbersRequest");
+        assertLogContains(input.toString(), "//wsa:Action", base + "addNumbersResponse");
         
 
         output.reset();
@@ -179,10 +172,8 @@ public class WSAPureWsdlTest extends AbstractWSATestBase {
         
         disp.invoke(new StreamSource(new StringReader(req)));
         
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
-        assertTrue(input.toString().indexOf(expectedIn) != -1);
-
-        
+        assertLogContains(output.toString(), "//wsa:Action", base + "addNumbersRequest");
+        assertLogContains(input.toString(), "//wsa:Action", base + "addNumbersResponse");
     }
     
     @Test


Mime
View raw message