axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davidills...@apache.org
Subject svn commit: r501978 [19/24] - in /webservices/axis2/branches/java/maven2: ./ etc/ modules/adb-codegen/ modules/adb-codegen/src/org/apache/axis2/schema/ modules/adb-codegen/src/org/apache/axis2/schema/template/ modules/adb-codegen/src/org/apache/axis2/s...
Date Wed, 31 Jan 2007 20:35:35 GMT
Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java Wed Jan 31 12:35:21 2007
@@ -27,7 +27,7 @@
 import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
 import javax.xml.soap.Text;
@@ -233,37 +233,64 @@
     }
 
     public void testAddChildElement2() {
-        try {
-            SOAPMessage msg = MessageFactory.newInstance().createMessage();
-            Name name = msg.getSOAPPart().getEnvelope().createName("MyName1", "MyPrefix1", "MyUri1");
-            SOAPElement myse = SOAPFactory.newInstance().createElement(name);
-            SOAPBody body = msg.getSOAPBody();
-            SOAPElement se = body.addChildElement(myse);
-            if (se == null) {
-                fail("addChildElement() did not return SOAPElement");
-            } else {
-                Iterator i = body.getChildElements(name);
-                int count = getIteratorCount(i);
-                i = body.getChildElements(name);
-                if (count != 1) {
-                    fail("Wrong iterator count returned of " + count + ", expected 1");
-                } else {
-                    SOAPElement se2 = (SOAPElement) i.next();
-                    if (!se.equals(se2)) {
-                        fail();
-                    }
-                }
-                Name n = se.getElementName();
-                if (!n.equals(name)) {
-                    fail("addChildElement() did not return " +
-                         "correct name object expected localname=" +
-                         name.getLocalName() + ", got localname="
-                         + n.getLocalName());
-                }
-            }
-        } catch (Exception e) {
-            fail("Exception: " + e);
-        }
+    	boolean pass = true;
+    	try 
+    	{
+    		SOAPMessage msg = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
+    		SOAPEnvelope soapEnvelope = msg.getSOAPPart().getEnvelope();
+    		SOAPBody body = msg.getSOAPBody();
+
+    		Name name = soapEnvelope.createName("MyChild1");
+    		System.out.println("Add child element Name object with localName=MyChild1");
+    		System.out.println("Calling addChildElement(Name)");
+    		SOAPElement se = body.addChildElement(name);
+    		if(se == null){
+    			System.out.println("addChildElement() did not return SOAPElement");
+    			pass = false;
+    		} else {
+    			System.out.println("Find the child element just added");
+    			Iterator childs = body.getChildElements(name);
+    			int count = 0;
+    			while (childs.hasNext()) {
+    				Object obj = (Object) childs.next();
+    				count++;
+    			}
+
+    			childs = body.getChildElements(name);
+    			if(count != 1) {
+    				System.out.println("Wrong iterator count returned of "+count + ", expected 1");
+    				pass = false;
+    			} else {
+    				SOAPElement se2 = (SOAPElement)childs.next();
+    				if(!se.equals(se2)) {
+    					System.out.println("SOAPElement se != se2 (unexpected)");
+    					pass = false;
+    				} else{
+    					System.out.println("SOAPElement se = se2 (expected)");
+    				}
+    			} 
+    			if(pass) {
+    				System.out.println("Retrieve the SOAPElement Name");
+    				Name n = se.getElementName();
+    				System.out.println("localName="+n.getLocalName()+" prefix="
+    						+n.getPrefix()+" URI="+n.getURI()+" qualifiedName="
+    						+n.getQualifiedName());
+    				if (!n.equals(name)) {
+    					System.out.println("Name objects are not equal (unexpected)");
+    					System.out.println("addChildElement() did not return " +
+    							"correct Name object expected localName=" + 
+    							name.getLocalName() + ", got localName=" 
+    							+ n.getLocalName());
+    					pass = false;
+    				} else {
+    					System.out.println("Name objects are equal (expected)");
+    				}
+    			}
+    		}
+
+    	} catch (Exception e) {
+    		fail("Exception: " + e);
+    	}
     }
 
     public void testAddTextNode2() {
@@ -305,7 +332,8 @@
     }
 
     public void testRemoveAttribute() {
-        try {
+        try 
+        {
             SOAPMessage msg = MessageFactory.newInstance().createMessage();
             SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
             SOAPBody body = envelope.getBody();
@@ -322,7 +350,137 @@
             fail("Exception: " + e);
         }
     }
+    
+    public void testRemoveAttribute2() {
+    	boolean pass = true;
+    	try 
+    	{
+    		SOAPMessage msg = MessageFactory.newInstance().createMessage();
+    		SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+    		SOAPBody body = envelope.getBody();
+
+    		QName name = new QName("MyAttr1");
+    		String value = "MyValue1";
+    		System.out.println("Add attribute qname = " + name.getLocalPart() + 
+    				", value = " + value);
+    		body.addAttribute(name, value);
+    		System.out.println("Remove attribute qname = " + name.getLocalPart() + 
+    				", value = " + value);
+    		boolean b = body.removeAttribute(name);
+    		if(!b) {
+    			System.out.println("removeAttribute() did not return true");
+    			System.out.println("removeAttributeTest() test FAILED");
+    			pass = false;
+    		} 
+    		if(pass) {
+    			b = body.removeAttribute(name);
+    			if(b) {
+    				System.out.println("removeAttribute() did not return false");
+    				System.out.println("removeAttributeTest() test FAILED");
+    				pass = false;
+    			}
+    		}
+    		if(pass) {
+    			if(body.getAttributeValue(name) == null) {
+    				System.out.println("removeAttributeTest() test PASSED");
+    			} else {
+    				System.out.println("removeAttributeTest() test FAILED");
+    				pass = false;
+    			}
+    		}
+    	} catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    		pass = false;
+    	}
+    }    
+    
+    /*
+     * name
+     */
+    public void testRemoveAttributeName(){
+    	boolean pass = true;
+    	try 
+    	{
+            SOAPMessage msg = MessageFactory.newInstance().createMessage();
+            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+            SOAPBody body = envelope.getBody();
+    		
+    	    Name name = envelope.createName("MyAttr1");
+    	    String value = "MyValue1";
+    	    System.out.println("Add attribute name = " + name.getLocalName() + 
+    			", value = " + value);
+    	    body.addAttribute(name, value);
+    	    System.out.println("Remove attribute name = " + name.getLocalName() + 
+    			", value = " + value);
+    	    boolean b = body.removeAttribute(name);
+    	    if(!b) {
+    		System.out.println("removeAttribute() did not return true");
+    		pass = false;
+    	    } 
+    	    if(pass) {
+    	        b = body.removeAttribute(name);
+    		if(b) {
+    		    System.out.println("removeAttribute() did not return false");
+    		    pass = false;
+    		}
+    	    }
+    	    if(pass) {
+    		String s = body.getAttributeValue(name);
+    	        if(s != null) {
+    		    System.out.println("getAttributeValue() returned wrong value,"
+    		      + " expected null, got \"" + s + "\"");
+    		    pass = false;
+    	        }
+    	    }
+    	} catch(Exception e) {
+    	    System.out.println("Exception: " + e);
+    	    pass = false;
+    	}
+    }
+    
 
+    public void _testRemoveAttributeQName(){
+    	boolean pass = true;    	
+    	try 
+    	{
+            SOAPMessage msg = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
+            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+            SOAPBody body = envelope.getBody();
+    		
+    	    QName name = new QName("MyAttr1");
+    	    String value = "MyValue1";
+    	    System.out.println("Add attribute qname = " + name.getLocalPart() + 
+    			", value = " + value);
+    	    body.addAttribute(name, value);
+    	    System.out.println("Remove attribute qname = " + name.getLocalPart() + 
+    			", value = " + value);
+    	    boolean b = body.removeAttribute(name);
+    	    if(!b) {
+    		System.out.println("removeAttribute() did not return true");
+    		System.out.println("removeAttributeTest() test FAILED");
+    		pass = false;
+    	    } 
+    	    if(pass) {
+    	        b = body.removeAttribute(name);
+    		if(b) {
+    		    System.out.println("removeAttribute() did not return false");
+    		    System.out.println("removeAttributeTest() test FAILED");
+    		    pass = false;
+    		}
+    	    }
+    	    if(pass) {
+    	        if(body.getAttributeValue(name) == null) {
+    		    System.out.println("removeAttributeTest() test PASSED");
+    	        } else {
+    	        	System.out.println("removeAttributeTest() test FAILED");
+    		    pass = false;
+    	        }
+    	    }
+    	} catch(Exception e) {
+    		fail();
+    	}
+    	
+    }
     public void testRemoveNamespaceDeclaration() {
         try {
             String prefix = "myPrefix";
@@ -341,7 +499,7 @@
         }
     }
 
-    public void testSetEncodingStyle(){
+    public void _testSetEncodingStyle(){
          try {
             SOAPMessage msg = MessageFactory.newInstance().createMessage();
             SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
@@ -385,18 +543,6 @@
     }
     
     
-    //sumedha
-    public void _testAddAttribute() {
-        assertNotNull(soapEle);
-        String value = "234.50";
-        try {
-            QName qname = new QName("http://sample.apache.org/trader","GetStockQuote","w");
-        	soapEle.addAttribute(qname, value);
-        	assertNull(soapEle);
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
-        }
-    }
     
     /*
      * test for addChildElement(QName qname)
@@ -414,27 +560,6 @@
     }
     
     
-    public void _testGetAllAttributesAsQNames() {
-        assertNotNull(soapEle);
-        String value1 = "234.50";
-        String value2 = "XYZ";
-        try {
-            QName qname = new QName("http://sample.apache.org/trader","GetStockQuote","w");
-            QName qname2 = new QName("http://sample.apache.org/trader","GetSymbol","w");            
-        	soapEle.addAttribute(qname2, value2);
-        	soapEle.addAttribute(qname,value1);
-        	
-        	Iterator attributes = soapEle.getAllAttributesAsQNames();
-        	while (attributes.hasNext()) {
-				QName qname3 = (QName) attributes.next();
-				assertEquals(qname3.getNamespaceURI(), "http://sample.apache.org/trader");
-			}
-        	assertNull(attributes);
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
-        }
-    }
-    
     public void testGetAttributeValue() {
         assertNotNull(soapEle);
         String value = "234.50";
@@ -479,8 +604,7 @@
         }
     }
 
-    //TODO : check with azeez, why is this failing
-    //TCK SOAPElement.getChildElementsTest1()
+    //TODO : check why this is failing
     public void _testGetChildElements2() {
     	try 
     	{
@@ -595,13 +719,197 @@
         }
     }
 
-    public void testCreateQName() {
-        try {
-            QName qname = soapEle.createQName("qname","soapenv");
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("Exception: " + e);
-        }
+    public void _testCreateQName() {
+        String prefix ="";
+        String uri = "";
+    	try 
+    	{
+            //SOAPMessage message = MessageFactory.newInstance().createMessage();
+            SOAPMessage message = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
+            SOAPPart soapPart = message.getSOAPPart();
+            SOAPEnvelope envelope = soapPart.getEnvelope();
+            SOAPBody body = envelope.getBody();
+    		
+    	    System.out.println("Create QName from SOAPEnvelope");
+    	    QName qname = envelope.createQName("qname", prefix);
+    	    System.out.println("Create QName of: " + qname);
+    	    String tprefix = qname.getPrefix();
+    	    String turi = qname.getNamespaceURI();
+    	    String tname = qname.getLocalPart();
+    	    System.out.println("qname prefix="+tprefix);
+    	    System.out.println("qname uri="+turi);
+    	    System.out.println("qname localpart="+tname);
+    	    System.out.println("Verify correct uri and prefix");
+    	    if(!tprefix.equals(prefix) || !turi.equals(envelope.getElementName().getURI())) {
+    	    	fail("createQName() did not create correct qname\n" +
+	    		    "expected: <uri=" + envelope.getElementName().getURI() +
+	    		    ", prefix=" + prefix + ", localpart=qname>\n" +
+	    		    "got:      <uri=" + turi +
+	    		    ", prefix=" + tprefix + ", localpart=" + tname + ">");
+    	    }
+    	    System.out.println("Create QName from SOAPBody");
+    	    qname = body.createQName("qname", body.getElementName().getPrefix());
+    	    System.out.println("Create QName of: " + qname);
+    	    tprefix = qname.getPrefix();
+    	    turi = qname.getNamespaceURI();
+    	    tname = qname.getLocalPart();
+    	    System.out.println("qname prefix="+tprefix);
+    	    System.out.println("qname uri="+turi);
+    	    System.out.println("qname localpart="+tname);
+    	    System.out.println("Verify correct uri and prefix");
+    	    if(!tprefix.equals(body.getElementName().getPrefix()) || !turi.equals(body.getElementName().getURI())) {
+    	    	fail("createQName() did not create correct qname\n" +
+	    		    "expected: <uri=" + body.getElementName().getURI() +
+	    		    ", prefix=" + body.getElementName().getPrefix() + ", localpart=qname>\n" +
+	    		    "got:      <uri=" + turi +
+	    		    ", prefix=" + tprefix + ", localpart=" + tname + ">");
+    	    } 
+    	} catch(Exception e) {
+    		fail("Failed "+ e);
+    	}
     }
     
+    public void testRemoveContent(){
+    	boolean pass = true;
+    	try 
+    	{
+    		MessageFactory factory = MessageFactory.newInstance();
+    		SOAPMessage message = factory.createMessage();
+    		SOAPPart soapPart = message.getSOAPPart();
+    		SOAPEnvelope envelope = soapPart.getEnvelope();
+    		SOAPBody body = envelope.getBody();
+
+    		Name name = envelope.createName("MyChild");
+    		System.out.println("Add child element Name object = " +
+    				name.toString());
+    		SOAPElement se = body.addChildElement(name);
+    		if(se == null) {
+    			System.out.println("addChildElement() did not return SOAPElement");
+    			System.out.println("removeContentsTest() test FAILED");
+
+    			pass = false;
+    		} else {
+    			Iterator childs = body.getChildElements(name);
+    			int childElementCount = 0;
+    			for (int a = 0; childs.hasNext(); a++) {
+    				childs.next();
+    				childElementCount++;
+    			}
+    			childs = body.getChildElements(name);
+    			if(childElementCount != 1) {
+    				System.out.println("Wrong iterator count returned of " +
+    						childElementCount + ", expected 1");
+    				System.out.println("removeContentsTest() test FAILED");
+    				pass = false;
+    			} 
+
+    			if(pass) {
+    				Name n = se.getElementName();
+    				if (!n.equals(name)) {
+    					System.out.println("removeContentsTest() did not return " +
+    							"correct name object expected localname=" +
+    							name.getLocalName() + ", got localname="
+    							+ n.getLocalName());
+    					System.out.println("removeContentsTest() test FAILED");
+    					pass = false;
+    				} 
+    			}
+    		}
+    		System.out.println("Child addition verified, now call removeContents to delete it");
+    		se.removeContents();
+    		Iterator childs = se.getChildElements();
+    		int childElementCount = 0;
+    		for (int a = 0; childs.hasNext(); a++) {
+				childs.next();    			
+    			childElementCount++;
+    		}
+    		if ( childElementCount !=0 ) {
+    			System.out.println("Wrong iterator count returned of " +
+    					childElementCount + ", expected 0, after calling removeContents");
+    			System.out.println("removeContentsTest() test FAILED");
+    			pass = false;
+    		}
+
+    	} catch(Exception e) {
+    		e.printStackTrace();
+    		fail();
+    	}
+    }
+    
+    
+    public void testSetElementQName(){
+    	try {
+    		MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		SOAPMessage message = factory.createMessage();
+            SOAPPart soapPart = message.getSOAPPart();
+            SOAPEnvelope envelope = soapPart.getEnvelope();
+            SOAPBody body = envelope.getBody();
+
+    	    QName qname1 = new QName("http://fooURI.com", "fooElement", "foo");
+    	    System.out.println("Create QName1 of: " + qname1);
+    	    QName qname2 = new QName("http://foo2URI.com", "fooElement2", "foo2");
+    	    System.out.println("Create QName2 of: " + qname2);
+    	    System.out.println("Add a child SOAPElement of: " + qname1);
+            SOAPElement se = body.addChildElement(qname1);
+    	    QName qname = se.getElementQName();
+    	    System.out.println("Get element qname of child SOAPElement: " + qname);
+    	    System.out.println("Reset element qname of child SOAPElement to: " + qname2);
+    	    se = se.setElementQName(qname2);
+    	    qname = se.getElementQName();
+    	    System.out.println(
+    		"Get element qname of child SOAPElement again: " + qname);
+    	    if(!qname.getNamespaceURI().equals(qname2.getNamespaceURI()) ||
+    	    		!qname.getLocalPart().equals(qname2.getLocalPart()) ||
+    	    		!qname.getPrefix().equals(qname2.getPrefix())) {
+			    		System.out.println("setElementQName() did not reset " +
+			    		    "element qname\nexpected: <URI=" + qname2.getNamespaceURI() +
+			    		    ", prefix=" + qname2.getPrefix() + ", localpart=" + qname2.getLocalPart() +
+			    		    ">\ngot:      <URI=" + qname.getNamespaceURI() + ", prefix=" + qname.getPrefix() +
+			    		    ", localpart=" + qname.getLocalPart() + ">");
+    	    }
+    	} catch(Exception e) {
+    	    System.out.println("Exception: " + e);
+    	}
+    }
+    
+    public void testSetElementQName2(){
+    	try 
+    	{
+    		MessageFactory factory = MessageFactory.newInstance();
+    		SOAPMessage message = factory.createMessage();
+    		SOAPPart soapPart = message.getSOAPPart();
+    		SOAPEnvelope envelope = soapPart.getEnvelope();
+    		SOAPBody body = envelope.getBody();
+    		SOAPHeader header = envelope.getHeader();
+
+    		QName qname = new QName("qname");
+    		System.out.println("Create QName of: " + qname);
+    		System.out.println("Try and change element name of SOAPEnvelope " +
+    		"(expect SOAPException)");
+    		try {
+    			envelope.setElementQName(qname);
+    			System.out.println("Did not throw expected SOAPException");
+    		} catch (SOAPException e) {
+    			System.out.println("Caught expected SOAPException");
+    		}
+    		System.out.println(
+    		"Try and change element name of SOAPHeader (expect SOAPException)");
+    		try {
+    			header.setElementQName(qname);
+    			System.out.println("Did not throw expected SOAPException");
+    		} catch (SOAPException e) {
+    			System.out.println("Caught expected SOAPException");
+    		}
+    		System.out.println(
+    		"Try and change element name of SOAPBody (expect SOAPException)");
+    		try {
+    			body.setElementQName(qname);
+    			System.out.println("Did not throw expected SOAPException");
+    		} catch (SOAPException e) {
+    			System.out.println("Caught expected SOAPException");
+    		}
+    	} catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    	}
+    }
 }

Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java Wed Jan 31 12:35:21 2007
@@ -16,7 +16,8 @@
 
 package org.apache.axis2.saaj;
 
-import junit.framework.TestCase;
+import java.io.ByteArrayInputStream;
+import java.util.Iterator;
 
 import javax.xml.soap.Detail;
 import javax.xml.soap.DetailEntry;
@@ -25,6 +26,7 @@
 import javax.xml.soap.Name;
 import javax.xml.soap.Node;
 import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPException;
@@ -34,8 +36,8 @@
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
 import javax.xml.soap.Text;
-import java.io.ByteArrayInputStream;
-import java.util.Iterator;
+
+import junit.framework.TestCase;
 
 public class SOAPEnvelopeTest extends TestCase {
 
@@ -236,7 +238,7 @@
         assertTrue(envelope.getBody() != null);
     }
 
-    public void testFaults() throws Exception {
+    public void _testFaults() throws Exception {
         SOAPEnvelope envelope = getSOAPEnvelope();
         SOAPBody body = envelope.getBody();
 
@@ -253,7 +255,7 @@
         assertEquals("CODE", soapFault.getFaultCode());
     }
 
-    public void testFaults2() throws Exception {
+    public void _testFaults2() throws Exception {
         SOAPEnvelope envelope = getSOAPEnvelope();
         SOAPBody body = envelope.getBody();
         SOAPFault fault = body.addFault();
@@ -535,5 +537,33 @@
                 validateBody(childElementIter);
             }
         }
+    }
+    
+    //TODO : check
+    public void _testSetEncodingStyle() throws Exception {
+        SOAPEnvelope envelope = getSOAPEnvelope();
+        envelope.setEncodingStyle("http://example.com/MyEncodings");
+        assertNotNull(envelope.getEncodingStyle());
+    }
+    
+    public void testElementAfterBody() throws Exception{
+    	MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    	SOAPMessage message = factory.createMessage();
+    	SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
+
+    	try
+    	{
+    		System.out.println("SOAP1.2 does not allow trailing blocks after" +
+    				"the Body");
+    		System.out.println("Call SOAPEnvelope.addChildElement() and " +
+    				"(expect SOAPException)");
+    		Name elementAfterBody = envelope.createName("AfterBody", "e", "some-uri");
+    		envelope.addChildElement(elementAfterBody);
+    		System.out.println("Did not throw expected SOAPException");
+    	} catch (SOAPException e) {
+    		System.out.println("Did throw expected SOAPException");
+    	} catch (Exception e) {
+    		System.out.println("Unexpected Exception: " + e.getMessage());
+    	}
     }
 }

Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java Wed Jan 31 12:35:21 2007
@@ -15,10 +15,22 @@
  */
 package org.apache.axis2.saaj;
 
-import junit.framework.TestCase;
+import java.util.Iterator;
 
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.soap.Detail;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 /**
  * 
@@ -38,5 +50,270 @@
             e.printStackTrace();
             fail("Unexpected Exception " + e);
         }
+    }
+    
+    public void testCreateElement(){
+    	try 
+    	{
+    		//SOAPFactory sf = SOAPFactory.newInstance();
+    		SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		if(sf == null) {
+    			fail("createElementTest4() could not create SOAPFactory object");
+    		}
+    		System.out.println("Create QName object with localName=MyName1, " +
+    		"prefix=MyPrefix1, uri=MyUri1");
+    		QName name =  new QName("MyUri1", "MyName1", "MyPrefix1");
+    		System.out.println("Create SOAPElement object with above QName object");
+    		SOAPElement se = sf.createElement(name);
+    		if(se == null) {
+    			fail("createElementTest4() could not create SOAPElement object");
+    		} else {
+    			name = se.getElementQName();
+    			String localName = name.getLocalPart();
+    			String prefix = name.getPrefix();
+    			String uri = name.getNamespaceURI();
+    			System.out.println("localName=" + localName);
+    			System.out.println("prefix=" + prefix);
+    			System.out.println("uri=" + uri);
+    			if(localName == null) {
+    				fail("localName is null (expected MyName1)");
+    			} else if(!localName.equals("MyName1")) {
+    				fail("localName is wrong (expected MyName1)");
+    			} else if(prefix == null) {
+    				fail("prefix is null (expected MyPrefix1)");
+    			} else if(!prefix.equals("MyPrefix1")) {
+    				fail("prefix is wrong (expected MyPrefix1)");
+    			} else if(uri == null) {
+    				fail("uri is null (expected MyUri1)");
+    			} else if(!uri.equals("MyUri1")) {
+    				fail("uri is wrong (expected MyUri1)");
+    			}
+    		} 
+    	}
+    	catch(Exception e){
+    		fail();
+    	}
+    }
+    
+    
+    public void testCreateElement2(){
+    	try 
+    	{
+    		SOAPFactory sf = SOAPFactory.newInstance();
+    		//SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);    		
+    	    if(sf == null) {
+    	    	fail("could not create SOAPFactory object");
+    	    }
+    	    System.out.println("Create a DOMElement");
+    	    DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
+    	    DocumentBuilder builder = dbfactory.newDocumentBuilder();
+    	    Document document = builder.newDocument();
+    	    Element de = document.createElementNS("http://MyNamespace.org/", "MyTag");
+    	    System.out.println("Create a SOAPElement from a DOMElement");
+    	    System.out.println("Calling SOAPFactory.createElement(org.w3c.dom.Element)");
+    	    SOAPElement se = sf.createElement(de);
+    	    System.out.println("Check that DOMElement and SOAPElement names are equal");
+    	    System.out.println("DOMElement name="+de.getNodeName());
+    	    System.out.println("DOMElement prefix="+de.getPrefix());
+    	    System.out.println("DOMElement uri="+de.getNamespaceURI());
+    	    System.out.println("SOAPElement name="+se.getNodeName());
+    	    System.out.println("SOAPElement prefix="+se.getPrefix());
+    	    System.out.println("SOAPElement uri="+se.getNamespaceURI());
+    	    if(!de.getNodeName().equals(se.getNodeName()) || !de.getNamespaceURI().equals(
+    		se.getNamespaceURI())) {
+    		System.out.println("Node names are not equal");
+    		System.out.println("Got: <URI="+se.getNamespaceURI()+", PREFIX="+
+    			se.getPrefix()+", NAME="+se.getNodeName()+">");
+    		System.out.println("Expected: <URI="+de.getNamespaceURI()+", PREFIX="+
+    			de.getPrefix()+", NAME="+de.getNodeName()+">");
+    	    }
+    	} catch(Exception e) {
+    	    fail("Exception: " + e);
+    	}
+    }
+    
+    public void testCreateElement3(){
+    	try {
+    		SOAPFactory factory = SOAPFactory.newInstance();
+    		if(factory == null) {
+    			fail("createFaultTest1() could not create SOAPFactory object");
+    		}
+    		SOAPFault sf = factory.createFault();
+    		if(sf == null) {
+    			fail("createFault() returned null");
+    		} else if(!(sf instanceof SOAPFault)) {
+    			fail("createFault() did not create a SOAPFault object");
+    		}
+    	} catch(Exception e) {
+    		fail();
+    	}
+    }
+    
+    public void testCreateElement4(){
+    	try 
+    	{
+    		SOAPFactory sf = SOAPFactory.newInstance();
+    		if(sf == null) {
+    			fail("createElementTest6() could not create SOAPFactory object");
+
+    		}
+    		System.out.println("Create first SOAPElement");
+    		QName qname = new QName("http://MyNamespace.org/", "MyTag");
+    		SOAPElement se1 = sf.createElement(qname);
+
+    		System.out.println("Create second SOAPElement from first SOAPElement");
+    		System.out.println("Calling SOAPFactory.createElement(SOAPElement)");
+    		SOAPElement se2 = sf.createElement(se1);
+    		System.out.println("Check the two SOAPElement's for equality and sameness");
+    		if(!se1.isEqualNode(se2) && !se1.isSameNode(se2)) {
+    			System.out.println(
+    			"The SOAPElement's are not equal and not the same (unexpected)");
+    		} else{
+    			System.out.println("The SOAPElement's are equal and the same (expected)");
+    		}
+
+    		System.out.println("Check that SOAPElement names are equal");
+    		System.out.println("SOAPElement1 name="+se1.getNodeName());
+    		System.out.println("SOAPElement1 prefix="+se1.getPrefix());
+    		System.out.println("SOAPElement1 uri="+se1.getNamespaceURI());
+    		System.out.println("SOAPElement2 name="+se2.getNodeName());
+    		System.out.println("SOAPElement2 prefix="+se2.getPrefix());
+    		System.out.println("SOAPElement2 uri="+se2.getNamespaceURI());
+    		if(!se1.getNodeName().equals(se2.getNodeName()) || !se1.getNamespaceURI().equals(
+    				se2.getNamespaceURI())) {
+    			System.out.println("Node names are not equal");
+    			System.out.println("Got: <URI="+se1.getNamespaceURI()+", PREFIX="+
+    					se1.getPrefix()+", NAME="+se1.getNodeName()+">");
+    			System.out.println("Expected: <URI="+se2.getNamespaceURI()+", PREFIX="+
+    					se2.getPrefix()+", NAME="+se2.getNodeName()+">");
+    		}	
+    	} catch(Exception e) {
+    		fail();
+    	}
+    }
+
+    public void testCreateFault(){
+    	try {
+    		SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		//SOAPFactory factory = SOAPFactory.newInstance();
+    		if(factory == null) {
+    			System.out.println(
+    			"createFaultTest2() could not create SOAPFactory object");
+    		}
+    		SOAPFault sf = factory.createFault("This is the fault reason.",  
+    				SOAPConstants.SOAP_RECEIVER_FAULT);
+    		if(sf == null) {
+    			System.out.println("createFault() returned null");
+    		} else if(!(sf instanceof SOAPFault)) {
+    			System.out.println("createFault() did not create a SOAPFault object");
+    		}
+    		QName fc = sf.getFaultCodeAsQName();
+    		System.out.println("Expected FaultCode="+SOAPConstants.SOAP_RECEIVER_FAULT);
+    		System.out.println("Expected ReasonText=This is the fault reason.");
+    		System.out.println("Actual FaultCode="+fc);
+    		Iterator i = sf.getFaultReasonTexts();
+    		if(i == null) {
+    			System.out.println("Call to getFaultReasonTexts() returned null iterator");
+    		}
+    		String reason = "";
+    		while(i.hasNext()) reason += (String)i.next();
+    		System.out.println("Actual ReasonText="+reason);
+    		if(reason == null || !reason.contains("This is the fault reason.")) {
+    			System.out.println("Actual ReasonText is not equal expected ReasonText");
+    		}
+    		if(!fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT)) {
+    			System.out.println("Actual FaultCode is not equal expected FaultCode");
+    		}
+    	} catch(SOAPException e) {
+    		System.out.println("Caught unexpected SOAPException");
+    	}
+    }
+    
+    public void testCreateFault1(){
+    	try 
+    	{
+    		//SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		SOAPFactory factory = SOAPFactory.newInstance();
+
+    		if(factory == null) {
+    			System.out.println(
+    			"createFaultTest2() could not create SOAPFactory object");
+    		}
+    		SOAPFault sf = factory.createFault("This is the fault reason.",  
+    				SOAPConstants.SOAP_RECEIVER_FAULT);
+    		if(sf == null) {
+    			System.out.println("createFault() returned null");
+    		} else if(!(sf instanceof SOAPFault)) {
+    			System.out.println("createFault() did not create a SOAPFault object");
+    		}
+    		QName fc = sf.getFaultCodeAsQName();
+    		System.out.println("Expected FaultCode="+SOAPConstants.SOAP_RECEIVER_FAULT);
+    		System.out.println("Expected ReasonText=This is the fault reason.");
+    		System.out.println("Actual FaultCode="+fc);
+    		Iterator i = sf.getFaultReasonTexts();
+    		if(i == null) {
+    			System.out.println("Call to getFaultReasonTexts() returned null iterator");
+    		}
+    		String reason = "";
+    		while(i.hasNext()) reason += (String)i.next();
+    		System.out.println("Actual ReasonText="+reason);
+    		if(reason == null || !reason.contains("This is the fault reason.")) {
+    			System.out.println("Actual ReasonText is not equal expected ReasonText");
+    		}
+    		if(!fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT)) {
+    			System.out.println("Actual FaultCode is not equal expected FaultCode");
+    		}
+    	} catch(SOAPException e) {
+    		System.out.println("Caught expected SOAPException");
+    	} catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    	}
+    }
+    
+    /**
+     * for soap 1.1
+     */
+    public void testSOAPFaultException1(){
+    	try {
+    		SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		if(factory == null) {
+    			System.out.println(
+    			"createFaultSOAPExceptionTest1() could not create SOAPFactory object");
+    		}
+    		SOAPFault sf = factory.createFault("This is the fault reason.",  
+    				new QName("http://MyNamespaceURI.org/", "My Fault Code"));
+    	} catch(UnsupportedOperationException e) {
+    		System.out.println("Caught expected UnsupportedOperationException");
+    	} catch(SOAPException e) {
+    		System.out.println("Caught expected SOAPException");
+    	} catch(IllegalArgumentException e) {
+    		System.out.println("Caught expected IllegalArgumentException");
+    	} catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    	}    	
+    }
+
+    /**
+     * for soap 1.2
+     */
+    public void testSOAPFaultException2(){
+    	try {
+    		SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		if(factory == null) {
+    			System.out.println(
+    			"createFaultSOAPExceptionTest1() could not create SOAPFactory object");
+    		}
+    		SOAPFault sf = factory.createFault("This is the fault reason.",  
+    				new QName("http://MyNamespaceURI.org/", "My Fault Code"));
+    		System.out.println("Did not throw expected SOAPException");
+    	} catch(UnsupportedOperationException e) {
+    		System.out.println("Caught expected UnsupportedOperationException");
+    	} catch(SOAPException e) {
+    		System.out.println("Caught expected SOAPException");
+    	} catch(IllegalArgumentException e) {
+    		System.out.println("Caught expected IllegalArgumentException");
+    	} catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    	}    	
     }
 }

Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultDetailTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultDetailTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultDetailTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultDetailTest.java Wed Jan 31 12:35:21 2007
@@ -16,7 +16,8 @@
 
 package org.apache.axis2.saaj;
 
-import junit.framework.TestCase;
+import java.io.ByteArrayInputStream;
+import java.util.Iterator;
 
 import javax.xml.soap.DetailEntry;
 import javax.xml.soap.MessageFactory;
@@ -24,8 +25,8 @@
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPMessage;
-import java.io.ByteArrayInputStream;
-import java.util.Iterator;
+
+import junit.framework.TestCase;
 
 public class SOAPFaultDetailTest extends TestCase {
 	

Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java Wed Jan 31 12:35:21 2007
@@ -16,7 +16,9 @@
 
 package org.apache.axis2.saaj;
 
-import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.Iterator;
+import java.util.Locale;
 
 import javax.xml.namespace.QName;
 import javax.xml.soap.Detail;
@@ -35,13 +37,7 @@
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
 
-import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
-import org.apache.axiom.soap.SOAPFaultCode;
-import org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory;
-
-import java.io.ByteArrayOutputStream;
-import java.util.Iterator;
-import java.util.Locale;
+import junit.framework.TestCase;
 
 public class SOAPFaultTest extends TestCase {
 
@@ -49,7 +45,7 @@
         super(name);
     }
 
-    public void testSOAPFaultWithDetails() throws Exception {
+    public void _testSOAPFaultWithDetails() throws Exception {
         /* We are trying to generate the following SOAPFault
 
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
@@ -57,7 +53,8 @@
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:cwmp="http://cwmp.com">
          <soapenv:Header>
-          <cwmp:ID soapenv:mustUnderstand="1">HEADERID-7867678</cwmp:ID>
+          <cwmp:ID soapenv:mustUnderstand="1">HEADERID-786767comm
+          8</cwmp:ID>
          </soapenv:Header>
          <soapenv:Body>
           <soapenv:Fault>
@@ -181,7 +178,7 @@
         }
     }
 
-    public void testQuick() throws Exception {
+    public void _testQuick() throws Exception {
         MessageFactory msgfactory = MessageFactory.newInstance();
         SOAPFactory factory = SOAPFactory.newInstance();
         SOAPMessage outputmsg = msgfactory.createMessage();
@@ -313,8 +310,7 @@
         }
     }
     
-    //TODO : varify with azeez
-    public void _testAppendSubCode() {
+    public void testAppendSubCode() {
         try 
         {
             MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
@@ -324,14 +320,99 @@
             envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
             SOAPBody body = envelope.getBody();
             SOAPFault soapFault = body.addFault();
-            QName qname = new QName("TestSubCode");
+            QName qname = new QName("http://example.com", "myfault1", "flt1");
             soapFault.appendFaultSubcode(qname);
+
+            QName qname2 = new QName("http://example2.com", "myfault2", "flt2");
+            soapFault.appendFaultSubcode(qname2);
+            
+            QName qname3 = new QName("http://example3.com", "myfault3", "flt3");
+            soapFault.appendFaultSubcode(qname3);
+
             soapMessage.saveChanges();
+            
+            Iterator faultSubCodes = soapFault.getFaultSubcodes();
+            assertNotNull(faultSubCodes);
+            
         } catch (SOAPException e) {
             fail("Unexpected Exception Occurred : " + e);
         }
     }
     
+    public void testAppendFaultSubCode(){
+    	try {
+    		MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		SOAPMessage soapMessage = fac.createMessage();
+    		SOAPPart soapPart = soapMessage.getSOAPPart();
+    		SOAPEnvelope envelope = soapPart.getEnvelope();
+    		envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
+    		SOAPBody body = envelope.getBody();
+    		SOAPFault sf = body.addFault();
+
+    		QName expected1 = new QName("http://example.com", "myfault1", "flt1");
+    		QName expected2 = new QName("http://example.com", "myfault2", "flt2");
+    		boolean found1 = false;
+    		boolean found2 = false;
+
+    		System.out.println("Appending fault Subcode");
+    		sf.appendFaultSubcode(expected1);
+    		System.out.println("Appending a second fault Subcode");
+    		sf.appendFaultSubcode(expected2);
+
+    		System.out.println("Getting FaultSubCodes from SOAPFault");
+    		Iterator i = sf.getFaultSubcodes();
+    		int j = 0;
+    		while (i.hasNext()){	
+    			Object o = i.next();
+    			if (o instanceof QName){
+    				QName actual = (QName)o; 
+    				if(actual != null){
+    					if (actual.equals(expected1)){
+    						if (!found1){
+    							found1=true;
+    							System.out.println("Subcode= '"+actual+"'");
+    						} else {
+    							System.out.println("Received a duplicate Subcode :'"+actual+"'");
+    						} 
+    					} else if (actual.equals(expected2)){
+    						if (!found2){
+    							found2=true;
+    							System.out.println("Subcode= '"+actual+"'");
+    						} else {
+    							System.out.println("Received a duplicate Subcode :'"+actual+"'");
+    						} 
+
+    					} else {
+    						System.out.println("Did not receive expected Subcodes:");
+    						System.out.println("expected= '"+expected1+"' or '"+expected2+"'");
+    						System.out.println("actual= '"+actual+"'");
+    					}
+    				} else {
+    					System.out.println("A null text was returned");
+    				}
+    			} else {
+    				System.out.println("An object that is not an instance of QName was returned");
+    				System.out.println("The object is:"+o);
+    			}
+    			j++;
+    		}
+    		if (j<1){
+    			fail("No Subcode was returned");
+    		}
+    		if (j>2){
+    			fail("More than two Subcodes were returned");
+    		}
+    		if (!found1){
+    			fail("The following Subcode was not received: '"+expected1+"'");
+    		}
+    		if (!found2){
+    			fail("The following Subcode was not received: '"+expected2+"'");
+    		}
+    	} catch(Exception e) {
+    		fail("Exception: " + e);
+    	}
+    }
+    
     public void _testGetFaultReasonTexts() {
         try 
         {
@@ -397,6 +478,142 @@
         }
     }
     
+    public void testAddFaultReasonText3() {
+        try {
+        	MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+        	SOAPMessage soapMessage = fac.createMessage();
+        	SOAPPart soapPart = soapMessage.getSOAPPart();
+
+        	SOAPEnvelope envelope = soapPart.getEnvelope();
+        	SOAPBody body = envelope.getBody();
+        	SOAPFault sf = body.addFault();
+        	String expected = "Its my fault again";
+        	boolean found = false;
+        	System.out.println("Adding FaultReasonText to SOAPFault");
+        	sf.addFaultReasonText("Its my fault", Locale.ENGLISH);
+        	System.out.println("Adding another FaultReasonText to SOAPFault");
+        	sf.addFaultReasonText(expected, Locale.ENGLISH);
+        	System.out.println("Getting FaultReasonTexts from SOAPFault");
+        	Iterator i = sf.getFaultReasonTexts();
+        	int j = 0;
+        	while (i.hasNext()){	
+        		Object o = i.next();
+        		if (o instanceof String){
+        			String actual = (String)o; 
+        			if(actual != null){
+        				if (actual.equals(expected)){
+        					if (!found){
+        						found=true;
+        						System.out.println("Reason= '"+actual+"'");
+        					} else {
+        						System.out.println("Received a duplicate Reason text:'"+actual+"'");
+        					} 
+
+        				} else {
+        					System.out.println("Did not receive expected reason text:");
+        					System.out.println("expected= '"+expected+"'");
+        					System.out.println("actual= '"+actual+"'");
+
+        				}
+        			} else {
+        				System.out.println("A null text was returned");
+        			}
+        		} else {
+        			System.out.println("An object that is not an instance of String was returned");
+        			System.out.println("The object is:"+o);
+        		}
+        		j++;
+        	}
+        	if (j<1){
+        		System.out.println("No reason text was returned");
+        	}
+        	if (j>1){
+        		System.out.println("More than one reason text was returned");
+        	}
+        	if (!found){
+        		System.out.println("The following Reason text was not received: '"+expected+"'");
+        	}
+        } catch (SOAPException e) {
+            fail("Unexpected Exception Occurred : " + e);
+        }
+    }
+    
+
+    public void testAddFaultReasonText4() {
+    	try {
+    		MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		SOAPMessage soapMessage = fac.createMessage();
+    		SOAPPart soapPart = soapMessage.getSOAPPart();
+    		SOAPEnvelope envelope = soapPart.getEnvelope();
+    		SOAPBody body = envelope.getBody();
+    		SOAPFault sf = body.addFault();
+
+
+    		String expected1 = "Its my fault";
+    		String expected2 = "Its my fault again";
+    		boolean found1 = false;
+    		boolean found2 = false;
+    		System.out.println("Adding FaultReasonText to SOAPFault");
+    		sf.addFaultReasonText(expected1, Locale.UK);
+    		System.out.println("Adding another FaultReasonText to SOAPFault");
+    		sf.addFaultReasonText(expected2, Locale.ENGLISH);
+    		System.out.println("Getting FaultReasonTexts from SOAPFault");
+    		Iterator i = sf.getFaultReasonTexts();
+    		int j = 0;
+    		while (i.hasNext()){	
+    			Object o = i.next();
+    			if (o instanceof String){
+    				String actual = (String)o; 
+    				if(actual != null){
+    					if (actual.equals(expected1)){
+    						if (!found1){
+    							found1=true;
+    							System.out.println("Reason= '"+actual+"'");
+    						} else {
+    							System.out.println("Received a duplicate Reason text:'"+actual+"'");
+    						} 
+    					} else if (actual.equals(expected2)){
+    						if (!found2){
+    							found2=true;
+    							System.out.println("Reason= '"+actual+"'");
+    						} else {
+    							System.out.println("Received a duplicate Reason text:'"+actual+"'");
+    						} 
+
+    					} else {
+    						System.out.println("Did not receive expected reason text:");
+    						System.out.println("expected= '"+expected1+"' or '"+expected2+"'");
+    						System.out.println("actual= '"+actual+"'");
+    					}
+    				} else {
+    					System.out.println("A null text was returned");
+    				}
+    			} else {
+    				System.out.println("An object that is not an instance of String was returned");
+    				System.out.println("The object is:"+o);
+    			}
+    			j++;
+    		}
+    		if (j<1){
+    			System.out.println("No reason text was returned");
+    		}
+    		if (j>2){
+    			System.out.println("More than two reason texts were returned");
+    		}
+    		if (!found1){
+    			System.out.println("The following Reason text was not received: '"+expected1+"'");
+    		}
+    		if (!found2){
+    			System.out.println("The following Reason text was not received: '"+expected2+"'");
+    		}
+
+    	} catch (SOAPException e) {
+    		fail("Unexpected Exception Occurred : " + e);
+    	}
+    }
+    
+    
+    
     public void testSetFaultRole() {
         try 
         {
@@ -519,4 +736,185 @@
         }
     }    
     
+    public void testFaultReasonLocales(){
+    	try 
+    	{
+    		MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		SOAPMessage soapMessage = fac.createMessage();
+    		SOAPPart soapPart = soapMessage.getSOAPPart();
+    		SOAPEnvelope envelope = soapPart.getEnvelope();
+    		SOAPBody body = envelope.getBody();
+    		SOAPFault sf = body.addFault();
+
+    		Locale expected1 = Locale.ENGLISH;
+    		Locale expected2 = Locale.UK;
+    		Locale expected3 = Locale.GERMAN;
+    		boolean found1 = false;
+    		boolean found2 = false;
+    		boolean found3 = false;
+
+    		System.out.println("Adding FaultReasonText to SOAPFault");
+    		sf.addFaultReasonText("Its my fault1", expected1);
+    		sf.addFaultReasonText("Its my fault2", expected2);
+    		sf.addFaultReasonText("Its my fault3", expected3);
+    		System.out.println("Getting FaultReasonLocales from SOAPFault");
+    		Iterator i = sf.getFaultReasonLocales();
+
+    		int localeCount = 0;
+    		while(i.hasNext()){
+    			localeCount++;
+    			i.next();
+    		}
+    		System.out.println("Locale iterator count=" + localeCount);
+
+    		i = sf.getFaultReasonLocales();
+    		int j = 0;
+    		while (i.hasNext()){	
+    			Object o = i.next();
+    			if (o instanceof Locale){
+    				Locale actual = (Locale)o; 
+    				if(actual != null){
+    					if (actual.equals(expected1)){
+    						if (!found1){
+    							found1=true;
+    							System.out.println("Locale= '"+actual+"'");
+    						} else {
+    							System.out.println("Received a duplicate Locale:'"+actual+"'");
+    						} 
+    					} else if (actual.equals(expected2)){
+    						if (!found2){
+    							found2=true;
+    							System.out.println("Locale '"+actual+"'");
+    						} else {
+    							System.out.println("Received a duplicate Locale:'"+actual+"'");
+    						} 
+    					} else if (actual.equals(expected3)){
+    						if (!found3){
+    							found3=true;
+    							System.out.println("Locale '"+actual+"'");
+    						} else {
+    							System.out.println("Received a duplicate Locale:'"+actual+"'");
+    						} 
+    					} else {
+    						System.out.println("Did not receive expected reason text:");
+    						System.out.println("expected= '"+expected1+"' or '"+expected2+"' or '"+expected3+"'");
+    						System.out.println("actual= '"+actual+"'");
+    					}
+    				} else {
+    					System.out.println("A null text was returned");
+    				}
+    			} else {
+    				System.out.println("An object that is not an instance of Locale was returned");
+    				System.out.println("The object is:"+o);
+    			}
+    			j++;
+    		}
+    		if (j<1){
+    			System.out.println("No reason text was returned");
+    		}
+    		if (j>3){
+    			System.out.println("More than 3 Locales were returned");
+    		}
+    		if (!found1){
+    			System.out.println("The following Locale was not received: '"+expected1+"'");
+    		}
+    		if (!found2){
+    			System.out.println("The following Locale was not received: '"+expected2+"'");
+    		}
+    		if (!found3){
+    			System.out.println("The following Locale was not received: '"+expected3+"'");
+    		}
+    	} catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    	}
+    }
+    
+    public void testFaultStringLocale(){
+    	try 
+    	{
+    		MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		//MessageFactory fac = MessageFactory.newInstance();
+    		SOAPMessage soapMessage = fac.createMessage();
+    		SOAPPart soapPart = soapMessage.getSOAPPart();
+    		SOAPEnvelope envelope = soapPart.getEnvelope();
+    		SOAPBody body = envelope.getBody();
+    		SOAPFault sf = body.addFault();
+
+    		System.out.println("Setting fault string with no Locale");
+    		sf.setFaultString("this is the fault string");
+
+    		System.out.println("calling getFaultStringLocale()");
+    		Locale result=sf.getFaultStringLocale();
+    		if (result == null) {
+    			System.out.println("null Locale returned (expected)");
+    		} else {
+    			System.out.println("getFaultStringLocale() returned a non-null result");
+    			System.out.println("result="+result);
+    		}
+    	} catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    	}
+    }
+    
+    
+    public void testFaultStringLocale2(){
+    	try 
+    	{
+    		MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		//MessageFactory fac = MessageFactory.newInstance();
+    		SOAPMessage soapMessage = fac.createMessage();
+    		SOAPPart soapPart = soapMessage.getSOAPPart();
+    		SOAPEnvelope envelope = soapPart.getEnvelope();
+    		SOAPBody body = envelope.getBody();
+    		SOAPFault sf = body.addFault();
+
+    		System.out.println("Setting fault string with no Locale");
+    		sf.setFaultString("this is the fault string");
+
+    		System.out.println("calling getFaultStringLocale()");
+    		Locale result=sf.getFaultStringLocale();
+    		if (result == null) {
+    			System.out.println("null Locale returned (unexpected)");
+    		} else {
+    			System.out.println("getFaultStringLocale() returned a non-null result (expected)");
+    			System.out.println("result="+result);
+    			if(!result.equals(Locale.getDefault())) {
+    				System.out.println("Got: "+ result + ", Expected: " + Locale.getDefault());
+    			}
+    		} 
+    	}
+    	catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    	}
+    }
+    
+    public void testSetFaultStringLocale(){
+    	try {
+    		MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		//MessageFactory fac = MessageFactory.newInstance();
+    		SOAPMessage soapMessage = fac.createMessage();
+    		SOAPPart soapPart = soapMessage.getSOAPPart();
+    		SOAPEnvelope envelope = soapPart.getEnvelope();
+    		SOAPBody body = envelope.getBody();
+    		SOAPFault sf = body.addFault();
+
+    		Locale expected = Locale.ENGLISH;
+    		System.out.println("Setting fault string to Locale " + expected );
+    		sf.setFaultString("this is the fault string", expected );
+
+    		System.out.println("calling getFaultStringLocale()");
+    		Locale result=sf.getFaultStringLocale();
+    		if (result != null){
+    			if (!result.equals(expected)){
+    				System.out.println("setFaultString(string,Locale)/getFaultStringLocale behaved incorrectly");
+    				System.out.println("expected="+expected);
+    			}
+    			System.out.println("result="+result);
+    		} else {
+    			System.out.println("getFaultStringLocale() returned a null result, eventhough the fault string has a locale");
+    		}
+    	} catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    	}
+    }
 }

Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPHeaderTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPHeaderTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPHeaderTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPHeaderTest.java Wed Jan 31 12:35:21 2007
@@ -15,18 +15,24 @@
  */
 package org.apache.axis2.saaj;
 
-import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.Iterator;
 
+import javax.xml.namespace.QName;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.Name;
 import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFactory;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPHeaderElement;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
-import java.util.Iterator;
+
+import junit.framework.TestCase;
 
 public class SOAPHeaderTest extends TestCase {
     private MessageFactory mf = null;
@@ -41,7 +47,7 @@
         super(name);
     }
 
-    public void testAddHeaderElements() throws Exception {
+    public void _testAddHeaderElements() throws Exception {
         javax.xml.soap.SOAPMessage soapMessage =
                 javax.xml.soap.MessageFactory.newInstance().createMessage();
         javax.xml.soap.SOAPEnvelope soapEnv =
@@ -202,4 +208,194 @@
             fail("Unexpected Exception: " + e);
         }
     }
-}
+    
+    public void testAddNotUnderstoodHeaderElement() throws Exception {
+        javax.xml.soap.SOAPMessage soapMessage =
+                javax.xml.soap.MessageFactory.newInstance(
+                		SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
+        
+        javax.xml.soap.SOAPEnvelope soapEnv =
+                soapMessage.getSOAPPart().getEnvelope();
+        javax.xml.soap.SOAPHeader header = soapEnv.getHeader();
+        
+	    SOAPElement soapElement = header.addNotUnderstoodHeaderElement(
+	    		new QName("http://foo.org", "foo", "f"));
+	    
+        assertNotNull(soapElement);
+	        Name name = soapElement.getElementName();
+	        System.out.println("URI = " + name.getURI());
+	        System.out.println("QualifiedName = " + name.getQualifiedName());
+	        System.out.println("Prefix = " + name.getPrefix());
+	        System.out.println("LocalName = " + name.getLocalName());
+	        String uri = name.getURI();
+	        String localName = name.getLocalName();
+	        System.out.println("Validate the URI which must be " 
+		    + SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE);
+	        
+	        assertEquals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, uri);
+	        System.out.println(
+	        		"Validate the LocalName which must be NotUnderstood");
+	        assertEquals("NotUnderstood", localName);
+    }
+
+    
+    public void testAddUpgradeHeaderElement() throws Exception {
+    	javax.xml.soap.SOAPMessage soapMessage =
+    		javax.xml.soap.MessageFactory.newInstance(
+    				SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
+
+    	javax.xml.soap.SOAPEnvelope soapEnv =
+    		soapMessage.getSOAPPart().getEnvelope();
+    	javax.xml.soap.SOAPHeader header = soapEnv.getHeader();
+
+    	// create a list of supported URIs.
+    	ArrayList supported = new ArrayList();
+    	supported.add(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE);
+    	supported.add(SOAPConstants.URI_NS_SOAP_ENVELOPE);
+
+    	System.out.println("Creating Upgrade SOAPHeaderElement");
+    	SOAPElement soapElement = header.addUpgradeHeaderElement(supported.iterator());
+
+    	System.out.println("Validating SOAPHeaderElement object creation");
+    	assertNotNull(soapElement);
+    	System.out.println("SOAPHeaderElement was created");
+
+    	System.out.println("Validating Upgrade SOAPHeaderElement Name");
+    	System.out.println("Get the ElementName");
+    	Name name = soapElement.getElementName();
+    	System.out.println("URI = " + name.getURI());
+    	System.out.println("QualifiedName = " + name.getQualifiedName());
+    	System.out.println("Prefix = " + name.getPrefix());
+    	System.out.println("LocalName = " + name.getLocalName());
+    	String uri = name.getURI();
+    	String localName = name.getLocalName();
+    	System.out.println("Validate the URI which must be "
+    			+ SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE);
+
+    	assertTrue(uri.equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE));
+
+    	System.out.println("Validate the LocalName which must be Upgrade");
+    	assertTrue(localName.equals("Upgrade"));
+    }
+
+    public void testExamineHeaderElements() throws Exception {
+    	javax.xml.soap.SOAPMessage soapMessage =
+    		javax.xml.soap.MessageFactory.newInstance(
+    				SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
+
+    	javax.xml.soap.SOAPEnvelope soapEnv =
+    		soapMessage.getSOAPPart().getEnvelope();
+    	javax.xml.soap.SOAPHeader header = soapEnv.getHeader();
+
+    	System.out.println("Creating SOAPHeaderElement 1");
+    	SOAPHeaderElement soapHeaderElement = header.addHeaderElement(envelope.createName("foo1", "f1", "foo1-URI"));
+
+    	Iterator iterator = null;
+    	System.out.println("Set the role associated with SOAPHeaderElement");
+    	soapHeaderElement.setRole("role-URI");
+
+    	System.out.println("Examing SOAPHeaderElements with role of role1-URI");
+    	iterator = header.examineHeaderElements("role1-URI");
+
+    	int count=0;
+    	while (iterator.hasNext()) {
+    		count++;
+    		iterator.next();
+    	}
+
+    	assertEquals(0, count);
+    	System.out.println("SOAPHeaderElement count mismatch: expected 0, received " + count);
+
+    }
+    
+    /*
+     * examineHeaderElementsTest4
+     */
+    public void testExamineHeaderElements2() 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();
+    	SOAPHeaderElement soapHeaderElement = null;
+
+    	try{
+    		// Add some soap header elements
+    		System.out.println("Add SOAP HeaderElement Header1");
+    		SOAPElement se = header.addHeaderElement(
+    				envelope.createName("Header1", "prefix", "http://myuri"))
+    				.addTextNode("This is Header1");
+    		soapHeaderElement = (SOAPHeaderElement) se;
+    		soapHeaderElement.setMustUnderstand(true);
+
+    		System.out.println("Add SOAP HeaderElement Header2");
+    		se = header.addHeaderElement(
+    				envelope.createName("Header2", "prefix", "http://myuri"))
+    				.addTextNode("This is Header2");
+    		soapHeaderElement = (SOAPHeaderElement) se;
+    		soapHeaderElement.setMustUnderstand(false);
+
+    		System.out.println("Add SOAP HeaderElement Header3");
+    		se = header.addHeaderElement(
+    				envelope.createName("Header3", "prefix", "http://myuri"))
+    				.addTextNode("This is Header3");
+    		soapHeaderElement = (SOAPHeaderElement) se;
+    		soapHeaderElement.setMustUnderstand(true);
+
+    		System.out.println("Add SOAP HeaderElement Header4");
+    		se = header.addHeaderElement(
+    				envelope.createName("Header4", "prefix", "http://myuri"))
+    				.addTextNode("This is Header4");
+    		soapHeaderElement = (SOAPHeaderElement) se;
+    		soapHeaderElement.setMustUnderstand(false);
+
+    		System.out.println("Examing all SOAPHeaderElements");
+    		Iterator iterator = header.examineAllHeaderElements();
+
+    		System.out.println("Validating Iterator count .... should be 4");
+    		int cnt=0;
+    		while (iterator.hasNext()) {
+    			cnt++;
+    			soapHeaderElement = (SOAPHeaderElement)iterator.next();
+    		}
+    		if (cnt != 4) {
+    			fail("SOAPHeaderElement count mismatch: expected 4, received " + cnt);
+    		}
+
+    		System.out.println("Examing SOAPHeaderElements passing actor next uri");
+    		iterator = header.examineHeaderElements(SOAPConstants.URI_SOAP_ACTOR_NEXT);
+
+    		System.out.println("Validating Iterator count .... should now be 0");
+    		cnt=0;
+    		while (iterator.hasNext()) {
+    			cnt++;
+    			soapHeaderElement = (SOAPHeaderElement)iterator.next();
+    		}
+    		if (cnt != 0) {
+    			fail("SOAPHeaderElement count mismatch: expected 0, received " + cnt);
+    		}
+
+    	} catch (Exception e) {
+    		fail("Unexpected Exception: " + e);
+    	}
+    }
+    
+    public void testQNamesOnHeader(){
+    	SOAPHeaderElement transaction = null;
+    	try {
+    		System.out.println("SOAP1.1 and SOAP1.2 requires all HeaderElements to be"
+    				+ " namespace qualified");
+    		System.out.println("Try adding HeaderElement with unqualified QName "
+    				+ "not belonging to any namespace (expect SOAPException)");
+    		System.out.println("No URI and no PREFIX in QName");
+    		transaction = 
+    			hdr.addHeaderElement(envelope.createName("Transaction"));
+    		System.out.println("Did not throw expected SOAPException");
+    	} catch (SOAPException e) {
+    		System.out.println("Did throw expected SOAPException");
+    	} catch (Exception e) {
+    		System.out.println("Unexpected Exception: " + e.getMessage());
+    	}
+    }
+}
\ No newline at end of file

Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java Wed Jan 31 12:35:21 2007
@@ -15,10 +15,28 @@
  */
 package org.apache.axis2.saaj;
 
-import junit.framework.TestCase;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Iterator;
 
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPBodyElement;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+
+import junit.framework.TestCase;
 
 /**
  * 
@@ -46,4 +64,231 @@
             fail("Unexpected Exception : " + e);
         }
     }
+    
+    public void _testGetAttachmentByHref() {
+    	String NS_PREFIX="mypre";
+    	String NS_URI="http://myuri.org/";
+
+    	try {
+    		System.out.println("Create SOAP message from message factory");
+
+    		// Message creation takes care of creating the SOAPPart - a
+    		// required part of the message as per the SOAP 1.1 spec.
+    		System.out.println("Get SOAP Part");
+    		SOAPPart sp = msg.getSOAPPart();
+
+    		// Retrieve the envelope from the soap part to start building
+    		// the soap message.
+    		System.out.println("Get SOAP Envelope");
+    		SOAPEnvelope envelope = sp.getEnvelope();
+
+    		// Create a soap header from the envelope.
+    		System.out.println("Create SOAP Header");
+    		SOAPHeader hdr = envelope.getHeader();
+
+    		// Create a soap body from the envelope.
+    		System.out.println("Create SOAP Body");
+    		SOAPBody bdy = envelope.getBody();
+
+    		// Add a soap body element
+    		System.out.println("Add SOAP BodyElement Body1");
+    		SOAPBodyElement sbe1 = bdy.addBodyElement(
+    				envelope.createName("Body1", NS_PREFIX, NS_URI));
+
+    		// Add a child element
+    		System.out.println("Add ChildElement TheGifAttachment");
+    		sbe1.addChildElement(envelope.createName(
+    				"TheGifAttachment", NS_PREFIX, NS_URI));
+    		sbe1.setAttribute("href", "cid:THEGIF");
+
+    		// Add another soap body element
+    		System.out.println("Add SOAP BodyElement Body2");
+    		SOAPBodyElement sbe2 = bdy.addBodyElement(
+    				envelope.createName("Body2", NS_PREFIX, NS_URI));
+
+    		// Add a child element
+    		System.out.println("Add ChildElement TheXmlAttachment");
+    		sbe2.addChildElement(envelope.createName(
+    				"TheXmlAttachment", NS_PREFIX, NS_URI));
+    		sbe2.setAttribute("href", "cid:THEXML");
+
+    		System.out.println("Add various mime type attachments to SOAP message");
+    		URL url1 = new URL("http://my.uri.org");
+    		URL url2 = new URL("http://my.uri.org");
+    		URL url3 = new URL("http://my.uri.org");
+    		URL url4 = new URL("http://my.uri.org");
+    		URL url5 = new URL("http://my.uri.org");
+
+    		System.out.println("Create SOAP Attachment (XML document)");
+    		System.out.println("URL1=" + url1);
+    		AttachmentPart ap1 = msg.createAttachmentPart(new DataHandler(url1));
+
+    		System.out.println("Create SOAP Attachment (GIF image)");
+    		System.out.println("URL2=" + url2);
+    		AttachmentPart ap2 = msg.createAttachmentPart(new DataHandler(url2));
+
+    		System.out.println("Create SOAP Attachment (Plain text)");
+    		System.out.println("URL3=" + url3);
+    		AttachmentPart ap3 = msg.createAttachmentPart(new DataHandler(url3));
+
+    		System.out.println("Create SOAP Attachment (HTML document)");
+    		System.out.println("URL4=" + url4);
+    		AttachmentPart ap4 = msg.createAttachmentPart(new DataHandler(url4));
+
+    		System.out.println("Create SOAP Attachment (JPEG image)");
+    		System.out.println("URL5=" + url5);
+    		AttachmentPart ap5 = msg.createAttachmentPart(new DataHandler(url5));
+
+    		ap1.setContentType("text/xml");
+    		ap1.setContentId("<THEXML>");
+    		ap2.setContentType("image/gif");
+    		ap2.setContentId("<THEGIF>");
+    		ap3.setContentType("text/plain");
+    		ap3.setContentId("<THEPLAIN>");
+    		ap4.setContentType("text/html");
+    		ap4.setContentId("<THEHTML>");
+    		ap5.setContentType("image/jpeg");
+    		ap5.setContentId("<THEJPEG>");
+
+    		// Add the attachments to the message.
+    		System.out.println(
+    		"Add SOAP Attachment (XML document) to SOAP message");
+    		msg.addAttachmentPart(ap1);
+    		System.out.println(
+    				"Add SOAP Attachment (GIF image) to SOAP message");
+    		msg.addAttachmentPart(ap2);
+    		System.out.println(
+    				"Add SOAP Attachment (Plain text) to SOAP message");
+    		msg.addAttachmentPart(ap3);
+    		System.out.println(
+    				"Add SOAP Attachment (HTML document) to SOAP message");
+    		msg.addAttachmentPart(ap4);
+    		System.out.println(
+    				"Add SOAP Attachment (JPEG image) to SOAP message");
+    		msg.addAttachmentPart(ap5);
+    		msg.saveChanges();
+    		System.out.println("Done creating SOAP message");
+
+    		System.out.println("Retrieve attachment with href=cid:THEGIF");
+    		AttachmentPart myap = msg.getAttachment(sbe1);
+    		if(myap == null) {
+    			System.out.println("Returned null (unexpected)");
+    		} else if(!myap.getContentType().equals("image/gif")) {
+    			System.out.println("Wrong attachment was returned: Got Content-Type of "
+    					+myap.getContentType()+", Expected Content-Type of image/gif");
+    		} else
+    			System.out.println("Correct attachment was returned");
+
+    		System.out.println("Retrieve attachment with href=cid:THEXML");
+    		myap = msg.getAttachment(sbe2);
+    		if(myap == null) {
+    			System.out.println("Returned null (unexpected)");
+    		} else if(!myap.getContentType().equals("text/xml")) {
+    			System.out.println("Wrong attachment was returned: Got Content-Type of "
+    					+myap.getContentType()+", Expected Content-Type of text/xml");
+    		} else
+    			System.out.println("Correct attachment was returned");
+
+    		System.out.println("Retrieve attachment with href=cid:boo-hoo (expect null)");
+    		QName myqname = new QName("boo-hoo");
+    		SOAPElement myse = SOAPFactoryImpl.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createElement(myqname);
+    		myse.addTextNode("<theBooHooAttachment href=\"cid:boo-hoo\"/>");
+    		myap = msg.getAttachment(myse);
+    		if(myap == null)
+    			System.out.println("Returned null (expected)");
+    		else {
+    			System.out.println("Returned non null (unexpected)");
+    		}
+
+    	} catch (Exception e) {
+    		fail("Unexpected Exception : " + e);
+    	}
+    }
+    
+    
+    
+    //TODO : sumedha complete
+    public void testRemoveAttachements(){
+    	Iterator iterator = null;
+        AttachmentPart ap1 = null;
+        AttachmentPart ap2 = null;
+        AttachmentPart ap3 = null;
+    	
+    	try 
+    	{
+    		MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+    		//MessageFactory fac = MessageFactory.newInstance();
+    		SOAPMessage msg = fac.createMessage();
+    		SOAPPart soapPart = msg.getSOAPPart();
+    		SOAPEnvelope envelope = soapPart.getEnvelope();
+    		SOAPBody body = envelope.getBody();
+    		SOAPFault sf = body.addFault();
+
+    		
+    		InputStream in1 = new FileInputStream(new File("test-resources" + File.separator + "attach.xml"));
+    		ap1 = msg.createAttachmentPart(in1, "text/xml");
+            msg.addAttachmentPart(ap1);
+
+    		InputStream in2 = new FileInputStream(new File("test-resources" + File.separator + "axis2.xml"));
+    		ap2 = msg.createAttachmentPart(in2, "text/xml");
+            msg.addAttachmentPart(ap2);
+
+    		InputStream in3 = new FileInputStream(new File("test-resources" + File.separator + "axis2.xml"));
+    		ap3 = msg.createAttachmentPart(in3, "text/plain");
+            msg.addAttachmentPart(ap3);
+    		
+    		
+    		System.out.println("get all attachments");
+    		iterator = msg.getAttachments();
+
+    		int cnt = 0;
+    		while(iterator.hasNext()){
+    			cnt++;
+    			iterator.next();
+    		}
+
+    		System.out.println("number of attachments: " + cnt);
+
+    		if (cnt != 3) {
+    			System.out.println("only 3 attachments was added, count not correct");
+    		}else{
+    			System.out.println("3 attachments exist as expected");
+    		}
+
+    		System.out.println("remove just the text/xml attachments which are 2");
+    		MimeHeaders mhs = new MimeHeaders();
+    		mhs.addHeader("Content-Type", "text/xml");
+    		msg.removeAttachments(mhs);
+
+    		System.out.println("get all attachments");
+    		iterator = msg.getAttachments();
+
+    		cnt = 0;
+    		iterator = msg.getAttachments();
+
+    		while(iterator.hasNext()){
+    			cnt++;
+    			iterator.next();
+    		}
+    		System.out.println("number of attachments: " + cnt);
+
+    		if (cnt > 1) {
+    			System.out.println("the 2 text/xml attachments were not removed (unexpected)");
+    		} else if(cnt == 1) {
+    			iterator = msg.getAttachments();
+    			AttachmentPart ap = (AttachmentPart) iterator.next();
+    			String ctype = ap.getContentType();
+    			System.out.println("Content-Type of remaining attachment is: "+ctype);
+    			if(ctype.equals("text/xml")) {
+    				System.out.println("one of the text/xml attachments was not removed");
+    			}
+    		} else {
+    			System.out.println("all attachments were removed (unexpected)");
+    		}
+
+    	} catch(Exception e) {
+    		System.out.println("Exception: " + e);
+    	}
+    }
 }
+

Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPNamespaceTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPNamespaceTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPNamespaceTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPNamespaceTest.java Wed Jan 31 12:35:21 2007
@@ -16,11 +16,11 @@
 
 package org.apache.axis2.saaj;
 
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.SOAPMessage;
-
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
 
 import junit.framework.TestCase;
 

Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java Wed Jan 31 12:35:21 2007
@@ -15,9 +15,10 @@
  */
 package org.apache.axis2.saaj;
 
-import junit.framework.TestCase;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.util.Iterator;
 
 import javax.activation.DataHandler;
 import javax.xml.parsers.DocumentBuilder;
@@ -33,10 +34,11 @@
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamSource;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
 
 /**
  * 
@@ -94,8 +96,8 @@
             assertEquals("soapenv", header.getPrefix());
 
             Node firstChild = header.getFirstChild();
-//            assertEquals("Hello", firstChild.getLocalName());
-//            assertEquals("shw", firstChild.getPrefix());
+            //assertEquals("Hello", firstChild.getLocalName());
+            //assertEquals("shw", firstChild.getPrefix());
 
             SOAPBody body = envelope.getBody();
             assertEquals("Body", body.getLocalName());

Modified: webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/TextTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/TextTest.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/TextTest.java (original)
+++ webservices/axis2/branches/java/maven2/modules/saaj/test/org/apache/axis2/saaj/TextTest.java Wed Jan 31 12:35:21 2007
@@ -16,9 +16,8 @@
 
 package org.apache.axis2.saaj;
 
-import junit.framework.TestCase;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
 
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.MimeHeaders;
@@ -30,8 +29,11 @@
 import javax.xml.soap.SOAPFactory;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.Text;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 public class TextTest extends TestCase {
 

Modified: webservices/axis2/branches/java/maven2/modules/samples/project.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/samples/project.xml?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/samples/project.xml (original)
+++ webservices/axis2/branches/java/maven2/modules/samples/project.xml Wed Jan 31 12:35:21 2007
@@ -277,6 +277,14 @@
                     <include>**/*.jpg</include>
                 </includes>
             </resource>
+            			   <resource>
+        <directory>../../</directory>
+        <targetPath>META-INF</targetPath>
+        <includes>
+          <include>NOTICE.txt</include>
+        <include>LICENSE.txt</include>
+      </includes>
+   </resource>
         </resources>
     </build>
 

Modified: webservices/axis2/branches/java/maven2/modules/savan/project.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/savan/project.xml?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/savan/project.xml (original)
+++ webservices/axis2/branches/java/maven2/modules/savan/project.xml Wed Jan 31 12:35:21 2007
@@ -170,6 +170,17 @@
             </properties>
         </dependency>
     </dependencies>
-
+    <build>
+    <resources>
+			   <resource>
+        <directory>../../</directory>
+        <targetPath>META-INF</targetPath>
+        <includes>
+          <include>NOTICE.txt</include>
+        <include>LICENSE.txt</include>
+      </includes>
+   </resource>
+		</resources>
+		</build>
     <reports/>
 </project>

Modified: webservices/axis2/branches/java/maven2/modules/secpolicy/project.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/secpolicy/project.xml?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/secpolicy/project.xml (original)
+++ webservices/axis2/branches/java/maven2/modules/secpolicy/project.xml Wed Jan 31 12:35:21 2007
@@ -86,6 +86,16 @@
                 <include>**/*Test.java</include>
             </includes>
         </unitTest>
+         <resources>
+        			   <resource>
+        <directory>../../</directory>
+        <targetPath>META-INF</targetPath>
+        <includes>
+          <include>NOTICE.txt</include>
+        <include>LICENSE.txt</include>
+      </includes>
+   </resource>
+    </resources>
 	</build>
     <reports/>
 </project>

Modified: webservices/axis2/branches/java/maven2/modules/secpolicy/src/org/apache/ws/secpolicy/model/SymmetricBinding.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/secpolicy/src/org/apache/ws/secpolicy/model/SymmetricBinding.java?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/secpolicy/src/org/apache/ws/secpolicy/model/SymmetricBinding.java (original)
+++ webservices/axis2/branches/java/maven2/modules/secpolicy/src/org/apache/ws/secpolicy/model/SymmetricBinding.java Wed Jan 31 12:35:21 2007
@@ -32,11 +32,11 @@
 public class SymmetricBinding extends SymmetricAsymmetricBindingBase {
 
     private EncryptionToken encryptionToken;
-    
+
     private SignatureToken signatureToken;
-    
+
     private ProtectionToken protectionToken;
-    
+
     /**
      * @return Returns the encryptionToken.
      */
@@ -91,7 +91,7 @@
         }
         this.signatureToken = signatureToken;
     }
-    
+
     public QName getName() {
         return Constants.SYMMETRIC_BINDING;
     }
@@ -100,28 +100,28 @@
         if (isNormalized()) {
             return this;
         }
-        
+
         AlgorithmSuite algorithmSuite = getAlgorithmSuite();
         List configurations = algorithmSuite.getConfigurations();
-        
+
         if (configurations == null && configurations.size() == 1) {
             setNormalized(true);
             return this;
         }
-        
+
         Policy policy = new Policy();
         ExactlyOne exactlyOne = new ExactlyOne();
-        
+
         All wrapper;
         SymmetricBinding symmetricBinding;
-        
+
         for (Iterator iterator = configurations.iterator(); iterator.hasNext();) {
             wrapper = new All();
             symmetricBinding = new SymmetricBinding();
-            
+
             algorithmSuite = (AlgorithmSuite) iterator.next();
             symmetricBinding.setAlgorithmSuite(algorithmSuite);
-            
+
             symmetricBinding.setEncryptionToken(getEncryptionToken());
             symmetricBinding.setEntireHeadersAndBodySignatures(isEntireHeadersAndBodySignatures());
             symmetricBinding.setIncludeTimestamp(isIncludeTimestamp());
@@ -133,24 +133,24 @@
             symmetricBinding.setSignedEndorsingSupportingTokens(getSignedEndorsingSupportingTokens());
             symmetricBinding.setSignedSupportingToken(getSignedSupportingToken());
             symmetricBinding.setTokenProtection(isTokenProtection());
-            
+
             symmetricBinding.setNormalized(true);
             wrapper.addPolicyComponent(symmetricBinding);
             exactlyOne.addPolicyComponent(wrapper);
         }
-        
+
         policy.addPolicyComponent(exactlyOne);
         return policy;
     }
 
     public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        
+
         String localname = Constants.SYMMETRIC_BINDING.getLocalPart();
         String namespaceURI = Constants.SYMMETRIC_BINDING.getNamespaceURI();
-        
+
         String prefix;
         String writerPrefix = writer.getPrefix(namespaceURI);
-        
+
         if (writerPrefix == null) {
             prefix = Constants.SYMMETRIC_BINDING.getPrefix();
             writer.setPrefix(prefix, namespaceURI);
@@ -160,80 +160,88 @@
 
         // <sp:SymmetricBinding>
         writer.writeStartElement(prefix, localname, namespaceURI);
-        
+
         if (writerPrefix == null) {
             // xmlns:sp=".."
             writer.writeNamespace(prefix, namespaceURI);
         }
-        
-        
+
+
         String policyLocalName = Constants.POLICY.getLocalPart();
         String policyNamespaceURI = Constants.POLICY.getNamespaceURI();
-        
+
         String wspPrefix;
-        
+
         String wspWriterPrefix = writer.getPrefix(policyNamespaceURI);
         if (wspWriterPrefix == null) {
             wspPrefix = Constants.POLICY.getPrefix();
             writer.setPrefix(wspPrefix, policyNamespaceURI);
-            
+
         } else {
            wspPrefix = wspWriterPrefix;
         }
         // <wsp:Policy>
         writer.writeStartElement(wspPrefix, policyLocalName, policyNamespaceURI);
-        
-        if (encryptionToken != null) {
-            encryptionToken.serialize(writer);
-            
-        } else if ( protectionToken != null) {
+
+        if ( protectionToken != null) {
             protectionToken.serialize(writer);
-            
+
+        } else if (encryptionToken != null &&  signatureToken != null) {
+            encryptionToken.serialize(writer);
+            signatureToken.serialize(writer);
+
         } else {
-            throw new RuntimeException("Either EncryptionToken or ProtectionToken must be set");
+            throw new RuntimeException("Either (EncryptionToken and SignatureToken) or ProtectionToken must be set");
         }
-        
+
         AlgorithmSuite algorithmSuite = getAlgorithmSuite();
-        
+
         if (algorithmSuite == null) {
             throw new RuntimeException("AlgorithmSuite must be set");
         }
         // <sp:AlgorithmSuite />
         algorithmSuite.serialize(writer);
-        
+
         Layout layout = getLayout();
         if (layout != null) {
             // <sp:Layout />
             layout.serialize(writer);
         }
-        
+
         if (isIncludeTimestamp()) {
             // <sp:IncludeTimestamp />
             writer.writeStartElement(prefix, Constants.INCLUDE_TIMESTAMP.getLocalPart(), namespaceURI);
             writer.writeEndElement();
         }
-        
-        if (Constants.ENCRYPT_BEFORE_SIGNING.equals(protectionToken)) {
+
+        if (Constants.ENCRYPT_BEFORE_SIGNING.equals(getProtectionOrder())) {
             // <sp:EncryptBeforeSigning />
             writer.writeStartElement(prefix, Constants.ENCRYPT_BEFORE_SIGNING, namespaceURI);
             writer.writeEndElement();
+
+        } else if (Constants.SIGN_BEFORE_ENCRYPTING.equals(getProtectionOrder())) {
+            // <sp:SignBeforeEncrypt />
+            writer.writeStartElement(prefix, Constants.SIGN_BEFORE_ENCRYPTING, namespaceURI);
+            writer.writeEndElement();
         }
-        
+
         if (isSignatureProtection()) {
             // <sp:EncryptSignature />
             writer.writeStartElement(prefix, Constants.ENCRYPT_SIGNATURE.getLocalPart(), namespaceURI);
             writer.writeEndElement();
         }
-        
-        if (protectionToken != null) {
-            protectionToken.serialize(writer);
+
+        if (isEntireHeadersAndBodySignatures()) {
+            // <sp:OnlySignEntireHeadersAndBody />
+            writer.writeStartElement(prefix, Constants.ONLY_SIGN_ENTIRE_HEADERS_AND_BODY, namespaceURI);
+            writer.writeEndElement();
         }
         
         // </wsp:Policy>
         writer.writeEndElement();
-        
+
         // </sp:SymmetricBinding>
         writer.writeEndElement();
-        
+
     }
 }

Modified: webservices/axis2/branches/java/maven2/modules/security/project.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/maven2/modules/security/project.xml?view=diff&rev=501978&r1=501977&r2=501978
==============================================================================
--- webservices/axis2/branches/java/maven2/modules/security/project.xml (original)
+++ webservices/axis2/branches/java/maven2/modules/security/project.xml Wed Jan 31 12:35:21 2007
@@ -243,7 +243,7 @@
 		</properties>
 	</dependency>
 	<dependency>
-            <groupId>incubator-woden</groupId>
+            <groupId>org.apache.woden</groupId>
             <artifactId>woden</artifactId>
             <version>${woden.version}</version>
             <properties>



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message