Author: fadushin
Date: Thu Apr 10 14:05:50 2008
New Revision: 646961

URL: http://svn.apache.org/viewvc?rev=646961&view=rev
Log:
WSS-93 use correct NS variants for DOM attribute getters and setters

 * Applied Frank's patch
 * Added a unit test for the module


Added:
    webservices/wss4j/trunk/test/components/TestReference.java   (with props)
Modified:
    
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/Reference.java
    webservices/wss4j/trunk/test/components/PackageTests.java

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/Reference.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/token/Reference.java?rev=646961&r1=646960&r2=646961&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/Reference.java 
(original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/Reference.java 
Thu Apr 10 14:05:50 2008
@@ -93,7 +93,7 @@
      * @return TODO
      */
     public String getValueType() {
-        return this.element.getAttribute("ValueType");
+        return this.element.getAttributeNS(null, "ValueType");
     }
 
     /**
@@ -103,7 +103,7 @@
      * @return TODO
      */
     public String getURI() {
-        return this.element.getAttribute("URI");
+        return this.element.getAttributeNS(null, "URI");
     }
 
     /**
@@ -113,7 +113,7 @@
      * @param valueType
      */
     public void setValueType(String valueType) {
-        this.element.setAttribute("ValueType", valueType);
+        this.element.setAttributeNS(null, "ValueType", valueType);
     }
 
     /**
@@ -123,7 +123,7 @@
      * @param uri 
      */
     public void setURI(String uri) {
-        this.element.setAttribute("URI", uri);
+        this.element.setAttributeNS(null, "URI", uri);
     }
 
     /**

Modified: webservices/wss4j/trunk/test/components/PackageTests.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/components/PackageTests.java?rev=646961&r1=646960&r2=646961&view=diff
==============================================================================
--- webservices/wss4j/trunk/test/components/PackageTests.java (original)
+++ webservices/wss4j/trunk/test/components/PackageTests.java Thu Apr 10 
14:05:50 2008
@@ -51,6 +51,7 @@
         TestSuite suite = new TestSuite();
         suite.addTestSuite(TestMerlin.class);
         suite.addTestSuite(TestX509NameTokenizer.class);
+        suite.addTestSuite(TestReference.class);
         return suite;
     }
 

Added: webservices/wss4j/trunk/test/components/TestReference.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/components/TestReference.java?rev=646961&view=auto
==============================================================================
--- webservices/wss4j/trunk/test/components/TestReference.java (added)
+++ webservices/wss4j/trunk/test/components/TestReference.java Thu Apr 10 
14:05:50 2008
@@ -0,0 +1,138 @@
+/*
+ * Copyright The Apache Software Foundation.
+ *
+ *  Licensed 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 components;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.message.token.Reference;
+
+/**
+ * unit test for the Reference type
+ */
+public class TestReference extends TestCase {
+
+    private static final String 
+    TEST_REFERENCE_TEMPLATE = 
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+        +   "<wss:Reference "
+        +       
"xmlns:wss=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\";
 "
+        +       "ValueType=\"TheValueType\" "
+        +       "URI=\"TheURI\" "
+        +       "/>"
+        ;
+
+    private static final String 
+    BOGUS_REFERENCE_TEMPLATE = 
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+        +   "<wss:Reference "
+        +       "xmlns:wss=\"http://something-completely-different\"; "
+        +       "ValueType=\"TheValueType\" "
+        +       "URI=\"TheURI\" "
+        +       "/>"
+        ;
+
+
+    public TestReference(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestReference.class);
+    }
+    
+    
+    public void
+    testConstructor() throws Exception {
+        //
+        // null input
+        //
+        try {
+            new Reference((org.w3c.dom.Element) null);
+            fail("Expected failure on null Element passed to ctor");
+        } catch (final WSSecurityException e) {
+            // complete
+        }
+        //
+        // The XML doesn't conform to the WSS namespace
+        //
+        try {
+            new Reference(
+                createReferenceDocument(
+                    BOGUS_REFERENCE_TEMPLATE,
+                    "foo", "bar"
+                ).getDocumentElement()
+            );
+            fail("Expected failure on bogus template");
+        } catch (final Exception e) {
+            // complete
+        }
+        //
+        // create a Reference from valid XML
+        //
+        new Reference(
+            createReferenceDocument(
+                TEST_REFERENCE_TEMPLATE,
+                "foo", "bar"
+            )
+        );
+        new Reference(
+            createReferenceDocument(
+                TEST_REFERENCE_TEMPLATE,
+                "foo", "bar"
+            ).getDocumentElement()
+        );
+    }
+    
+    public void
+    testAccessors() throws Exception {
+        final Reference ref = new Reference(
+            createReferenceDocument(
+                TEST_REFERENCE_TEMPLATE,
+                "foo", "bar"
+            ).getDocumentElement()
+        );
+        assertEquals(ref.getValueType(), "foo");
+        assertEquals(ref.getURI(), "bar");
+    }
+    
+    private static org.w3c.dom.Document
+    createReferenceDocument(
+        final String template,
+        final String valueType,
+        final String uri
+    ) throws javax.xml.parsers.ParserConfigurationException,
+             org.xml.sax.SAXException,
+             java.io.IOException {
+        final java.io.InputStream in = 
+            new java.io.ByteArrayInputStream(
+                template.replaceFirst(
+                    "TheValueType", valueType
+                ).replaceFirst(
+                    "TheURI", uri
+                ).getBytes()
+            );
+        final javax.xml.parsers.DocumentBuilderFactory factory = 
+            javax.xml.parsers.DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        final javax.xml.parsers.DocumentBuilder builder = 
factory.newDocumentBuilder();
+        return builder.parse(in);
+    }
+}

Propchange: webservices/wss4j/trunk/test/components/TestReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: webservices/wss4j/trunk/test/components/TestReference.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to