11/* 
2-  * Copyright 2008  the original author or authors. 
2+  * Copyright 2002-2009  the original author or authors. 
33 * 
44 * Licensed under the Apache License, Version 2.0 (the "License"); 
55 * you may not use this file except in compliance with the License. 
1616package  org .springframework .ws .soap .security .wss4j ;
1717
1818import  java .io .InputStream ;
19- import  java .util .HashMap ;
20- import  java .util .Map ;
19+ import  java .util .Properties ;
2120import  javax .xml .soap .MessageFactory ;
2221import  javax .xml .soap .MimeHeaders ;
2322import  javax .xml .soap .SOAPMessage ;
2423import  javax .xml .stream .XMLInputFactory ;
2524import  javax .xml .stream .XMLStreamReader ;
25+ import  javax .xml .transform .dom .DOMSource ;
2626
2727import  junit .framework .TestCase ;
2828import  org .apache .axiom .soap .impl .builder .StAXSOAPModelBuilder ;
4141import  org .springframework .ws .soap .axiom .support .AxiomUtils ;
4242import  org .springframework .ws .soap .saaj .SaajSoapMessage ;
4343import  org .springframework .ws .soap .saaj .SaajSoapMessageFactory ;
44- import  org .springframework .xml .xpath . XPathExpression ;
45- import  org .springframework .xml .xpath .XPathExpressionFactory ;
44+ import  org .springframework .xml .transform . StringSource ;
45+ import  org .springframework .xml .xpath .Jaxp13XPathTemplate ;
4646
4747public  abstract  class  Wss4jTestCase  extends  TestCase  {
4848
@@ -52,43 +52,57 @@ public abstract class Wss4jTestCase extends TestCase {
5252
5353    protected  final  boolean  saajTest  = this .getClass ().getSimpleName ().startsWith ("Saaj" );
5454
55-     protected  Map   namespaces ;
55+     protected  Jaxp13XPathTemplate   xpathTemplate  =  new   Jaxp13XPathTemplate () ;
5656
5757    protected  final  void  setUp () throws  Exception  {
5858        if  (!axiomTest  && !saajTest ) {
5959            throw  new  IllegalArgumentException ("test class name must statrt with either Axiom or Saaj" );
6060        }
6161        messageFactory  = MessageFactory .newInstance ();
62-         namespaces  = new  HashMap ();
63-         namespaces .put ("SOAP-ENV" , "http://schemas.xmlsoap.org/soap/envelope/" );
64-         namespaces .put ("wsse" , "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" );
65-         namespaces .put ("ds" , "http://www.w3.org/2000/09/xmldsig#" );
66-         namespaces .put ("xenc" , "http://www.w3.org/2001/04/xmlenc#" );
62+         Properties  namespaces  = new  Properties ();
63+         namespaces .setProperty ("SOAP-ENV" , "http://schemas.xmlsoap.org/soap/envelope/" );
64+         namespaces .setProperty ("wsse" ,
65+                 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" );
66+         namespaces .setProperty ("ds" , "http://www.w3.org/2000/09/xmldsig#" );
67+         namespaces .setProperty ("xenc" , "http://www.w3.org/2001/04/xmlenc#" );
6768//        namespaces.put("wsse11", "http://docs.oasis-open.org/wss/2005/xx/oasis-2005xx-wss-wssecurity-secext-1.1.xsd"); 
68-         namespaces .put ("wsse11" , "http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" );
69-         namespaces .put ("echo" , "http://www.springframework.org/spring-ws/samples/echo" );
70-         namespaces .put ("wsu" , "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" );
69+         namespaces .setProperty ("wsse11" , "http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" );
70+         namespaces .setProperty ("echo" , "http://www.springframework.org/spring-ws/samples/echo" );
71+         namespaces .setProperty ("wsu" ,
72+                 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" );
73+         namespaces .setProperty ("test" , "http://test" );
74+         xpathTemplate .setNamespaces (namespaces );
7175        onSetup ();
7276    }
7377
7478    protected  void  assertXpathEvaluatesTo (String  message ,
7579                                          String  expectedValue ,
7680                                          String  xpathExpression ,
7781                                          Document  document ) {
78-         XPathExpression  expression  = XPathExpressionFactory .createXPathExpression (xpathExpression , namespaces );
79-         String  actualValue  = expression .evaluateAsString (document );
82+         String  actualValue  = xpathTemplate .evaluateAsString (xpathExpression , new  DOMSource (document ));
83+         assertEquals (message , expectedValue , actualValue );
84+     }
85+ 
86+     protected  void  assertXpathEvaluatesTo (String  message ,
87+                                           String  expectedValue ,
88+                                           String  xpathExpression ,
89+                                           String  document ) {
90+         String  actualValue  = xpathTemplate .evaluateAsString (xpathExpression , new  StringSource (document ));
8091        assertEquals (message , expectedValue , actualValue );
8192    }
8293
8394    protected  void  assertXpathExists (String  message , String  xpathExpression , Document  document ) {
84-         XPathExpression  expression  = XPathExpressionFactory .createXPathExpression (xpathExpression , namespaces );
85-         Node  node  = expression .evaluateAsNode (document );
95+         Node  node  = xpathTemplate .evaluateAsNode (xpathExpression , new  DOMSource (document ));
8696        assertNotNull (message , node );
8797    }
8898
8999    protected  void  assertXpathNotExists (String  message , String  xpathExpression , Document  document ) {
90-         XPathExpression  expression  = XPathExpressionFactory .createXPathExpression (xpathExpression , namespaces );
91-         Node  node  = expression .evaluateAsNode (document );
100+         Node  node  = xpathTemplate .evaluateAsNode (xpathExpression , new  DOMSource (document ));
101+         assertNull (message , node );
102+     }
103+ 
104+     protected  void  assertXpathNotExists (String  message , String  xpathExpression , String  document ) {
105+         Node  node  = xpathTemplate .evaluateAsNode (xpathExpression , new  StringSource (document ));
92106        assertNull (message , node );
93107    }
94108
0 commit comments