Author: dkulp
Date: Mon Feb 21 16:28:25 2011
New Revision: 1073050

URL: http://svn.apache.org/viewvc?rev=1073050&view=rev
Log:
Fix issues with Primitives with text content having the text get lost
Fix a bunch of issues with serializing things
Make XmlPrimitiveAssertion extend PrimitiveAssertion
Add a couple basic test cases for all of the above.

Added:
    
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
    
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
    
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
    
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
    
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java

Modified: 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java?rev=1073050&r1=1073049&r2=1073050&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
 (original)
+++ 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
 Mon Feb 21 16:28:25 2011
@@ -25,6 +25,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
@@ -147,18 +148,22 @@ public class Policy extends All {
         String localName = null;
 
         Map<String, String> prefix2ns = new HashMap<String, String>();
+        boolean writeNS = true;
 
-        for (Iterator iterator = getAttributes().keySet().iterator(); iterator
-                .hasNext();) {
+        for (Map.Entry<QName, String> ents : attributes.entrySet()) {
             
-            key = (QName) iterator.next();
+            key = ents.getKey();
             localName = key.getLocalPart();
             
             namespaceURI = key.getNamespaceURI();
             namespaceURI = (namespaceURI == null || namespaceURI.length() == 
0) ? null : namespaceURI;
                         
-            if (namespaceURI != null) {
-                
+            if (namespaceURI != null && 
XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) {
+                writer.writeNamespace(localName, ents.getValue());
+                if (nspace.equals(ents.getValue())) {
+                    writeNS = false;
+                }
+            } else if (namespaceURI != null) {
                 String writerPrefix = writer.getPrefix(namespaceURI);
                 writerPrefix = (writerPrefix == null || writerPrefix.length() 
== 0) ? null : writerPrefix;
                 
@@ -171,11 +176,11 @@ public class Policy extends All {
                 }
                 
                 if (prefix != null) {
-                    writer.writeAttribute(prefix, namespaceURI, localName, 
getAttribute(key));
+                    writer.writeAttribute(prefix, namespaceURI, localName, 
ents.getValue());
                     prefix2ns.put(prefix, key.getNamespaceURI());
 
                 } else {
-                    writer.writeAttribute(namespaceURI, localName, 
getAttribute(key));
+                    writer.writeAttribute(namespaceURI, localName, 
ents.getValue());
                 }
                     
             } else {
@@ -185,8 +190,10 @@ public class Policy extends All {
             
         }
 
-        // writes xmlns:wsp=".."
-        writer.writeNamespace(wspPrefix, nspace);
+        if (writeNS) {
+            // writes xmlns:wsp=".."
+            writer.writeNamespace(wspPrefix, nspace);
+        }
 
         String prefiX;
 

Modified: 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java?rev=1073050&r1=1073049&r2=1073050&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
 (original)
+++ 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
 Mon Feb 21 16:28:25 2011
@@ -111,30 +111,11 @@ public class PolicyContainingPrimitiveAs
     public Policy getPolicy() {
         return nested;
     }
-    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        String namespace = Constants.findPolicyNamespace(writer);
-        String pfx = writer.getPrefix(name.getNamespaceURI());
-        boolean writeNS = false;
-        if ("".equals(pfx) || pfx == null) {
-            pfx = "";
-            writer.setDefaultNamespace(name.getNamespaceURI());
-            writeNS = true;
-        } else {
-            pfx = pfx + ":";
-        }
-        writer.writeStartElement(name.getNamespaceURI(), pfx + 
name.getLocalPart());
-        if (writeNS) {
-            writer.writeDefaultNamespace(name.getNamespaceURI());
-        }
-        if (optional) {
-            writer.writeAttribute(namespace, Constants.ATTR_OPTIONAL, "true");
-        }
-        if (ignorable) {
-            writer.writeAttribute(namespace, Constants.ATTR_IGNORABLE, "true");
-        }
-        writeAttributes(writer);
+    protected void writeContents(XMLStreamWriter writer) throws 
XMLStreamException {
         nested.serialize(writer);
-        writer.writeEndElement();
+    }
+    protected boolean hasContents() {
+        return true;
     }
 
 }

Modified: 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java?rev=1073050&r1=1073049&r2=1073050&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
 (original)
+++ 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
 Mon Feb 21 16:28:25 2011
@@ -23,6 +23,7 @@ package org.apache.neethi.builders;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
@@ -41,6 +42,7 @@ public class PrimitiveAssertion implemen
     protected QName name;
     protected boolean optional;
     protected boolean ignorable;
+    protected String textValue;
     protected Map<QName, String> attributes;
     
     public PrimitiveAssertion() {
@@ -55,17 +57,22 @@ public class PrimitiveAssertion implemen
         this(n, o, false);
     }
     public PrimitiveAssertion(QName n, boolean o, boolean i) {
-        name = n;
-        optional = o;
-        ignorable = i;
+        this(n, o, i, null, null);
     }
-    public PrimitiveAssertion(QName n, boolean o, boolean i, Map<QName, 
String> atts) {
+    public PrimitiveAssertion(QName n, boolean o, boolean i,
+                              Map<QName, String> atts) {
+        this(n, o, i, atts, null);
+    }
+    public PrimitiveAssertion(QName n, boolean o, boolean i,
+                              Map<QName, String> atts,
+                              String value) {
         name = n;
         optional = o;
         ignorable = i;
         if (atts != null) {
             attributes = new HashMap<QName, String>(atts);
         }
+        textValue = value;
     }
     public String getAttribute(QName n) {
         if (attributes != null) {
@@ -86,6 +93,13 @@ public class PrimitiveAssertion implemen
             attributes.putAll(atts);
         }
     }
+    public String getTextValue() {
+        return textValue;
+    }
+    public void setTextValue(String s) {
+        textValue = s;
+    }
+    
     public String toString() {
         return name.toString();
     }
@@ -147,17 +161,31 @@ public class PrimitiveAssertion implemen
         String namespace = Constants.findPolicyNamespace(writer);
         String pfx = writer.getPrefix(name.getNamespaceURI());
         boolean writeNS = false;
+        if (pfx == null && name.getPrefix() != null && 
!"".equals(name.getPrefix())) {
+            pfx = name.getPrefix();
+            writeNS = true;
+        }
         if ("".equals(pfx) || pfx == null) {
             pfx = "";
-            writer.setDefaultNamespace(name.getNamespaceURI());
             writeNS = true;
-        } else {
-            pfx = pfx + ":";
         }
-        writer.writeStartElement(name.getNamespaceURI(), pfx + 
name.getLocalPart());
+        
+        if (!hasContents() && attributes == null && !writeNS) {
+            writer.writeEmptyElement(pfx, name.getLocalPart(), 
name.getNamespaceURI());
+            return;
+        }
+        
+        writer.writeStartElement(pfx, name.getLocalPart(), 
name.getNamespaceURI());
+        
         if (writeNS) {
-            writer.writeDefaultNamespace(name.getNamespaceURI());
+            if ("".equals(pfx) || pfx == null) {
+                writer.writeDefaultNamespace(name.getNamespaceURI());
+            } else if (attributes == null 
+                || !attributes.containsKey(new 
QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, pfx))) {
+                writer.writeNamespace(pfx, name.getNamespaceURI());
+            }
         }
+        
         if (optional) {
             writer.writeAttribute(namespace, Constants.ATTR_OPTIONAL, "true");
         }
@@ -165,8 +193,19 @@ public class PrimitiveAssertion implemen
             writer.writeAttribute(namespace, Constants.ATTR_IGNORABLE, "true");
         }
         writeAttributes(writer);
+        writeContents(writer);
         writer.writeEndElement();
     }
+    protected void writeContents(XMLStreamWriter writer) throws 
XMLStreamException {
+        if (textValue != null) {
+            writer.writeCharacters(textValue);
+        }
+    }    
+    protected boolean hasContents() {
+        return textValue != null && !"".equals(textValue);
+    }
+
+    
     protected void writeAttributes(XMLStreamWriter writer) throws 
XMLStreamException {
         if (attributes != null) {
             for (Map.Entry<QName, String> att : attributes.entrySet()) {
@@ -178,14 +217,26 @@ public class PrimitiveAssertion implemen
                     //already handled
                     continue;
                 }
-                String prefix = 
getOrCreatePrefix(att.getKey().getNamespaceURI(), writer);
-                writer.writeAttribute(prefix, att.getKey().getNamespaceURI(),
-                                      att.getKey().getLocalPart(),
-                                      att.getValue());
+                if 
(XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(att.getKey().getNamespaceURI())) {
+                    writer.writeNamespace(att.getKey().getLocalPart(), 
att.getValue());
+                    continue;
+                }
+                String ns = att.getKey().getNamespaceURI();
+                if (ns != null && !"".equals(ns)) {
+                    String prefix = 
getOrCreatePrefix(att.getKey().getNamespaceURI(), writer);
+                    writer.writeAttribute(prefix, 
att.getKey().getNamespaceURI(),
+                                          att.getKey().getLocalPart(),
+                                          att.getValue());
+                } else {
+                    writer.writeAttribute(att.getKey().getLocalPart(), 
att.getValue());
+                }
             }
         }
     }
     protected String getOrCreatePrefix(String ns, XMLStreamWriter writer) 
throws XMLStreamException {
+        if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(ns)) {
+            return null;
+        }
         String prefix = writer.getPrefix(ns);
         int count = 1;
         while (prefix == null || "".equals(prefix)) {
@@ -202,7 +253,7 @@ public class PrimitiveAssertion implemen
     }
     
     protected Assertion clone(boolean isoptional) {
-        return new PrimitiveAssertion(name, isoptional, ignorable, attributes);
+        return new PrimitiveAssertion(name, isoptional, ignorable, attributes, 
textValue);
     }
 
 }
\ No newline at end of file

Modified: 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java?rev=1073050&r1=1073049&r2=1073050&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
 (original)
+++ 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
 Mon Feb 21 16:28:25 2011
@@ -76,12 +76,15 @@ public class XMLPrimitiveAssertionBuilde
     }
     
     public Assertion newPrimitiveAssertion(Element element, Map<QName, String> 
atts) {
-        return new PrimitiveAssertion(new QName(element.getNamespaceURI(), 
element.getLocalName()),
-                                      isOptional(element), 
isIgnorable(element));        
+        return new PrimitiveAssertion(new QName(element.getNamespaceURI(), 
element.getLocalName(), element.getPrefix()),
+                                      isOptional(element), 
isIgnorable(element),
+                                      atts,
+                                      element.getTextContent());
     }
     public Assertion newPolicyContainingAssertion(Element element, Map<QName, 
String> atts, Policy policy) {
         return new PolicyContainingPrimitiveAssertion(new 
QName(element.getNamespaceURI(),
-                                                                
element.getLocalName()),
+                                                                
element.getLocalName(),
+                                                                
element.getPrefix()),
                                       isOptional(element), 
isIgnorable(element),
                                       policy);
     }

Modified: 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java?rev=1073050&r1=1073049&r2=1073050&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java
 (original)
+++ 
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java
 Mon Feb 21 16:28:25 2011
@@ -43,6 +43,7 @@ import org.apache.neethi.Constants;
 import org.apache.neethi.ExactlyOne;
 import org.apache.neethi.Policy;
 import org.apache.neethi.PolicyComponent;
+import org.apache.neethi.builders.PrimitiveAssertion;
 
 /**
  * XmlPrimitiveAssertion wraps an Element s.t. any unknown elements can be
@@ -50,11 +51,8 @@ import org.apache.neethi.PolicyComponent
  * assertion from that Element.
  * 
  */
-public class XmlPrimitiveAssertion implements Assertion {
-
+public class XmlPrimitiveAssertion extends PrimitiveAssertion implements 
Assertion {
     protected Element element;
-    protected boolean optional;
-    protected boolean ignorable;
 
     /**
      * Constructs a XmlPrimitiveAssertion from an Element.
@@ -63,9 +61,10 @@ public class XmlPrimitiveAssertion imple
      *            the Element from which the XmlAssertion is constructed
      */
     public XmlPrimitiveAssertion(Element element) {
+        super(new QName(element.getNamespaceURI(), element.getLocalName(), 
element.getPrefix()),
+              XMLPrimitiveAssertionBuilder.isOptional(element), 
+              XMLPrimitiveAssertionBuilder.isIgnorable(element));
         this.element = element;
-        setOptionality(element);
-        setIgnorability(element);
     }
 
 
@@ -95,20 +94,6 @@ public class XmlPrimitiveAssertion imple
         return element;
     }
 
-    /**
-     * Returns <tt>true</tt> if the wrapped element that assumed to be an
-     * assertion, is optional.
-     */
-    public boolean isOptional() {
-        return optional;
-    }
-    /**
-     * Returns <tt>true</tt> if the wrapped element that assumed to be an
-     * assertion, is ignorable.
-     */
-    public boolean isIgnorable() {
-        return ignorable;
-    }
 
     /**
      * Returns the partial normalized version of the wrapped Element, that is
@@ -141,13 +126,6 @@ public class XmlPrimitiveAssertion imple
         return this;
     }
 
-    /**
-     * Throws an UnsupportedOperationException since an assertion of an unknown
-     * element can't be fully normalized due to it's unkonwn composite.
-     */
-    public PolicyComponent normalize(boolean isDeep) {
-        throw new UnsupportedOperationException();
-    }
 
     public void serialize(XMLStreamWriter writer) throws XMLStreamException {
         if (element != null) {
@@ -164,28 +142,6 @@ public class XmlPrimitiveAssertion imple
         return Constants.TYPE_ASSERTION;
     }
 
-    private void setOptionality(Element element2) {
-        Attr attribute = 
element2.getAttributeNodeNS(Constants.URI_POLICY_13_NS, 
Constants.ATTR_OPTIONAL);
-        if (attribute == null) {
-            attribute = 
element2.getAttributeNodeNS(Constants.URI_POLICY_15_NS, 
Constants.ATTR_OPTIONAL);
-        }
-        if (attribute != null) {
-            this.optional = Boolean.parseBoolean(attribute.getValue());
-
-        } else {
-            this.optional = false;
-        }
-    }
-    private void setIgnorability(Element element2) {
-        Attr attribute = 
element2.getAttributeNodeNS(Constants.URI_POLICY_15_NS, 
Constants.ATTR_IGNORABLE);
-        if (attribute != null) {
-            this.ignorable = Boolean.parseBoolean(attribute.getValue());
-        } else {
-            this.ignorable = false;
-        }
-        
-    }
-
     public boolean equal(PolicyComponent policyComponent) {
         if (policyComponent.getType() != Constants.TYPE_ASSERTION) {
             return false;
@@ -210,7 +166,7 @@ public class XmlPrimitiveAssertion imple
             case XMLEvent.START_DOCUMENT:
             case XMLEvent.END_DOCUMENT:
                 //not doing this as we're in a partial write mode
-                return;
+                break;
 
             case XMLEvent.END_ELEMENT:
                 writer.writeEndElement();

Added: 
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java?rev=1073050&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
 (added)
+++ 
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
 Mon Feb 21 16:28:25 2011
@@ -0,0 +1,143 @@
+/**
+ * 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.neethi;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.w3c.dom.Element;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import junit.framework.TestCase;
+
+import org.apache.neethi.builders.PrimitiveAssertion;
+import org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder;
+
+/**
+ * 
+ */
+public class BasicTestCases extends TestCase {
+    PolicyBuilder pb = new PolicyBuilder();
+    
+    public void testPrimitiveBuilder() throws Exception {
+        String text = "<ns1:MaximumRetransmissionCount FooAtt=\"blah\" 
xmlns:ns1=\"http://foo\";>10"
+            + "</ns1:MaximumRetransmissionCount>";
+        
+        
+        Assertion as = new 
XMLPrimitiveAssertionBuilder().build(getElementFromString(text),
+                                                                
pb.getAssertionBuilderFactory());
+        assertNotNull(as);
+        PrimitiveAssertion pas = (PrimitiveAssertion)as;
+        assertEquals("10", pas.getTextValue());
+        assertEquals("blah", pas.getAttribute(new QName("FooAtt")));
+        
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xwriter = 
XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        pas.serialize(xwriter);
+        xwriter.flush();
+        
+        Element el = getElementFromString(writer.getBuffer().toString());
+        assertEquals("blah", el.getAttribute("FooAtt"));
+        assertEquals("10", el.getTextContent());
+    }
+    public void testPolicyChildren() throws Exception {
+        String text = "<sp:Wss11 
xmlns:sp=\"http://schemas.xmlsoap.org/ws/2005/07/securitypolicy\";>"
+                      + "<wsp:Policy 
xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\";>"
+                      + "<sp:MustSupportRefKeyIdentifier/>"
+                      + "<sp:MustSupportRefIssuerSerial/>"
+                      + "<sp:MustSupportRefThumbprint/>"
+                      + "<sp:MustSupportRefEncryptedKey/>"
+                      + "</wsp:Policy></sp:Wss11>";
+                                                                               
         
+
+        Assertion as = new 
XMLPrimitiveAssertionBuilder().build(getElementFromString(text),
+                                                                
pb.getAssertionBuilderFactory());
+        assertNotNull(as);
+        
+        
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xwriter = 
XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        as.serialize(xwriter);
+        xwriter.flush();
+        xwriter.close();
+        
+        Element el = getElementFromString(writer.getBuffer().toString());
+        assertEquals("Wss11", el.getLocalName());
+        el = (Element)el.getFirstChild();
+        assertEquals("Policy", el.getLocalName());
+        el = (Element)el.getFirstChild();
+        assertEquals("MustSupportRefKeyIdentifier", el.getLocalName());
+    }
+
+    
+    public void testMultiChildren() throws Exception {
+        String text = "<sp:SignedParts 
xmlns:sp=\"http://schemas.xmlsoap.org/ws/2005/07/securitypolicy\";>"
+            + "<sp:Body />"
+            + "<sp:Header Name=\"To\" 
Namespace=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\"/>"
+            + "<sp:Header Name=\"From\" 
Namespace=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\"; />"
+            + "</sp:SignedParts>";
+
+        Assertion as = new 
XMLPrimitiveAssertionBuilder().build(getElementFromString(text),
+                                                                
pb.getAssertionBuilderFactory());
+        assertNotNull(as);
+        
+        
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xwriter = 
XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        as.serialize(xwriter);
+        xwriter.flush();
+        xwriter.close();
+        
+        Element el = getElementFromString(writer.getBuffer().toString());
+        assertEquals("SignedParts", el.getLocalName());
+        el = (Element)el.getFirstChild();
+        assertEquals("Body", el.getLocalName());
+        el = (Element)el.getNextSibling();
+        assertEquals("Header", el.getLocalName());
+    }
+
+    
+    private Element getElementFromString(String s) 
+        throws ParserConfigurationException, SAXException, IOException {
+        
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+
+        dbf.setValidating(false);
+        dbf.setIgnoringComments(false);
+        dbf.setIgnoringElementContentWhitespace(true);
+        dbf.setNamespaceAware(true);
+
+        DocumentBuilder db = null;
+        db = dbf.newDocumentBuilder();
+
+        
+        return db.parse(new InputSource(new 
StringReader(s))).getDocumentElement();
+    }
+}

Propchange: 
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date


Reply via email to