You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ru...@apache.org on 2005/12/23 10:40:56 UTC

svn commit: r358784 [4/4] - in /webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2: src/org/apache/axis2/saaj2/ test-resources/ test/org/apache/axis2/saaj2/

Modified: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/src/org/apache/axis2/saaj2/TextImplEx.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/src/org/apache/axis2/saaj2/TextImplEx.java?rev=358784&r1=358783&r2=358784&view=diff
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/src/org/apache/axis2/saaj2/TextImplEx.java (original)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/src/org/apache/axis2/saaj2/TextImplEx.java Fri Dec 23 01:40:17 2005
@@ -15,130 +15,264 @@
  */
 package org.apache.axis2.saaj2;
 
-import javax.xml.soap.Text;
-import javax.xml.stream.XMLStreamException;
-
 import org.apache.axis2.om.OMContainer;
 import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.DOOMAbstractFactory;
 import org.apache.axis2.om.impl.OMOutputImpl;
 import org.apache.axis2.om.impl.dom.TextImpl;
+import org.apache.axis2.om.impl.dom.factory.OMDOMFactory;
 import org.w3c.dom.DOMException;
 
+import javax.xml.soap.Text;
+import javax.xml.stream.XMLStreamException;
+
 public class TextImplEx extends NodeImplEx implements Text {
 
-	TextImpl textNode;
-	
-	/* (non-Javadoc)
-	 * @see javax.xml.soap.Text#isComment()
-	 */
-	public boolean isComment() {
-		String value = this.textNode.getText();
-		return value.startsWith("<!--") && value.endsWith("-->");
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.Node#getNodeName()
-	 */
-	public String getNodeName() {
-		return this.textNode.getNodeName();
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.Node#getNodeType()
-	 */
-	public short getNodeType() {
-		return this.textNode.getNodeType();
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.Text#splitText(int)
-	 */
-	public org.w3c.dom.Text splitText(int offset) throws DOMException {
-		return this.textNode.splitText(offset);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.CharacterData#getData()
-	 */
-	public String getData() throws DOMException {
-		return this.textNode.getData();
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.CharacterData#setData(java.lang.String)
-	 */
-	public void setData(String data) throws DOMException {
-		this.textNode.setData(data);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.CharacterData#substringData(int, int)
-	 */
-	public String substringData(int offset, int count) throws DOMException {
-		return this.textNode.substringData(offset, count);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.CharacterData#appendData(java.lang.String)
-	 */
-	public void appendData(String value) throws DOMException {
-		this.textNode.appendData(value);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.CharacterData#insertData(int, java.lang.String)
-	 */
-	public void insertData(int offset, String data) throws DOMException {
-		this.textNode.insertData(offset, data);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.CharacterData#deleteData(int, int)
-	 */
-	public void deleteData(int offset, int count) throws DOMException {
-		this.textNode.deleteData(offset, count);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.CharacterData#replaceData(int, int, java.lang.String)
-	 */
-	public void replaceData(int offset, int count, String data) throws DOMException {
-		this.textNode.replaceData(offset, count, data);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.impl.OMNodeEx#setParent(org.apache.axis2.om.OMContainer)
-	 */
-	public void setParent(OMContainer element) {
-		this.textNode.setParent(element);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMNode#getParent()
-	 */
-	public OMContainer getParent() {
-		return this.textNode.getParent();
-	}
-
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMNode#discard()
-	 */
-	public void discard() throws OMException {
-		this.textNode.discard();
-	}
-
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMNode#serialize(org.apache.axis2.om.impl.OMOutputImpl)
-	 */
-	public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
-		this.textNode.serialize(omOutput);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMNode#serializeAndConsume(org.apache.axis2.om.impl.OMOutputImpl)
-	 */
-	public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {
-		this.textNode.serializeAndConsume(omOutput);
-	}
+    //TODO: assign textNode
+
+    private TextImpl textNode;
 
+    public TextImplEx(String data) {
+        textNode = (TextImpl) DOOMAbstractFactory.getOMFactory().createText(data);
+    }
+    /*public TextImplEx(SOAPElementImpl parent, String s) throws SOAPException {
+        //super();
+        //super.setParentElement(parent);
+        OMElement par = parent.getOMElement();
+        omNode =
+        omText =
+                org.apache.axis2.om.OMAbstractFactory.getOMFactory()
+                        .createText(par, s);
+    }
+
+    public TextImplEx(org.w3c.dom.CharacterData data) {
+        if (data == null) {
+            throw new IllegalArgumentException("Text value may not be null.");
+        }
+        omText =
+                org.apache.axis2.om.OMAbstractFactory.getOMFactory()
+                        .createText(data.getData());
+    }
+
+    public TextImplEx(OMText omText) {
+        omNode = this.omText = omText;
+    }*/
+
+    /**
+     * Retrieves whether this <CODE>Text</CODE> object
+     * represents a comment.
+     *
+     * @return <CODE>true</CODE> if this <CODE>Text</CODE> object is
+     *         a comment; <CODE>false</CODE> otherwise
+     */
+    public boolean isComment() {
+        String value = textNode.getText();
+        return value.startsWith("<!--") && value.endsWith("-->");
+    }
+
+    /**
+     * The name of this node, depending on its type; see the table above.
+     */
+    public String getNodeName() {
+        return textNode.getNodeName();
+    }
+
+    /**
+     * A code representing the type of the underlying object, as defined above.
+     */
+    public short getNodeType() {
+        return textNode.getNodeType();
+    }
+
+    /**
+     * Breaks this node into two nodes at the specified <code>offset</code>,
+     * keeping both in the tree as siblings. After being split, this node
+     * will contain all the content up to the <code>offset</code> point. A
+     * new node of the same type, which contains all the content at and
+     * after the <code>offset</code> point, is returned. If the original
+     * node had a parent node, the new node is inserted as the next sibling
+     * of the original node. When the <code>offset</code> is equal to the
+     * length of this node, the new node has no data.
+     *
+     * @param offset The 16-bit unit offset at which to split, starting from
+     *               <code>0</code>.
+     * @return The new node, of the same type as this node.
+     * @throws DOMException INDEX_SIZE_ERR: Raised if the specified offset is negative or greater
+     *                      than the number of 16-bit units in <code>data</code>.
+     *                      <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
+     */
+    public org.w3c.dom.Text splitText(int offset) throws DOMException {
+        return textNode.splitText(offset);
+    }
+
+    /**
+     * The character data of the node that implements this interface. The DOM
+     * implementation may not put arbitrary limits on the amount of data
+     * that may be stored in a <code>CharacterData</code> node. However,
+     * implementation limits may mean that the entirety of a node's data may
+     * not fit into a single <code>DOMString</code>. In such cases, the user
+     * may call <code>substringData</code> to retrieve the data in
+     * appropriately sized pieces.
+     *
+     * @throws DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
+     * @throws DOMException DOMSTRING_SIZE_ERR: Raised when it would return more characters than
+     *                      fit in a <code>DOMString</code> variable on the implementation
+     *                      platform.
+     */
+    public String getData() throws DOMException {
+        return textNode.getData();
+    }
+
+    /**
+     * The character data of the node that implements this interface. The DOM
+     * implementation may not put arbitrary limits on the amount of data
+     * that may be stored in a <code>CharacterData</code> node. However,
+     * implementation limits may mean that the entirety of a node's data may
+     * not fit into a single <code>DOMString</code>. In such cases, the user
+     * may call <code>substringData</code> to retrieve the data in
+     * appropriately sized pieces.
+     *
+     * @throws DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
+     * @throws DOMException DOMSTRING_SIZE_ERR: Raised when it would return more characters than
+     *                      fit in a <code>DOMString</code> variable on the implementation
+     *                      platform.
+     */
+    public void setData(String data) throws DOMException {
+        textNode.setData(data);
+    }
+
+    /**
+     * Extracts a range of data from the node.
+     *
+     * @param offset Start offset of substring to extract.
+     * @param count  The number of 16-bit units to extract.
+     * @return The specified substring. If the sum of <code>offset</code> and
+     *         <code>count</code> exceeds the <code>length</code>, then all 16-bit
+     *         units to the end of the data are returned.
+     * @throws DOMException INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
+     *                      negative or greater than the number of 16-bit units in
+     *                      <code>data</code>, or if the specified <code>count</code> is
+     *                      negative.
+     *                      <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
+     *                      not fit into a <code>DOMString</code>.
+     */
+    public String substringData(int offset, int count) throws DOMException {
+        return textNode.substringData(offset, count);
+    }
+
+    /**
+     * Append the string to the end of the character data of the node. Upon
+     * success, <code>data</code> provides access to the concatenation of
+     * <code>data</code> and the <code>DOMString</code> specified.
+     *
+     * @param value The <code>DOMString</code> to append.
+     * @throws DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
+     */
+    public void appendData(String value) throws DOMException {
+        textNode.appendData(value);
+    }
+
+    /**
+     * Insert a string at the specified 16-bit unit offset.
+     *
+     * @param offset The character offset at which to insert.
+     * @param data   The <code>DOMString</code> to insert.
+     * @throws DOMException INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
+     *                      negative or greater than the number of 16-bit units in
+     *                      <code>data</code>.
+     *                      <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
+     */
+    public void insertData(int offset, String data) throws DOMException {
+        textNode.insertData(offset, data);
+    }
+
+    /**
+     * Remove a range of 16-bit units from the node. Upon success,
+     * <code>data</code> and <code>length</code> reflect the change.
+     *
+     * @param offset The offset from which to start removing.
+     * @param count  The number of 16-bit units to delete. If the sum of
+     *               <code>offset</code> and <code>count</code> exceeds
+     *               <code>length</code> then all 16-bit units from <code>offset</code>
+     *               to the end of the data are deleted.
+     * @throws DOMException INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
+     *                      negative or greater than the number of 16-bit units in
+     *                      <code>data</code>, or if the specified <code>count</code> is
+     *                      negative.
+     *                      <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
+     */
+    public void deleteData(int offset, int count) throws DOMException {
+        textNode.deleteData(offset, count);
+    }
+
+    /**
+     * Replace the characters starting at the specified 16-bit unit offset
+     * with the specified string.
+     *
+     * @param offset The offset from which to start replacing.
+     * @param count  The number of 16-bit units to replace. If the sum of
+     *               <code>offset</code> and <code>count</code> exceeds
+     *               <code>length</code>, then all 16-bit units to the end of the data
+     *               are replaced; (i.e., the effect is the same as a <code>remove</code>
+     *               method call with the same range, followed by an <code>append</code>
+     *               method invocation).
+     * @param data   The <code>DOMString</code> with which the range must be
+     *               replaced.
+     * @throws DOMException INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
+     *                      negative or greater than the number of 16-bit units in
+     *                      <code>data</code>, or if the specified <code>count</code> is
+     *                      negative.
+     *                      <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
+     */
+    public void replaceData(int offset, int count, String data) throws DOMException {
+        textNode.replaceData(offset, count, data);
+    }
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.om.impl.OMNodeEx#setParent(org.apache.axis2.om.OMContainer)
+      */
+    public void setParent(OMContainer element) {
+        textNode.setParent(element);
+    }
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.om.OMNode#getParent()
+      */
+    public OMContainer getParent() {
+        return textNode.getParent();
+    }
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.om.OMNode#discard()
+      */
+    public void discard() throws OMException {
+        textNode.discard();
+    }
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.om.OMNode#serialize(org.apache.axis2.om.impl.OMOutputImpl)
+      */
+    public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
+        textNode.serialize(omOutput);
+    }
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.om.OMNode#serializeAndConsume(org.apache.axis2.om.impl.OMOutputImpl)
+      */
+    public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {
+        textNode.serializeAndConsume(omOutput);
+    }
+
+    /**
+     * Retrieve the text value (data) of this
+     *
+     * @return The text value (data) of this
+     */
+    public String getValue() {
+        return textNode.getData();
+    }
+
+    public String toString(){
+        return getValue();
+    }
 }

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test-resources/axis.jpg
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test-resources/axis.jpg?rev=358784&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test-resources/axis.jpg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/AttachmentSerializationTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/AttachmentSerializationTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/AttachmentSerializationTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/AttachmentSerializationTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,119 @@
+package org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.xml.soap.*;
+import javax.xml.soap.MimeHeaders;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.FileInputStream;
+import java.util.Iterator;
+
+import org.w3c.dom.Document;
+import org.apache.axis2.om.impl.dom.DocumentImpl;
+
+public class AttachmentSerializationTest extends TestCase {
+
+    public AttachmentSerializationTest(String name) {
+        super(name);
+    }
+
+    public static void main(String args[]) throws Exception {
+        AttachmentSerializationTest tester = new AttachmentSerializationTest("tester");
+        tester.testAttachments();
+    }
+
+    public void testAttachments() throws Exception {
+        try {
+            ByteArrayOutputStream bais = new ByteArrayOutputStream();
+            int count = saveMsgWithAttachments(bais);
+            assertEquals(count, 2);
+        } catch (Exception e) {
+//            throw new Exception("Fault returned from test: " + e);
+            e.printStackTrace();
+            fail("Unexpected Exception : " + e);
+        }
+    }
+
+    public static final String MIME_MULTIPART_RELATED = "multipart/related";
+    public static final String MIME_APPLICATION_DIME = "application/dime";
+    public static final String NS_PREFIX = "jaxmtst";
+    public static final String NS_URI = "http://www.jcommerce.net/soap/jaxm/TestJaxm";
+
+    public int saveMsgWithAttachments(OutputStream os) throws Exception {
+        MessageFactory mf = MessageFactory.newInstance();
+        SOAPMessage msg = mf.createMessage();
+
+        SOAPPart soapPart = msg.getSOAPPart();
+        SOAPEnvelope envelope = soapPart.getEnvelope();
+        SOAPHeader header = envelope.getHeader();
+        SOAPBody body = envelope.getBody();
+
+        SOAPElement el = header.addHeaderElement(envelope.createName("field4", NS_PREFIX, NS_URI));
+
+        SOAPElement el2 = el.addChildElement("field4b", NS_PREFIX);
+        SOAPElement el3 = el2.addTextNode("field4value");
+
+        el = body.addBodyElement(envelope.createName("bodyfield3", NS_PREFIX, NS_URI));
+        el2 = el.addChildElement("bodyfield3a", NS_PREFIX);
+        el2.addTextNode("bodyvalue3a");
+        el2 = el.addChildElement("bodyfield3b", NS_PREFIX);
+        el2.addTextNode("bodyvalue3b");
+        el2 = el.addChildElement("datefield", NS_PREFIX);
+
+        // First Attachment
+        AttachmentPart ap = msg.createAttachmentPart();
+        final String testText = "some attachment text...";
+        ap.setContent(testText, "text/plain");
+        msg.addAttachmentPart(ap);
+
+        // Second attachment
+        String jpgfilename = "./test-resources/axis.jpg";
+        File myfile = new File(jpgfilename);
+        FileDataSource fds = new FileDataSource(myfile);
+        DataHandler dh = new DataHandler(fds);
+        AttachmentPart ap2 = msg.createAttachmentPart(dh);
+        ap2.setContentType("image/jpg");
+        msg.addAttachmentPart(ap2);
+
+        MimeHeaders headers = msg.getMimeHeaders();
+        assertTrue(headers != null);
+        String [] contentType = headers.getHeader("Content-Type");
+        assertTrue(contentType != null);
+
+        for (Iterator iter = msg.getAttachments(); iter.hasNext();) {
+            AttachmentPart attachmentPart =  (AttachmentPart) iter.next();
+            final Object content = attachmentPart.getDataHandler().getContent();
+            if(content instanceof String){
+                assertEquals(testText, (String) content);
+            } else if(content instanceof FileInputStream){
+                final FileInputStream fis = (FileInputStream) content;
+                /*File file = new File("output-file.jpg");
+                file.createNewFile();
+
+                fis.read(new byte[(int)file.length()])*/
+            }
+        }
+
+        msg.writeTo(os);
+        os.flush();
+        msg.writeTo(System.out);
+        return msg.countAttachments();
+    }
+
+    public int loadMsgWithAttachments(InputStream is) throws Exception {
+        MimeHeaders headers = new MimeHeaders();
+        headers.setHeader("Content-Type", MIME_MULTIPART_RELATED);
+        MessageFactory mf = MessageFactory.newInstance();
+        SOAPMessage msg = mf.createMessage(headers, is);
+        SOAPPart sp = msg.getSOAPPart();
+        SOAPEnvelope envelope = sp.getEnvelope();
+        assertTrue(sp != null);
+        assertTrue(envelope != null);
+        return msg.countAttachments();
+    }
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/AttachmentTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/AttachmentTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/AttachmentTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/AttachmentTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,128 @@
+package org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPConnection;
+import javax.xml.soap.SOAPConnectionFactory;
+import javax.xml.soap.SOAPMessage;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class AttachmentTest extends TestCase {
+
+    public AttachmentTest(String name) {
+        super(name);
+    }
+    
+    public void testStringAttachment() throws Exception {
+    	SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
+    	SOAPConnection con = scFactory.createConnection();
+    	
+    	MessageFactory factory = MessageFactory.newInstance();
+    	SOAPMessage message = factory.createMessage();
+    	AttachmentPart attachment = message.createAttachmentPart();
+    	String stringContent = "Update address for Sunny Skies " +
+    			"Inc., to 10 Upbeat Street, Pleasant Grove, CA 95439";
+    	
+    	attachment.setContent(stringContent, "text/plain");
+    	attachment.setContentId("update_address");
+    	message.addAttachmentPart(attachment);
+    	
+    	assertTrue(message.countAttachments()==1);
+    	
+    	java.util.Iterator it = message.getAttachments();
+    	while (it.hasNext()) {
+    		attachment = (AttachmentPart) it.next();
+    		Object content = attachment.getContent();
+    		String id = attachment.getContentId();
+    		System.out.println("Attachment " + id + " contains: " + content);
+    		assertEquals(content,stringContent);
+    	}
+    	System.out.println("Here is what the XML message looks like:");
+    	message.writeTo(System.out);
+    	
+    	message.removeAllAttachments();
+    	assertTrue(message.countAttachments()==0);
+    }
+    
+    public void testMultipleAttachments() throws Exception {
+        SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
+        SOAPConnection con = scFactory.createConnection();
+
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage msg = factory.createMessage();
+        java.net.URL url1 = new java.net.URL("http://slashdot.org/slashdot.xml");
+        java.net.URL url2 = new java.net.URL("http://www.apache.org/LICENSE.txt");
+
+        AttachmentPart a1 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
+        a1.setContentType("text/xml");
+        msg.addAttachmentPart(a1);
+        AttachmentPart a2 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
+        a2.setContentType("text/xml");
+        msg.addAttachmentPart(a2);
+        AttachmentPart a3 = msg.createAttachmentPart(new javax.activation.DataHandler(url2));
+        a3.setContentType("text/plain");
+        msg.addAttachmentPart(a3);
+
+        assertTrue(msg.countAttachments()==3);
+
+        javax.xml.soap.MimeHeaders mimeHeaders = new javax.xml.soap.MimeHeaders();
+        mimeHeaders.addHeader("Content-Type", "text/xml");
+
+        int nAttachments = 0;
+        java.util.Iterator iterator = msg.getAttachments(mimeHeaders);
+	    while (iterator.hasNext()) {
+            nAttachments++;
+	        AttachmentPart ap = (AttachmentPart)iterator.next();
+	        assertTrue(ap.equals(a1) || ap.equals(a2));
+	    }
+        assertTrue(nAttachments==2);
+    }
+    
+    public void testBadAttSize() throws Exception {
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage message = factory.createMessage();
+
+        ByteArrayInputStream ins=new ByteArrayInputStream(new byte[5]);
+        DataHandler dh=new DataHandler(new Src(ins,"text/plain"));
+        AttachmentPart part = message.createAttachmentPart(dh);
+        assertEquals("Size should match",5,part.getSize());
+    }
+
+    class Src implements DataSource{
+        InputStream m_src;
+        String m_type;
+
+        public Src(InputStream data, String type){
+            m_src=data;
+            m_type=type;
+        }
+        public String getContentType(){
+            return m_type;
+        }
+        public InputStream getInputStream() throws IOException{
+            m_src.reset();
+            return m_src;
+        }
+        public String getName(){
+            return "Some-Data";
+        }
+        public OutputStream getOutputStream(){
+            throw new UnsupportedOperationException("I don't give output streams");
+        }
+    }
+    
+    public static void main(String[] args) throws Exception {
+        AttachmentTest tester = new AttachmentTest("TestSAAJ");
+        tester.testMultipleAttachments();
+        tester.testStringAttachment();
+        tester.testBadAttSize();
+    }
+
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/EnvelopeTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/EnvelopeTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/EnvelopeTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/EnvelopeTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,441 @@
+package org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.Name;
+import javax.xml.soap.Node;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.soap.Text;
+import javax.xml.soap.SOAPConnectionFactory;
+import javax.xml.soap.SOAPConnection;
+import java.io.ByteArrayInputStream;
+import java.util.Iterator;
+
+public class EnvelopeTest extends TestCase {
+
+    private static final String XML_STRING =
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+            "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
+            "                   xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
+            "                   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
+            " <soapenv:Header>\n" +
+            "  <shw:Hello xmlns:shw=\"http://www.jcommerce.net/soap/ns/SOAPHelloWorld\">\n" +
+            "    <shw:Myname>Tony</shw:Myname>\n" +
+            "  </shw:Hello>\n" +
+            " </soapenv:Header>\n" +
+            " <soapenv:Body>\n" +
+            "  <shw:Address shw:t='test' xmlns:shw=\"http://www.jcommerce.net/soap/ns/SOAPHelloWorld\">\n" +
+            "    <shw:City>GENT</shw:City>\n" +
+            "  </shw:Address>\n" +
+            " </soapenv:Body>\n" +
+            "</soapenv:Envelope>";
+
+    public EnvelopeTest(String name) {
+        super(name);
+    }
+
+    public void testEnvelope() throws Exception {
+        MessageFactory mf = MessageFactory.newInstance();
+        SOAPMessage smsg =
+                mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(XML_STRING.getBytes()));
+        SOAPPart sp = smsg.getSOAPPart();
+        SOAPEnvelope se = sp.getEnvelope();
+        smsg.writeTo(System.out);
+        assertTrue(se != null);
+    }
+
+    public void testEnvelope2() throws Exception {
+        MessageFactory mf = MessageFactory.newInstance();
+        final ByteArrayInputStream baIS = new ByteArrayInputStream(XML_STRING.getBytes());
+        final MimeHeaders mimeheaders = new MimeHeaders();
+        mimeheaders.addHeader("Content-Type", "multipart/related");
+        SOAPMessage smsg =
+                mf.createMessage(mimeheaders, baIS);
+
+        smsg.writeTo(System.out);
+
+        SOAPEnvelope envelope = smsg.getSOAPPart().getEnvelope();
+        SOAPBody body = envelope.getBody();
+        assertTrue(body != null);
+    }
+
+    // TODO: This test fails due to some issues in OM. Needs to be added to the test suite
+    //   that issue is fixed
+    public void _testEnvelopeWithLeadingComment() throws Exception {
+        String soapMessageWithLeadingComment =
+                "<?xml version='1.0' encoding='UTF-8'?>" +
+                "<!-- Comment -->" +
+                "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
+                "<env:Body><echo><arg0>Hello</arg0></echo></env:Body>" +
+                "</env:Envelope>";
+
+        SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
+        SOAPConnection con = scFactory.createConnection();
+
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage message =
+                factory.createMessage(new MimeHeaders(),
+                                      new ByteArrayInputStream(soapMessageWithLeadingComment.getBytes()));
+        SOAPPart part = message.getSOAPPart();
+        SOAPEnvelope envelope = part.getEnvelope();
+        message.writeTo(System.out);
+        assertTrue(envelope != null);
+        assertTrue(envelope.getBody() != null);
+    }
+
+    public void testEnvelopeWithCommentInEnvelope() throws Exception {
+
+        String soapMessageWithLeadingComment =
+                "<?xml version='1.0' encoding='UTF-8'?>\n" +
+                "<soapenv:Envelope  xmlns='http://somewhere.com/html'\n" +
+                "                   xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'\n" +
+                "                   xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
+                "                   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" +
+                "<!-- Comment -->" +
+                " <soapenv:Body>\n" +
+                "    <echo><arg0>Hello</arg0></echo>" +
+//                "    <t:echo xmlns:t='http://test.org/Test'><t:arg0>Hello</t:arg0></t:echo>" +
+" </soapenv:Body>\n" +
+"</soapenv:Envelope>";
+
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage message =
+                factory.createMessage(new MimeHeaders(),
+                                      new ByteArrayInputStream(soapMessageWithLeadingComment.getBytes()));
+        SOAPPart part = message.getSOAPPart();
+        SOAPEnvelope envelope = part.getEnvelope();
+        message.writeTo(System.out);
+        assertTrue(envelope != null);
+        assertTrue(envelope.getBody() != null);
+    }
+
+    public void testEnvelopeWithCommentInBody() throws Exception {
+
+        String soapMessageWithLeadingComment =
+                "<?xml version='1.0' encoding='UTF-8'?>\n" +
+                "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'\n" +
+                "                   xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
+                "                   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" +
+                " <soapenv:Body>\n" +
+                "<!-- Comment -->" +
+//                "    <echo><arg0>Hello</arg0></echo>" +
+"    <t:echo xmlns:t='http://test.org/Test'><t:arg0>Hello</t:arg0></t:echo>" +
+" </soapenv:Body>\n" +
+"</soapenv:Envelope>";
+
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage message =
+                factory.createMessage(new MimeHeaders(),
+                                      new ByteArrayInputStream(soapMessageWithLeadingComment.getBytes()));
+        SOAPPart part = message.getSOAPPart();
+        SOAPEnvelope envelope = part.getEnvelope();
+        message.writeTo(System.out);
+        assertTrue(envelope != null);
+        assertTrue(envelope.getBody() != null);
+    }
+
+    public void testEnvelopeWithComments() throws Exception {
+
+        String soapMessageWithLeadingComment =
+                "<?xml version='1.0' encoding='UTF-8'?>\n" +
+                "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'\n" +
+                "                   xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
+                "                   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" +
+                " <soapenv:Header>\n" +
+                "<!-- Comment -->" +
+                "  <shw:Hello xmlns:shw=\"http://www.jcommerce.net/soap/ns/SOAPHelloWorld\">\n" +
+                "<!-- Comment -->" +
+                "    <shw:Myname><!-- Comment -->Tony</shw:Myname>\n" +
+                "  </shw:Hello>\n" +
+                " </soapenv:Header>\n" +
+                " <soapenv:Body>\n" +
+                "<!-- Comment -->" +
+                "    <t:echo xmlns:t='http://test.org/Test'><t:arg0>Hello</t:arg0></t:echo>" +
+                " </soapenv:Body>\n" +
+                "</soapenv:Envelope>";
+
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage message =
+                factory.createMessage(new MimeHeaders(),
+                                      new ByteArrayInputStream(soapMessageWithLeadingComment.getBytes()));
+        SOAPPart part = message.getSOAPPart();
+        SOAPEnvelope envelope = part.getEnvelope();
+        message.writeTo(System.out);
+        assertTrue(envelope != null);
+        assertTrue(envelope.getBody() != null);
+    }
+
+    //TODO: Fails. Check this. Faults need more thorough testing
+    public void testFaults() throws Exception {
+        SOAPEnvelope envelope = getSOAPEnvelope();
+        SOAPBody body = envelope.getBody();
+
+        assertFalse(body.hasFault());
+        SOAPFault soapFault = body.addFault();
+        assertTrue(body.hasFault());
+        assertNotNull(body.getFault());
+
+        soapFault.setFaultString("myFault");
+        String faultString = soapFault.getFaultString();
+        System.err.println("######## faultString=" + faultString);
+
+//        soapFault.setFaultCode("CODE");
+//        soapFault.getFaultCode();
+//        System.err.println("######## faultCode=" + soapFault.getFaultCode());
+
+//        assertEquals()
+
+        //soapFault.setFaultCode("myFault");
+        //String fc = soapFault.getFaultCode();
+        /*soapFault.setFaultString("myFault");
+        String fc = soapFault.getFaultString(); //Chk the same for FaultCode as well
+
+        // currently not done in SAAJ
+        assertTrue(fc.equals("myFault"));*/
+    }
+    /*
+   public void testFaults2() throws Exception {
+
+       SOAPEnvelope envelope = getSOAPEnvelope();
+       SOAPBody body = envelope.getBody();
+       SOAPFault sf = body.addFault();
+
+       assertTrue(body.getFault() != null);
+
+       Detail d1 = sf.addDetail();
+       Name name = envelope.createName("GetLastTradePrice", "WOMBAT",
+                                       "http://www.wombat.org/trader");
+       d1.addDetailEntry(name);
+
+       Detail d2 = sf.getDetail();
+       assertTrue(d2 != null);
+       Iterator i = d2.getDetailEntries();
+       assertTrue(getIteratorCount(i) == 1);
+       i = d2.getDetailEntries();
+       //message.writeTo(System.out);
+       while (i.hasNext()) {
+           DetailEntry de = (DetailEntry) i.next();
+           assertEquals(de.getElementName(), name);
+       }
+   }*/
+
+    public void testHeaderElements() throws Exception {
+        SOAPEnvelope envelope = getSOAPEnvelope();
+        SOAPHeader header = envelope.getHeader();
+
+        SOAPHeaderElement headerEle = header.addHeaderElement(envelope.createName("foo1",
+                                                                                  "f1",
+                                                                                  "foo1-URI"));
+        headerEle.setActor("actor-URI");
+        headerEle.setMustUnderstand(true);
+
+        Iterator iterator = header.extractHeaderElements("actor-URI");
+        int cnt = 0;
+        while (iterator.hasNext()) {
+            cnt++;
+            SOAPHeaderElement resultHeaderEle = (SOAPHeaderElement) iterator.next();
+
+            assertEquals(headerEle.getActor(), resultHeaderEle.getActor());
+            assertEquals(resultHeaderEle.getMustUnderstand(),headerEle.getMustUnderstand());
+        }
+        assertTrue(cnt == 1);
+        iterator = header.extractHeaderElements("actor-URI");
+        assertTrue(!iterator.hasNext());
+    }
+
+    public void testText() throws Exception {
+        SOAPEnvelope envelope = getSOAPEnvelope();
+        SOAPBody body = envelope.getBody();
+        Iterator iStart = body.getChildElements();
+        int countStart = getIteratorCount(iStart);
+
+        final String bodyText = "<txt>This is the body text</txt>";
+
+        SOAPElement se = body.addTextNode(bodyText);
+        assertTrue(se != null);
+
+        assertTrue(body.getValue().equals(bodyText));
+
+        Iterator i = body.getChildElements();
+        int count = getIteratorCount(i);
+        assertTrue(count == countStart + 1);
+    }
+
+    public void testNonCommentText() throws Exception {
+        SOAPEnvelope envelope = getSOAPEnvelope();
+        SOAPBody body = envelope.getBody();
+        SOAPElement se = body.addTextNode("<txt>This is text</txt>");
+        Iterator iterator = se.getChildElements();
+        Object o = null;
+        while (iterator.hasNext()) {
+            o = iterator.next();
+            if (o instanceof Text) {
+                break;
+            }
+        }
+        assertTrue(o instanceof Text);
+        Text t = (Text) o;
+        assertTrue(!t.isComment());
+    }
+
+    public void testCommentText() throws Exception {
+        SOAPEnvelope envelope = getSOAPEnvelope();
+        SOAPBody body = envelope.getBody();
+        SOAPElement se = body.addTextNode("<!-- This is a comment -->");
+        Iterator iterator = se.getChildElements();
+        Node n = null;
+        while (iterator.hasNext()) {
+            n = (Node) iterator.next();
+            if (n instanceof Text)
+                break;
+        }
+        assertTrue(n instanceof Text);
+        Text t = (Text) n;
+        assertTrue(t.isComment());
+    }
+
+    public void testAttributes() throws Exception {
+        SOAPEnvelope envelope = getSOAPEnvelope();
+        SOAPBody body = envelope.getBody();
+
+        Name name1 = envelope.createName("MyAttr1");
+        String value1 = "MyValue1";
+
+        Name name2 = envelope.createName("MyAttr2");
+        String value2 = "MyValue2";
+
+        Name name3 = envelope.createName("MyAttr3");
+        String value3 = "MyValue3";
+
+        body.addAttribute(name1, value1);
+        body.addAttribute(name2, value2);
+        body.addAttribute(name3, value3);
+
+        Iterator iterator = body.getAllAttributes();
+        assertTrue(getIteratorCount(iterator) == 3);
+        iterator = body.getAllAttributes();
+
+        boolean foundName1 = false;
+        boolean foundName2 = false;
+        boolean foundName3 = false;
+        while (iterator.hasNext()) {
+            Name name = (Name) iterator.next();
+            if (name.equals(name1)) {
+                foundName1 = true;
+                assertEquals(value1, body.getAttributeValue(name));
+            } else if (name.equals(name2)) {
+                foundName2 = true;
+                assertEquals(value2, body.getAttributeValue(name));
+            } else if (name.equals(name3)) {
+                foundName3 = true;
+                assertEquals(value3, body.getAttributeValue(name));
+            }
+        }
+        assertTrue(foundName1 && foundName2 && foundName3);
+    }
+
+    public void testAttributes2() throws Exception {
+        SOAPEnvelope envelope = getSOAPEnvelope();
+        SOAPBody body = envelope.getBody();
+
+        Name name1 = envelope.createName("MyAttr1", "att", "http://test.com/Attr");
+        String value1 = "MyValue1";
+
+        Name name2 = envelope.createName("MyAttr2");
+        String value2 = "MyValue2";
+
+        Name name3 = envelope.createName("MyAttr3");
+        String value3 = "MyValue3";
+
+        body.addAttribute(name1, value1);
+        body.addAttribute(name2, value2);
+        body.addAttribute(name3, value3);
+
+        Iterator iterator = body.getAllAttributes();
+        assertTrue(getIteratorCount(iterator) == 3);
+        iterator = body.getAllAttributes();
+
+        boolean foundName1 = false;
+        boolean foundName2 = false;
+        boolean foundName3 = false;
+        while (iterator.hasNext()) {
+            Name name = (Name) iterator.next();
+            if (name.equals(name1)) {
+                foundName1 = true;
+                assertEquals(value1, body.getAttributeValue(name));
+            } else if (name.equals(name2)) {
+                foundName2 = true;
+                assertEquals(value2, body.getAttributeValue(name));
+            } else if (name.equals(name3)) {
+                foundName3 = true;
+                assertEquals(value3, body.getAttributeValue(name));
+            }
+        }
+        assertTrue(foundName1 && foundName2 && foundName3);
+    }
+
+    public void testAttributes3() throws Exception {
+        SOAPEnvelope envelope = getSOAPEnvelope();
+        SOAPBody body = envelope.getBody();
+
+        Name name1 = envelope.createName("MyAttr1", "att", "http://test.com/Attr");
+        String value1 = "MyValue1";
+
+        Name name2 = envelope.createName("MyAttr2", "att", "http://test.com/Attr");
+        String value2 = "MyValue2";
+
+        Name name3 = envelope.createName("MyAttr3", "att", "http://test.com/Attr");
+        String value3 = "MyValue3";
+
+        body.addAttribute(name1, value1);
+        body.addAttribute(name2, value2);
+        body.addAttribute(name3, value3);
+
+        Iterator iterator = body.getAllAttributes();
+        assertTrue(getIteratorCount(iterator) == 3);
+        iterator = body.getAllAttributes();
+
+        boolean foundName1 = false;
+        boolean foundName2 = false;
+        boolean foundName3 = false;
+        while (iterator.hasNext()) {
+            Name name = (Name) iterator.next();
+            if (name.equals(name1)) {
+                foundName1 = true;
+                assertEquals(value1, body.getAttributeValue(name));
+            } else if (name.equals(name2)) {
+                foundName2 = true;
+                assertEquals(value2, body.getAttributeValue(name));
+            } else if (name.equals(name3)) {
+                foundName3 = true;
+                assertEquals(value3, body.getAttributeValue(name));
+            }
+        }
+        assertTrue(foundName1 && foundName2 && foundName3);
+    }
+
+    private SOAPEnvelope getSOAPEnvelope() throws Exception {
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage message = factory.createMessage();
+        return message.getSOAPPart().getEnvelope();
+    }
+
+    private int getIteratorCount(java.util.Iterator i) {
+        int count = 0;
+        while (i.hasNext()) {
+            count++;
+            i.next();
+        }
+        return count;
+    }
+
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/HeadersTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/HeadersTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/HeadersTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/HeadersTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004,2005 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 org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.xml.soap.SOAPElement;
+import java.util.Iterator;
+
+public class HeadersTest extends TestCase {
+
+    private final String actor = "ACTOR#1";
+    private final String localName = "Local1";
+    private final String namespace = "http://ws.apache.org";
+    private final String prefix = "P1";
+
+    public HeadersTest(String name) {
+        super(name);
+    }
+
+    public void testAddingHeaderElements() throws Exception {
+        javax.xml.soap.SOAPMessage soapMessage =
+                javax.xml.soap.MessageFactory.newInstance().createMessage();
+        javax.xml.soap.SOAPEnvelope soapEnv =
+                soapMessage.getSOAPPart().getEnvelope();
+        javax.xml.soap.SOAPHeader header = soapEnv.getHeader();
+        header.addChildElement("ebxmlms");
+
+        /*ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      soapMessage.writeTo(baos);
+      String xml = new String(baos.toByteArray());
+      assertTrue(xml.indexOf("ebxmlms") != -1);*/
+
+        Iterator it = header.getChildElements();
+        boolean b = false;
+        while (it.hasNext()) {
+            SOAPElement el = (SOAPElement) it.next();
+            String lName = el.getNodeName();
+            if (lName.equalsIgnoreCase("ebxmlms")) {
+                b = true;
+                break;
+            }
+        }
+        assertTrue(b);
+    }
+
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/JUnitTestAttachmentIntegration.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/JUnitTestAttachmentIntegration.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/JUnitTestAttachmentIntegration.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/JUnitTestAttachmentIntegration.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,85 @@
+package org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.xml.soap.*;
+import java.io.File;
+import java.util.Iterator;
+//import javax.activation.FileDataSource;
+
+public class JUnitTestAttachmentIntegration extends TestCase {
+	
+    public JUnitTestAttachmentIntegration(String name) {
+        super(name);
+    }
+    
+    public static void main(String args[]) throws Exception {
+    	JUnitTestAttachmentIntegration tester = new JUnitTestAttachmentIntegration("tester");
+        testSendReceive();
+    }
+
+	public static void testSendReceive() throws Exception{
+		MessageFactory mf = MessageFactory.newInstance();
+		SOAPMessage message = mf.createMessage();
+		
+		//create the SOAPPart
+		createSOAPPart(message);
+		
+		//Attach a text/plain object with the SOAP message
+		String sampleMessage = "Sample Message: Hello World!";
+		AttachmentPart textAttach = message.createAttachmentPart(sampleMessage,"text/plain");
+		textAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
+		textAttach.setContentId("submitSampleText@apache.org");
+		message.addAttachmentPart(textAttach);
+		
+		//Attach a java.awt.Image object to the SOAP message
+        String jpgfilename = "./test-resources/axis.jpg";
+        File myfile = new File(jpgfilename);
+        FileDataSource fds = new FileDataSource(myfile);
+		DataHandler imageDH = new DataHandler(fds);
+		AttachmentPart jpegAttach = message.createAttachmentPart(imageDH);
+		jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
+		jpegAttach.setContentId("submitSampleImage@apache.org");
+		message.addAttachmentPart(jpegAttach);
+		
+		SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
+		
+		SOAPMessage sMsg =  sCon.call(message,"http://localhost:8080/axis2/services/Echo");
+		int attachmentCount = sMsg.countAttachments();
+		assertTrue(attachmentCount == 2);
+
+		Iterator attachIter = sMsg.getAttachments();		
+		//Of the two attachments first should be of type text/plain and 
+		//second of content-type image/jpeg
+		
+		//Underlying MTOM is converting all contentTypes to application/octet-stream
+		//Thats something to be fixed, I guess. Till then commenting out
+		//these two asserts
+		/*
+		AttachmentPart ap1 = (AttachmentPart)attachIter.next();
+		assertTrue(ap1.getContentType().equals("text/plain"));
+		AttachmentPart ap2 = (AttachmentPart)attachIter.next();
+		assertTrue(ap2.getContentType().equals("image/jpeg"));
+		*/
+	}
+	
+	private static void createSOAPPart(SOAPMessage message) throws SOAPException {
+		SOAPPart sPart = message.getSOAPPart();
+		SOAPEnvelope env = sPart.getEnvelope();
+		SOAPBody body = env.getBody();
+		
+		Name ns = env.createName("echo","swa","http://fakeNamespace.org");
+		SOAPBodyElement sbe = body.addBodyElement(ns);
+		
+		Name ns2 = env.createName("text");
+		SOAPElement textReference = sbe.addChildElement(ns2);
+		Name hrefAttr = env.createName("href");
+		textReference.addAttribute(hrefAttr, "cid:submitSampleText@apache.org");
+		
+		Name ns3 = env.createName("image");
+		SOAPElement imageReference = sbe.addChildElement(ns3);
+		imageReference.addAttribute(hrefAttr, "cid:submitSampleImage@apache.org");
+	}
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/PrefixesTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/PrefixesTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/PrefixesTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/PrefixesTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2004,2005 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 org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.soap.MimeHeaders;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+
+public class PrefixesTest extends TestCase {
+
+    public PrefixesTest(String name) {
+        super(name);
+    }
+
+    public void testAddingPrefixesForChildElements() throws Exception {
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage msg = factory.createMessage();
+        SOAPPart sp = msg.getSOAPPart();
+        SOAPEnvelope se = sp.getEnvelope();
+        SOAPBody sb = se.getBody();
+        SOAPElement el1 = sb.addBodyElement(
+                se.createName
+                ("element1", "prefix1", "http://www.sun.com"));
+        SOAPElement el2 = el1.addChildElement(
+                se.createName
+                ("element2", "prefix2", "http://www.apache.org"));
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        msg.writeTo(baos);
+
+        String xml = new String(baos.toByteArray());
+        assertTrue(xml.indexOf("prefix1") != -1);
+        assertTrue(xml.indexOf("prefix2") != -1);
+        assertTrue(xml.indexOf("http://www.sun.com") != -1);
+        assertTrue(xml.indexOf("http://www.apache.org") != -1);
+    }
+
+     public void testAttribute() throws Exception {
+      /*  String soappacket = "<SOAP-ENV:Envelope xmlns:SOAP-ENV =\"http://schemas.xmlsoap.org/soap/envelope/\"" +
+                            "xmlns:xsi =\"http://www.w3.org/1999/XMLSchema-instance\"" +
+                            "xmlns:xsd =\"http://www.w3.org/1999/XMLSchema\">" +
+                            "<SOAP-ENV:Body>" +
+//                            "<t:helloworld t:name=\"tester\" xmlns:t='http://test.org/Test' />" +
+                            "</SOAP-ENV:Body>" +
+                            "</SOAP-ENV:Envelope>";*/
+//         System.err.println(soappacket);
+
+         final String soappacket =
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+            "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
+            "                   xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
+            "                   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
+            " <soapenv:Header>\n" +
+            "  <shw:Hello xmlns:shw=\"http://www.jcommerce.net/soap/ns/SOAPHelloWorld\">\n" +
+            "    <shw:Myname>Tony</shw:Myname>\n" +
+            "  </shw:Hello>\n" +
+            " </soapenv:Header>\n" +
+            " <soapenv:Body>\n" +
+            "  <shw:Address xmlns:shw=\"http://www.jcommerce.net/soap/ns/SOAPHelloWorld\" shw:t='test' >\n" +
+            "    <shw:City>GENT</shw:City>\n" +
+            "  </shw:Address>\n" +
+            " </soapenv:Body>\n" +
+            "</soapenv:Envelope>";
+
+        SOAPMessage msg = MessageFactory.newInstance().createMessage(new MimeHeaders(),
+                                                                     new ByteArrayInputStream(soappacket.getBytes()));
+        SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
+        msg.writeTo(System.out);
+
+        SOAPElement ele = (SOAPElement) body.getChildElements().next();
+        java.util.Iterator attit = ele.getAllAttributes();
+
+        System.out.println(attit.next().getClass());
+
+        javax.xml.soap.Name n = (javax.xml.soap.Name) attit.next();
+        //assertEquals("Test fail prefix problem",n.getQualifiedName(),"name");
+    }
+
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/Readme.txt
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/Readme.txt?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/Readme.txt (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/Readme.txt Fri Dec 23 01:40:17 2005
@@ -0,0 +1,16 @@
+The testcase JUnitTestAttachmentsIntegration.java is a round trip 
+integration test written to put to test the attachment support added 
+to SAAJ module. However this test can't be run as part of maven b'coz
+of following pre-requisites
+A web service to echo back attachments is expected to be up and running
+at "http://localhost:8080/axis2/services/Echo" with operation name as
+"echo". We don't want the maven to break because of this dependency.
+The name of the test case is hence modified not to match *Test.java pattern,
+so that maven wouldn't run it.
+
+However, for those who want to test this round trip test of attachments
+support, we are providing the Echo.aar service in the test-resources
+folder. Hot deploy this service on a servlet container at 8080 port and
+manually run this test case.
+
+****
\ No newline at end of file

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPBodyTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPBodyTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPBodyTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPBodyTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2004,2005 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 org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import java.util.Iterator;
+
+import org.apache.axis2.saaj2.SOAPEnvelopeImpl;
+
+public class SOAPBodyTest extends TestCase {
+
+    /**
+     * Method suite
+     *                                                         
+     * @return
+     */
+    /*  public static Test suite() {
+          return new TestSuite(test.message.TestSOAPBody.class);
+      }
+    */
+
+    /**
+     * Constructor TestSOAPBody
+     *
+     * @param name
+     */
+    public SOAPBodyTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Method testSoapBodyBUG
+     *
+     * @throws Exception
+     */
+    public void testSoapBody() throws Exception {
+
+        MessageFactory fact = MessageFactory.newInstance();
+        SOAPMessage message = fact.createMessage();
+        SOAPPart soapPart = message.getSOAPPart();
+        SOAPEnvelopeImpl env = (SOAPEnvelopeImpl) soapPart.getEnvelope();
+        SOAPHeader header = env.getHeader();
+        Name hns = env.createName("Hello",
+                                  "shw",
+                                  "http://www.jcommerce.net/soap/ns/SOAPHelloWorld");
+        SOAPElement headElmnt = header.addHeaderElement(hns);
+        Name hns1 = env.createName("Myname",
+                                   "shw",
+                                   "http://www.jcommerce.net/soap/ns/SOAPHelloWorld");
+        SOAPElement myName = headElmnt.addChildElement(hns1);
+        myName.addTextNode("Tony");
+        Name ns = env.createName("Address",
+                                 "shw",
+                                 "http://www.jcommerce.net/soap/ns/SOAPHelloWorld");
+        SOAPBody body = env.getBody();
+        SOAPElement bodyElmnt = body.addBodyElement(ns);
+        Name ns1 = env.createName("City",
+                                  "shw",
+                                  "http://www.jcommerce.net/soap/ns/SOAPHelloWorld");
+        SOAPElement city = bodyElmnt.addChildElement(ns1);
+        city.addTextNode("GENT");
+
+        SOAPElement city2 = body.addBodyElement(ns1);
+        city2.addTextNode("CIT2");
+
+        Iterator it = body.getChildElements();
+        int count = 0;
+
+        while (it.hasNext()) {
+            SOAPElement el = (SOAPElement) it.next();
+            count++;
+//            Name name = el.getElementName();
+        }
+        assertEquals(2,count);
+    }
+
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPElementTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPElementTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPElementTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPElementTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004,2005 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 org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.xml.soap.SOAPElement;
+import java.util.List;
+
+import org.apache.axis2.saaj2.TextImplEx;
+import org.apache.axis2.om.impl.dom.NodeImpl;
+
+public class SOAPElementTest extends TestCase {
+
+    private SOAPElement soapElem;
+
+    protected void setUp() throws Exception {
+        soapElem =
+                SOAPFactoryImpl.newInstance().createElement("Test",
+                                                            "test",
+                                                            "http://test.apache.org/");
+    }
+
+    public void testAddTextNode() throws Exception {
+        assertNotNull(soapElem);
+        final String value = "foo";
+        soapElem.addTextNode(value);
+        assertEquals(value, soapElem.getValue());
+        TextImplEx text = assertContainsText(soapElem);
+        assertEquals(value, text.getValue());
+    }
+
+    private TextImplEx assertContainsText(SOAPElement soapElem) {
+        assertTrue(soapElem.hasChildNodes());
+        List childElems = toList(soapElem.getChildElements());
+        assertTrue(childElems.size() == 1);
+        NodeImpl node = (NodeImpl) childElems.get(0);
+        assertTrue(node instanceof TextImplEx);
+        return (TextImplEx) node;
+    }
+
+    private List toList(java.util.Iterator iter) {
+        List list = new java.util.ArrayList();
+        while (iter.hasNext()) {
+            list.add(iter.next());
+        }
+        return list;
+    }
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPFaultDetailTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPFaultDetailTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPFaultDetailTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPFaultDetailTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,71 @@
+package org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.xml.soap.DetailEntry;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPMessage;
+import java.io.ByteArrayInputStream;
+import java.util.Iterator;
+
+public class SOAPFaultDetailTest extends TestCase {
+	
+	public SOAPFaultDetailTest(String name){
+		super(name);
+	}
+	
+    String xmlString =
+    	"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+    	"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
+    	" <soapenv:Body>" +
+    	"  <soapenv:Fault>" +
+    	"   <faultcode>soapenv:Server.generalException</faultcode>" +
+    	"   <faultstring></faultstring>" +
+    	"   <detail>" +
+    	"    <tickerSymbol xsi:type=\"xsd:string\">MACR</tickerSymbol>" +
+    	"   <ns1:exceptionName xmlns:ns1=\"http://xml.apache.org/axis/\">test.wsdl.faults.InvalidTickerFaultMessage</ns1:exceptionName>" +
+    	"   </detail>" +
+    	"  </soapenv:Fault>" +
+    	" </soapenv:Body>" +
+    	"</soapenv:Envelope>";
+    
+    public void testDetails() throws Exception{
+    	MessageFactory mf = MessageFactory.newInstance();
+    	SOAPMessage smsg = 
+    		mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
+    	SOAPBody body = smsg.getSOAPBody();
+    	//smsg.writeTo(System.out);
+    	SOAPFault flt = body.getFault();
+    	flt.addDetail();
+    	javax.xml.soap.Detail d = flt.getDetail();
+    	Iterator i = d.getDetailEntries();
+    	while (i.hasNext()){
+    		DetailEntry entry = (DetailEntry) i.next();
+    		String name = entry.getElementName().getLocalName();
+    		if ("tickerSymbol".equals(name)) {
+    			assertEquals("the value of the tickerSymbol element didn't match",
+    					"MACR", entry.getValue());
+    		} else if ("exceptionName".equals(name)) {
+    			assertEquals("the value of the exceptionName element didn't match",
+    					"test.wsdl.faults.InvalidTickerFaultMessage", entry.getValue());
+    		} else {
+    			assertTrue("Expecting details element name of 'tickerSymbol' or 'expceptionName' - I found :" + name, false);
+    		}
+    	}
+    	assertTrue(d != null);
+    }
+    
+    /**
+     * Main
+     */
+    public static void main(String[] args)
+            throws Exception
+    {
+        SOAPFaultDetailTest detailTest = new SOAPFaultDetailTest("faultdetails");
+        detailTest.testDetails();
+    }
+
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPFaultsTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPFaultsTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPFaultsTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/SOAPFaultsTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,152 @@
+package org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+
+import javax.xml.soap.*;
+import java.io.ByteArrayOutputStream;
+
+public class SOAPFaultsTest extends TestCase {
+	
+	public SOAPFaultsTest(String name){
+		super(name);
+	}
+	
+	//Create SOAPFault with additional detail elements
+	public void testAdditionDetail() throws Exception{
+        String xml ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:cwmp=\"http://cwmp.com\">\n" +
+        " <soapenv:Header>\n" +
+        "  <cwmp:ID soapenv:mustUnderstand=\"1\">HEADERID-7867678</cwmp:ID>\n" +
+        " </soapenv:Header>\n" +
+        " <soapenv:Body>\n" +
+        "  <soapenv:Fault>\n" +
+        "   <faultcode>soapenv:Client</faultcode>\n" +
+        "   <faultstring>CWMP fault</faultstring>\n" +
+        "   <detail>\n" +
+        "    <cwmp:Fault>\n" +
+        "     <cwmp:FaultCode>This is the fault code</cwmp:FaultCode>\n" +
+        "     <cwmp:FaultString>Fault Message</cwmp:FaultString>\n" +
+        "    </cwmp:Fault>\n" +
+        "   </detail>\n" +
+        "  </soapenv:Fault>\n" +
+        " </soapenv:Body>\n" +
+        "</soapenv:Envelope>";
+        
+        MessageFactory fac = MessageFactory.newInstance();
+        SOAPMessage faultMessage = fac.createMessage();
+        
+        //Create the response to the message
+        faultMessage = fac.createMessage();
+        SOAPPart part = faultMessage.getSOAPPart();
+        SOAPEnvelope envelope = part.getEnvelope();
+        envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
+        SOAPBody body = envelope.getBody();
+        SOAPHeader header = envelope.getHeader();
+        Name idName = envelope.createName("ID", "cwmp", "http://cwmp.com");
+        SOAPHeaderElement id = header.addHeaderElement(idName);
+        id.setMustUnderstand(true);
+        id.addTextNode("HEADERID-7867678");
+        
+        //Create the SOAPFault object
+        SOAPFault fault = body.addFault();
+        fault.setFaultCode("Client");
+        fault.setFaultString("CWMP fault");
+        
+        //Add Fault Detail information
+        Detail faultDetail = fault.addDetail();
+        Name cwmpFaultName = envelope.createName("Fault", "cwmp",
+        		"http://cwmp.com");
+        DetailEntry cwmpFaultDetail =
+        	faultDetail.addDetailEntry(cwmpFaultName);
+        SOAPElement e = cwmpFaultDetail.addChildElement("FaultCode");
+        
+        e.addTextNode("This is the fault code");
+        SOAPElement e2 = cwmpFaultDetail.addChildElement(envelope.createName("FaultString", "cwmp", "http://cwmp.com"));
+        e2.addTextNode("Fault Message");
+        faultMessage.saveChanges();
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        faultMessage.writeTo(baos);
+        String xml2 = new String(baos.toByteArray());
+        faultMessage.writeTo(System.out);
+        //assertXMLEqual(xml,xml2);	
+	}
+	
+	public void testQuick() throws Exception {
+		MessageFactory msgfactory = MessageFactory.newInstance();
+		SOAPFactory factory = SOAPFactory.newInstance();
+		SOAPMessage outputmsg = msgfactory.createMessage();
+		String valueCode = "faultcode";
+		String valueString = "faultString";
+		SOAPFault fault = outputmsg.getSOAPPart().getEnvelope().getBody().addFault();
+		fault.setFaultCode(valueCode);
+		fault.setFaultString(valueString);
+		Detail d;
+		d = fault.addDetail();
+		d.addDetailEntry(factory.createName("Hello"));
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		if (outputmsg != null) {
+			if (outputmsg.saveRequired()) {
+				outputmsg.saveChanges();
+			}
+			outputmsg.writeTo(baos);
+		}
+		String xml = new String(baos.toByteArray());
+		assertTrue(xml.indexOf("Hello")!=-1);
+	}
+	
+	public void testSOAPFaultSaveChanges() throws Exception {
+		MessageFactory msgFactory =
+			MessageFactory.newInstance();
+		SOAPMessage msg = msgFactory.createMessage();
+		SOAPEnvelope envelope =
+			msg.getSOAPPart().getEnvelope();
+		SOAPBody body = envelope.getBody();
+		SOAPFault fault = body.addFault();
+		
+		fault.setFaultCode("Client");
+		fault.setFaultString(
+			"Message does not have necessary info");
+		fault.setFaultActor("http://gizmos.com/order");
+		
+		Detail detail = fault.addDetail();
+		
+		Name entryName = envelope.createName("order", "PO",
+			"http://gizmos.com/orders/");
+		DetailEntry entry = detail.addDetailEntry(entryName);
+		entry.addTextNode("quantity element does not have a value");
+		
+		Name entryName2 = envelope.createName("confirmation",
+				"PO", "http://gizmos.com/confirm");
+		DetailEntry entry2 = detail.addDetailEntry(entryName2);
+		entry2.addTextNode("Incomplete address: no zip code");
+		
+		msg.saveChanges();
+		
+        // Now retrieve the SOAPFault object and its contents
+        //after checking to see that there is one
+
+        if (body.hasFault()) {
+            fault = body.getFault();
+            String code = fault.getFaultCode();
+            String string = fault.getFaultString();
+            String actor = fault.getFaultActor();
+
+
+            detail = fault.getDetail();
+            if (detail != null) {
+                java.util.Iterator it = detail.getDetailEntries();
+                while (it.hasNext()) {
+                    entry = (DetailEntry) it.next();
+                    String value = entry.getValue();
+                }
+            }
+        }
+	}
+	
+    public static void main(String[] args) throws Exception {
+        SOAPFaultsTest detailTest = new SOAPFaultsTest("TestSOAPFaults");
+        detailTest.testQuick();
+        detailTest.testAdditionDetail();
+        detailTest.testSOAPFaultSaveChanges();
+    }
+}

Added: webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/TextTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/TextTest.java?rev=358784&view=auto
==============================================================================
--- webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/TextTest.java (added)
+++ webservices/axis2/trunk/archive/java/scratch/ruchith_dims/saaj2/test/org/apache/axis2/saaj2/TextTest.java Fri Dec 23 01:40:17 2005
@@ -0,0 +1,170 @@
+package org.apache.axis2.saaj2;
+
+import junit.framework.TestCase;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPBodyElement;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.Text;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+public class TextTest extends TestCase {
+
+    public TextTest(String name) {
+        super(name);
+    }
+
+    //Test SAAJ addTextNode performance
+    public void testAddTextNode() throws Exception {
+        SOAPFactory soapFactory = SOAPFactory.newInstance();
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage message = factory.createMessage();
+        SOAPBody body = message.getSOAPBody();
+
+        // Create the base element
+        Name bodyName = soapFactory.createName("VBGenReceiver", "xsi",
+                                               "http://www.w3.org/2001/XMLSchema-instance");
+        SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
+
+        // Create the MetaData Tag
+        Name name = soapFactory.createName("MetaData");
+        SOAPElement metaData = bodyElement.addChildElement(name);
+
+        //Create the SKey Tag
+        name = soapFactory.createName("SKey");
+        SOAPElement sKey = metaData.addChildElement(name);
+        sKey.addTextNode("SKEY001");
+
+        //Create Object Tag
+        name = soapFactory.createName("Object");
+        SOAPElement object = bodyElement.addChildElement(name);
+
+        //Create Book ID Tag
+        name = soapFactory.createName("BookID");
+        SOAPElement bookID = object.addChildElement(name);
+        bookID.addTextNode("BookID002");
+
+        //Create OrderID tag
+        name = soapFactory.createName("OrderID");
+        SOAPElement orderID = object.addChildElement(name);
+        orderID.addTextNode("OrderID003");
+
+        //create PurchaseID tage
+        name = soapFactory.createName("PurchaseID");
+        SOAPElement purchaseID = object.addChildElement(name);
+        purchaseID.addTextNode("PurchaseID005");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("LanguageID");
+        SOAPElement languageID = object.addChildElement(name);
+        languageID.addTextNode("LanguageID004");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("LanguageName");
+        SOAPElement languageName = object.addChildElement(name);
+        languageName.addTextNode("LanguageName006");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("Title");
+        SOAPElement title = object.addChildElement(name);
+        title.addTextNode("Title007");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("Author");
+        SOAPElement author = object.addChildElement(name);
+        author.addTextNode("Author008");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("Format");
+        SOAPElement format = bodyElement.addChildElement(name);
+
+        //create LanguageID Tag
+        name = soapFactory.createName("Type");
+        SOAPElement formatType = format.addChildElement(name);
+        formatType.addTextNode("Type009");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("Delivery");
+        SOAPElement delivery = bodyElement.addChildElement(name);
+
+        //create LanguageID Tag
+        name = soapFactory.createName("Name");
+        SOAPElement delName = delivery.addChildElement(name);
+        delName.addTextNode("Name010");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("Address1");
+        SOAPElement address1 = delivery.addChildElement(name);
+        address1.addTextNode("Address1011");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("Address2");
+        SOAPElement address2 = delivery.addChildElement(name);
+        address2.addTextNode("Address2012");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("City");
+        SOAPElement city = delivery.addChildElement(name);
+        city.addTextNode("City013");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("State");
+        SOAPElement state = delivery.addChildElement(name);
+        state.addTextNode("State014");
+
+        //create LanguageID Tag
+        name = soapFactory.createName("PostalCode");
+        SOAPElement postalCode = delivery.addChildElement(name);
+        postalCode.addTextNode("PostalCode015");
+
+        System.out.println("The message is:\n");
+        message.writeTo(System.out);
+        System.out.flush();
+    }
+
+    public void testComment() throws SOAPException, IOException {
+
+        String xmlString = "<?xml version='1.0' encoding='utf-8'?> " +
+                           "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
+                           "<soapenv:Header></soapenv:Header>" +
+                           "<soapenv:Body>" +
+                           "<Node:abc xmlns:Node=\"http://www.simpletest.org\">" +
+                           "This is some text" +
+                           "<!--This is comment-->This is other text" +
+                           "<!--This is another comment-->This is some other text" +
+                           "</Node:abc>" +
+                           "</soapenv:Body>" +
+                           "</soapenv:Envelope>";
+
+        MessageFactory mf = MessageFactory.newInstance();
+        SOAPMessage message =
+                mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
+
+        SOAPBody body = message.getSOAPBody();
+        Node bodyElement = body.getFirstChild();
+        NodeList textNodes = bodyElement.getChildNodes();
+
+        assertEquals(5, textNodes.getLength());
+
+        for (int i = 0; i < textNodes.getLength(); i++) {
+            Node nde = textNodes.item(i);
+            boolean isComment;
+            if (nde instanceof Text) {
+                isComment = ((Text) nde).isComment();
+                if (i == 1)
+                    assertEquals(true, isComment);
+                else
+                    assertEquals(false, isComment);
+            }
+        }
+    }
+}