You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by az...@apache.org on 2007/02/05 13:14:08 UTC

svn commit: r503658 [2/2] - in /webservices/axis2/trunk/java/modules/saaj: src/org/apache/axis2/saaj/ test-resources/ test/org/apache/axis2/saaj/ test/org/apache/axis2/saaj/integration/

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java?view=diff&rev=503658&r1=503657&r2=503658
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java Mon Feb  5 04:14:07 2007
@@ -60,35 +60,27 @@
     		if(sf == null) {
     			fail("createElementTest4() could not create SOAPFactory object");
     		}
-    		System.out.println("Create QName object with localName=MyName1, " +
-    		"prefix=MyPrefix1, uri=MyUri1");
+    		//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)");
-    			}
-    		} 
+    		assertNotNull(se);
+    		name = se.getElementQName();
+    		String localName = name.getLocalPart();
+    		String prefix = name.getPrefix();
+    		String uri = name.getNamespaceURI();
+    		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();
@@ -109,22 +101,14 @@
     	    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)");
+    	    //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="+
+    	    		se.getNamespaceURI())) {
+    		//Node names are not equal
+    		fail("Got: <URI="+se.getNamespaceURI()+", PREFIX="+
+    			se.getPrefix()+", NAME="+se.getNodeName()+">"+
+    			"Expected: <URI="+de.getNamespaceURI()+", PREFIX="+
     			de.getPrefix()+", NAME="+de.getNodeName()+">");
     	    }
     	} catch(Exception e) {
@@ -155,36 +139,19 @@
     		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)");
+    		//Create second SOAPElement from first 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)");
+    			fail("The SOAPElement's are not equal and not the same (unexpected)");
     		}
-
-    		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="+
+    			fail("Got: <URI="+se1.getNamespaceURI()+", PREFIX="+
+    					se1.getPrefix()+", NAME="+se1.getNodeName()+">"+
+    					"Expected: <URI="+se2.getNamespaceURI()+", PREFIX="+
     					se2.getPrefix()+", NAME="+se2.getNodeName()+">");
     		}	
     	} catch(Exception e) {
@@ -196,36 +163,25 @@
     	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");
-    		}
+    		assertNotNull(sf);
+    		assertTrue(sf instanceof SOAPFault);
     		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);
+    		//Expect FaultCode="+SOAPConstants.SOAP_RECEIVER_FAULT
     		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");
+    		while(i.hasNext()) {
+    			reason += (String)i.next();
     		}
+    		assertNotNull(reason);
+    		assertTrue(reason.contains("This is the fault reason."));
+    		assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
     	} catch(SOAPException e) {
-    		System.out.println("Caught unexpected SOAPException");
+    		fail("Caught unexpected SOAPException");
     	}
     }
     
@@ -234,39 +190,24 @@
     	{
     		//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");
-    		}
+    		assertNotNull(sf);
     		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");
+    		while(i.hasNext()){
+    			reason += (String)i.next();
     		}
-    		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");
+    		System.out.println("Actual ReasonText="+reason);
+    		assertNotNull(reason);
+    		assertTrue(reason.contains("This is the fault reason."));
+    		assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
+    	} catch(UnsupportedOperationException e) {
+    		//Caught expected UnsupportedOperationException
     	} catch(Exception e) {
-    		System.out.println("Exception: " + e);
+    		fail("Exception: " + e);
     	}
     }
     
@@ -276,20 +217,16 @@
     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.",  
+    		SOAPFault fault = factory.createFault("This is the fault reason.",  
     				new QName("http://MyNamespaceURI.org/", "My Fault Code"));
     	} catch(UnsupportedOperationException e) {
-    		System.out.println("Caught expected UnsupportedOperationException");
+    		//Caught expected UnsupportedOperationException
     	} catch(SOAPException e) {
-    		System.out.println("Caught expected SOAPException");
+    		//Caught expected SOAPException
     	} catch(IllegalArgumentException e) {
-    		System.out.println("Caught expected IllegalArgumentException");
+    		//Caught expected IllegalArgumentException
     	} catch(Exception e) {
-    		System.out.println("Exception: " + e);
+    		fail("Exception: " + e);
     	}    	
     }
 
@@ -299,21 +236,17 @@
     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");
+    		fail("Did not throw expected SOAPException");
     	} catch(UnsupportedOperationException e) {
-    		System.out.println("Caught expected UnsupportedOperationException");
+    		//Caught expected UnsupportedOperationException
     	} catch(SOAPException e) {
-    		System.out.println("Caught expected SOAPException");
+    		//Caught expected SOAPException
     	} catch(IllegalArgumentException e) {
-    		System.out.println("Caught expected IllegalArgumentException");
+    		//Caught expected IllegalArgumentException
     	} catch(Exception e) {
-    		System.out.println("Exception: " + e);
+    		fail("Exception: " + e);
     	}    	
     }
 }

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java?view=diff&rev=503658&r1=503657&r2=503658
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java Mon Feb  5 04:14:07 2007
@@ -148,7 +148,6 @@
         soapMessage.writeTo(baos);
         String xml = new String(baos.toByteArray());
 
-        System.out.println(xml);
         assertTrue(xml.indexOf("<faultcode>Client</faultcode>") != -1);
         assertTrue(xml.indexOf("<faultstring>CWMP fault</faultstring>") != -1);
         assertTrue(xml.indexOf("<faultactor>http://gizmos.com/order</faultactor>") != -1);
@@ -229,11 +228,7 @@
             entry2.addTextNode("Incomplete address: " + "no zip code");
 
             message.saveChanges();
-
-            System.out.println("Here is what the XML message looks like:");
-            message.writeTo(System.out);
-            System.out.println();
-            System.out.println();
+            //message.writeTo(System.out);
 
             // Now retrieve the SOAPFault object and
             // its contents, after checking to see that
@@ -242,22 +237,9 @@
                 SOAPFault newFault = body.getFault();
 
                 // Get the qualified name of the fault code
-                Name code = newFault.getFaultCodeAsName();
-
-                String string = newFault.getFaultString();
-                String actor = newFault.getFaultActor();
-
-                System.out.println("SOAP fault contains: ");
-                System.out.println("  Fault code = " + code.getQualifiedName());
-                System.out.println("  Local name = " + code.getLocalName());
-                System.out.println("  Namespace prefix = " + code.getPrefix() +
-                                   ", bound to " + code.getURI());
-                System.out.println("  Fault string = " + string);
-
-                if (actor != null) {
-                    System.out.println("  Fault actor = " + actor);
-                }
-
+                assertNotNull(newFault.getFaultCodeAsName());
+                assertNotNull(newFault.getFaultString());
+                assertNotNull(newFault.getFaultActor());
                 Detail newDetail = newFault.getDetail();
 
                 if (newDetail != null) {
@@ -266,12 +248,11 @@
                     while (entries.hasNext()) {
                         DetailEntry newEntry = (DetailEntry) entries.next();
                         String value = newEntry.getValue();
-                        System.out.println("  Detail entry = " + value);
+                        assertNotNull(value);
                     }
                 }
             }
         } catch (Exception e) {
-            e.printStackTrace();
             fail("Unexpected Exception : " + e);
         }
     }
@@ -280,7 +261,6 @@
         try {
             SOAPMessage msg = MessageFactory.newInstance().createMessage();
             SOAPFault sf = msg.getSOAPBody().addFault();
-
             sf.setFaultActor("/faultActorURI");
             sf.setFaultActor("/faultActorURI2");
             String result = sf.getFaultActor();
@@ -354,12 +334,12 @@
     		boolean found1 = false;
     		boolean found2 = false;
 
-    		System.out.println("Appending fault Subcode");
+    		//Appending fault Subcode
     		sf.appendFaultSubcode(expected1);
-    		System.out.println("Appending a second fault Subcode");
+    		//Appending a second fault Subcode
     		sf.appendFaultSubcode(expected2);
 
-    		System.out.println("Getting FaultSubCodes from SOAPFault");
+    		//Getting FaultSubCodes from SOAPFault
     		Iterator i = sf.getFaultSubcodes();
     		int j = 0;
     		while (i.hasNext()){	
@@ -370,30 +350,20 @@
     					if (actual.equals(expected1)){
     						if (!found1){
     							found1=true;
-    							System.out.println("Subcode= '"+actual+"'");
+    							//System.out.println("Subcode= '"+actual+"'");
     						} else {
-    							System.out.println("Received a duplicate Subcode :'"+actual+"'");
+    							//System.out.println("Received a duplicate Subcode :'"+actual+"'");
     						} 
     					} else if (actual.equals(expected2)){
     						if (!found2){
     							found2=true;
-    							System.out.println("Subcode= '"+actual+"'");
+    							//System.out.println("Subcode= '"+actual+"'");
     						} else {
-    							System.out.println("Received a duplicate Subcode :'"+actual+"'");
+    							//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){
@@ -426,14 +396,13 @@
             SOAPBody body = envelope.getBody();
             SOAPFault soapFault = body.addFault();
             soapFault.addFaultReasonText("myReason", new Locale("en"));
-            System.out.println("Adding second text");
             soapFault.addFaultReasonText("de-myReason", new Locale("de"));
             soapFault.addFaultReasonText("si-myReason", new Locale("si"));            
             soapMessage.saveChanges();
             Iterator reasonTexts = soapFault.getFaultReasonTexts(); 
             while(reasonTexts.hasNext()){
             	String reasonText = (String)reasonTexts.next();
-            	System.out.println(reasonText);
+            	assertNotNull(reasonText);
             }
             
         } catch (Exception e) {
@@ -489,11 +458,8 @@
         	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()){	
@@ -504,34 +470,20 @@
         				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");
+        		fail("No reason text was returned");
         	}
         	if (j>1){
-        		System.out.println("More than one reason text was returned");
+        		fail("More than one reason text was returned");
         	}
         	if (!found){
-        		System.out.println("The following Reason text was not received: '"+expected+"'");
+        		fail("The following Reason text was not received: '"+expected+"'");
         	}
         } catch (SOAPException e) {
             fail("Unexpected Exception Occurred : " + e);
@@ -553,11 +505,8 @@
     		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()){	
@@ -568,45 +517,28 @@
     					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)){
+    						}
+    					}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");
+    			fail("No reason text was returned");
     		}
     		if (j>2){
-    			System.out.println("More than two reason texts were returned");
+    			fail("More than two reason texts were returned");
     		}
     		if (!found1){
-    			System.out.println("The following Reason text was not received: '"+expected1+"'");
+    			fail("The following Reason text was not received: '"+expected1+"'");
     		}
     		if (!found2){
-    			System.out.println("The following Reason text was not received: '"+expected2+"'");
+    			fail("The following Reason text was not received: '"+expected2+"'");
     		}
-
     	} catch (SOAPException e) {
     		fail("Unexpected Exception Occurred : " + e);
     	}
@@ -626,8 +558,6 @@
             envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
             SOAPBody body = envelope.getBody();
             SOAPFault soapFault = body.addFault();
-            //soapFault.setFaultCode("mycode");
-
             soapFault.setFaultRole("test");
             soapMessage.saveChanges();
 
@@ -777,55 +707,37 @@
     					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");
+    			fail("No reason text was returned");
     		}
     		if (j>3){
-    			System.out.println("More than 3 Locales were returned");
+    			fail("More than 3 Locales were returned");
     		}
     		if (!found1){
-    			System.out.println("The following Locale was not received: '"+expected1+"'");
+    			fail("The following Locale was not received: '"+expected1+"'");
     		}
     		if (!found2){
-    			System.out.println("The following Locale was not received: '"+expected2+"'");
+    			fail("The following Locale was not received: '"+expected2+"'");
     		}
     		if (!found3){
-    			System.out.println("The following Locale was not received: '"+expected3+"'");
+    			fail("The following Locale was not received: '"+expected3+"'");
     		}
     	} catch(Exception e) {
-    		System.out.println("Exception: " + e);
+    		fail("Exception: " + e);
     	}
     }
     
@@ -840,19 +752,12 @@
     		SOAPBody body = envelope.getBody();
     		SOAPFault sf = body.addFault();
 
-    		System.out.println("Setting fault string with no Locale");
+    		//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);
-    		}
+    		assertNotNull(result);
     	} catch(Exception e) {
-    		System.out.println("Exception: " + e);
+    		fail("Exception: " + e);
     	}
     }
     
@@ -868,23 +773,13 @@
     		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());
-    			}
-    		} 
+    		assertNotNull(result);
+    		assertTrue(result.equals(Locale.getDefault()));
     	}
     	catch(Exception e) {
-    		System.out.println("Exception: " + e);
+    		fail("Exception: " + e);
     	}
     }
     
@@ -899,22 +794,12 @@
     		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");
-    		}
+    		assertNotNull(result);
+    		assertTrue(result.equals(expected));
     	} catch(Exception e) {
-    		System.out.println("Exception: " + e);
+    		fail("Exception: " + e);
     	}
     }
 }

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPHeaderTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPHeaderTest.java?view=diff&rev=503658&r1=503657&r2=503658
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPHeaderTest.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPHeaderTest.java Mon Feb  5 04:14:07 2007
@@ -47,42 +47,46 @@
         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 =
                 soapMessage.getSOAPPart().getEnvelope();
         javax.xml.soap.SOAPHeader header = soapEnv.getHeader();
-        assertTrue(header.addChildElement("ebxmlms1") instanceof SOAPHeaderElement);
-        assertTrue(header.addChildElement("ebxmlms2", "ch2", "http;//test.apache.org") instanceof SOAPHeaderElement);
-        assertTrue(header.addHeaderElement(soapEnv.createName("ebxmlms3", "ch3", "http://test2.apache.org")) != null);
-        assertTrue(header.addHeaderElement(soapEnv.createName("ebxmlms4")) != null);
-        assertTrue(header.addHeaderElement(new PrefixedQName("http://test3.apache.org", "ebxmlms5", "ch5")) != null);
+        try{
+        	header.addChildElement("ebxmlms1");
+        }catch(Exception e){
+        	assertTrue(e instanceof SOAPException);
+        }
+
+        assertTrue(header.addChildElement("ebxmlms1", "ns-prefix", "http://test.apache.org") instanceof SOAPHeaderElement);
+        ((SOAPHeaderElement)header.getFirstChild()).addTextNode("test add");
+        
+
+        assertTrue(header.addHeaderElement(soapEnv.createName("ebxmlms2", "ns-prefix", "http://test2.apache.org")) != null);
+        assertTrue(header.addHeaderElement(new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ns-prefix")) != null);
+        
+
 
         SOAPHeaderElement firstChild = (SOAPHeaderElement) header.getFirstChild();
         assertEquals("ebxmlms1", firstChild.getLocalName());
-        assertEquals("", firstChild.getPrefix());
-        assertEquals("", firstChild.getNamespaceURI());
+        assertEquals("ns-prefix", firstChild.getPrefix());
+        assertEquals("http://test.apache.org", firstChild.getNamespaceURI());
 
         SOAPHeaderElement secondChild = (SOAPHeaderElement) firstChild.getNextSibling();
         assertEquals("ebxmlms2", secondChild.getLocalName());
-        assertEquals("ch2", secondChild.getPrefix());
-        assertEquals("http;//test.apache.org", secondChild.getNamespaceURI());
-
-        SOAPHeaderElement thirdChild = (SOAPHeaderElement) secondChild.getNextSibling();
-        assertEquals("ebxmlms3", thirdChild.getLocalName());
-        assertEquals("ch3", thirdChild.getPrefix());
-        assertEquals("http://test2.apache.org", thirdChild.getNamespaceURI());
+        assertEquals("ns-prefix", secondChild.getPrefix());
+        assertEquals("http://test2.apache.org", secondChild.getNamespaceURI());
 
         SOAPHeaderElement lastChild = (SOAPHeaderElement) header.getLastChild();
-        assertEquals("ebxmlms5", lastChild.getLocalName());
-        assertEquals("ch5", lastChild.getPrefix());
+        assertEquals("ebxmlms3", lastChild.getLocalName());
+        assertEquals("ns-prefix", lastChild.getPrefix());
         assertEquals("http://test3.apache.org", lastChild.getNamespaceURI());
 
         SOAPHeaderElement fourthChild = (SOAPHeaderElement) lastChild.getPreviousSibling();
-        assertEquals("ebxmlms4", fourthChild.getLocalName());
-        assertEquals("", fourthChild.getPrefix());
-        assertEquals("", fourthChild.getNamespaceURI());
+        assertEquals("ebxmlms2", fourthChild.getLocalName());
+        assertEquals("ns-prefix", fourthChild.getPrefix());
+        assertEquals("http://test2.apache.org", fourthChild.getNamespaceURI());
 
         Iterator it = header.getChildElements();
         int numOfHeaderElements = 0;
@@ -93,7 +97,7 @@
             String lName = el.getLocalName();
             assertTrue(lName.equals("ebxmlms" + ++numOfHeaderElements));
         }
-        assertEquals(5, numOfHeaderElements);
+        assertEquals(3, numOfHeaderElements);
     }
 
     public void testHeaders() {
@@ -151,8 +155,8 @@
             message.saveChanges();
 
             // Display the message that would be sent
-            System.out.println("\n----- Request Message ----\n");
-            message.writeTo(System.out);
+            //System.out.println("\n----- Request Message ----\n");
+            //message.writeTo(System.out);
 
             // Look at the headers
             Iterator allHeaders = header.examineAllHeaderElements();
@@ -161,11 +165,11 @@
                 SOAPHeaderElement headerElement =
                         (SOAPHeaderElement) allHeaders.next();
                 Name headerName = headerElement.getElementName();
-                System.out.println("\nHeader name is " +
-                                   headerName.getQualifiedName());
-                System.out.println("Actor is " + headerElement.getActor());
-                System.out.println("mustUnderstand is " +
-                                   headerElement.getMustUnderstand());
+                //System.out.println("\nHeader name is " +
+                //                   headerName.getQualifiedName());
+                //System.out.println("Actor is " + headerElement.getActor());
+                //System.out.println("mustUnderstand is " +
+                //                   headerElement.getMustUnderstand());
             }
         } catch (Exception e) {
             fail("Enexpected Exception " + e);
@@ -223,18 +227,10 @@
 	    
         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");
+	        //Validate the LocalName which must be NotUnderstood
 	        assertEquals("NotUnderstood", localName);
     }
 
@@ -253,28 +249,14 @@
     	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);
 
+    	//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"));
     }
 
@@ -287,14 +269,11 @@
     		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;
@@ -302,15 +281,10 @@
     		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();
@@ -322,80 +296,63 @@
 
     	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");
+    		//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");
+    		assertEquals(cnt,4);
     		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);
-    		}
-
+    		assertEquals(cnt,0);
     	} catch (Exception e) {
     		fail("Unexpected Exception: " + e);
     	}
     }
     
     public void testQNamesOnHeader(){
-    	SOAPHeaderElement transaction = null;
+    	SOAPHeaderElement headerElement = 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");
+    		//SOAP1.1 and SOAP1.2 requires all HeaderElements to be namespace qualified
+    		//Try adding HeaderElement with unqualified QName not belonging to any namespace 
+    		//(expect SOAPException)
+    		headerElement = hdr.addHeaderElement(envelope.createName("Transaction"));
+    		fail("Did not throw expected SOAPException");
     	} catch (SOAPException e) {
-    		System.out.println("Did throw expected SOAPException");
+    		//Did throw expected SOAPException
     	} catch (Exception e) {
-    		System.out.println("Unexpected Exception: " + e.getMessage());
+    		fail("Unexpected Exception: " + e.getMessage());
     	}
     }
 }

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java?view=diff&rev=503658&r1=503657&r2=503658
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java Mon Feb  5 04:14:07 2007
@@ -15,9 +15,12 @@
  */
 package org.apache.axis2.saaj;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
 import java.net.URL;
 import java.util.Iterator;
 
@@ -31,264 +34,366 @@
 import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPFactory;
 import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
+import javax.xml.transform.stream.StreamSource;
 
 import junit.framework.TestCase;
 
+import org.apache.axis2.saaj.util.SAAJDataSource;
+
 /**
  * 
  */
 public class SOAPMessageTest extends TestCase {
-    private SOAPMessage msg;
+	private SOAPMessage msg;
+
+	protected void setUp() throws Exception {
+		msg = MessageFactory.newInstance().createMessage();
+	}
+
+	public void testSaveRequired() {
+		try {
+			assertTrue("Save Required is False",msg.saveRequired());
+		} catch (Exception e) {
+			fail("Unexpected Exception : " + e);
+		}
+	}
+
+	public void testSaveRequired2() {
+		try {
+			msg.saveChanges();
+			assertFalse("Save Required is True",msg.saveRequired());
+		} catch (Exception e) {
+			fail("Unexpected Exception : " + e);
+		}
+	}
+
+
+
+
+	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);
+
+			//get all attachments
+			iterator = msg.getAttachments();
+
+			int cnt = 0;
+			while(iterator.hasNext()){
+				cnt++;
+				iterator.next();
+			}
+			assertEquals(cnt,3);
+			//remove just the text/xml attachments
+			MimeHeaders mhs = new MimeHeaders();
+			mhs.addHeader("Content-Type", "text/xml");
+			msg.removeAttachments(mhs);
+
+			//get all attachments
+			iterator = msg.getAttachments();
+			cnt = 0;
+			iterator = msg.getAttachments();
+			while(iterator.hasNext()){
+				cnt++;
+				iterator.next();
+			}
+			System.out.println("number of attachments: " + cnt);
+			assertEquals(cnt,1);
+			iterator = msg.getAttachments();
+			AttachmentPart ap = (AttachmentPart) iterator.next();
+			String ctype = ap.getContentType();
+			System.out.println(ctype);
+			assertTrue(ctype.equals("text/plain"));
+
+		} catch(Exception e) {
+			fail("Exception: " + e);
+		}
+	}
+
+
+	public void testGetContent(){
+		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();
+
+			AttachmentPart ap;
+
+			InputStream inputStream = new FileInputStream(new File("test-resources" + File.separator + "attach.xml"));
+			ap = msg.createAttachmentPart(inputStream, "text/xml");
+			DataHandler dh = new DataHandler(new SAAJDataSource(inputStream,1000,"text/xml",true));
+
+			StringBuffer sb1 = copyToBuffer(dh.getInputStream());
+			assertNotNull(ap);
+
+			//Verify attachment part is not empty and contents are correct
+			try {
+				Object o = ap.getContent();
+				InputStream is = null;
+				assertNotNull(o);
+				if(o instanceof StreamSource) {
+					StreamSource ss = (StreamSource)o;
+					is = ss.getInputStream();
+				} else {
+					fail("got object: " + o + 
+					", expected object: javax.xml.transform.stream.StreamSource");
+				}
+
+				//if(is != null) {
+				//	StringBuffer sb2 = copyToBuffer(is);
+				//	String s1 = sb1.toString();
+				//	String s2 = sb2.toString();
+				//	assertTrue(s1.equals(s2));
+				//}
+			}
+			catch (Exception e) {
+				fail("attachment has no content - unexpected");
+			}
+		} catch(Exception e) {
+			fail("Exception: " + e);
+		}
+	}
+
+
+	private StringBuffer copyToBuffer(InputStream inputStream)
+	{
+		if (inputStream == null){
+			return null;
+		}
+		StringWriter stringWriter = new StringWriter();
+		BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
+		try {
+			String s;
+			while((s = br.readLine()) != null)
+				stringWriter.write(s);
+		}
+		catch (Exception e) {
+			e.printStackTrace();
+		}
+		return stringWriter.getBuffer();
+	}
+
+	
+	/*
+	 * Do not add this test unless below mentioned resources are accessible
+	 */
+
+	public void testGetAttachmentsByHREF(){
+		String NS_PREFIX="mypre";
+		String NS_URI="http://myuri.org/";
+
+		try {
+			//MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+			SOAPMessage msg = MessageFactory.newInstance().createMessage();
+
+
+			// Message creation takes care of creating the SOAPPart - a
+			// required part of the message as per the SOAP 1.1 spec.
+			SOAPPart sp = msg.getSOAPPart();
+			SOAPEnvelope envelope = sp.getEnvelope();
+			SOAPHeader hdr = envelope.getHeader();
+			SOAPBody bdy = envelope.getBody();
+			SOAPBodyElement sbe1 = bdy.addBodyElement(
+					envelope.createName("Body1", NS_PREFIX, NS_URI));
+			sbe1.addChildElement(envelope.createName(
+					"TheGifAttachment", NS_PREFIX, NS_URI));
+			sbe1.setAttribute("href", "cid:THEGIF");
+			SOAPBodyElement sbe2 = bdy.addBodyElement(
+					envelope.createName("Body2", NS_PREFIX, NS_URI));
+			sbe2.addChildElement(envelope.createName(
+					"TheXmlAttachment", NS_PREFIX, NS_URI));
+			sbe2.setAttribute("href", "cid:THEXML");
+
+			URL url1 = new URL("http://localhost:8080/SOAPMessage/attach.xml");
+			URL url2 = new URL("http://localhost:8080/SOAPMessage/attach.gif");
+			URL url3 = new URL("http://localhost:8080/SOAPMessage/attach.txt");
+			URL url4 = new URL("http://localhost:8080/SOAPMessage/attach.html");
+			URL url5 = new URL("http://localhost:8080/SOAPMessage/attach.jpeg");
+
+			System.out.println("Add various mime type attachments to SOAP message");
+			AttachmentPart ap1 = msg.createAttachmentPart(new DataHandler(url1));
+			AttachmentPart ap2 = msg.createAttachmentPart(new DataHandler(url2));
+			AttachmentPart ap3 = msg.createAttachmentPart(new DataHandler(url3));
+			AttachmentPart ap4 = msg.createAttachmentPart(new DataHandler(url4));
+			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>");
+
+			msg.addAttachmentPart(ap1);
+			msg.addAttachmentPart(ap2);
+			msg.addAttachmentPart(ap3);
+			msg.addAttachmentPart(ap4);
+			msg.addAttachmentPart(ap5);
+			msg.saveChanges();
+
+			//Retrieve attachment with href=cid:THEGIF
+			AttachmentPart myap = msg.getAttachment(sbe1);
+			if(myap == null) {
+				fail("Returned null (unexpected)");
+			} else if(!myap.getContentType().equals("image/gif")) {
+				fail("Wrong attachment was returned: Got Content-Type of "
+						+myap.getContentType()+", Expected Content-Type of image/gif");
+			} 
+			//Retrieve attachment with href=cid:THEXML
+			myap = msg.getAttachment(sbe2);
+			if(myap == null) {
+				fail("Returned null (unexpected)");
+			} else if(!myap.getContentType().equals("text/xml")) {
+				fail("Wrong attachment was returned: Got Content-Type of "
+						+myap.getContentType()+", Expected Content-Type of text/xml");
+			}
+			//Retrieve attachment with href=cid:boo-hoo (expect null)
+			QName myqname = new QName("boo-hoo");
+			SOAPElement myse = SOAPFactoryImpl.newInstance().createElement(myqname);
+			myse.addTextNode("<theBooHooAttachment href=\"cid:boo-hoo\"/>");
+			myap = msg.getAttachment(myse);
+			assertNull(myap);
+
+		} catch(Exception e) {
+			fail("Error :"+e);
+		}
+	}
+
+
+	/*
+	 * Do not add this test unless below mentioned resources are accessible
+	 */
+	public void _testGetAttachmentByHREF2(){
+		String NS_PREFIX="mypre";
+		String NS_URI="http://myuri.org/";
+
+		try {
+			System.out.println("Create SOAP message from message factory");
+			MessageFactory fac = MessageFactory.newInstance();
+			SOAPMessage msg = fac.createMessage();
+
+			// Message creation takes care of creating the SOAPPart - a
+			// required part of the message as per the SOAP 1.1 spec.
+			SOAPPart sp = msg.getSOAPPart();
+			SOAPEnvelope envelope = sp.getEnvelope();
+			SOAPHeader hdr = envelope.getHeader();
+
+			SOAPBody bdy = envelope.getBody();
+			SOAPBodyElement sbe1 = bdy.addBodyElement(
+					envelope.createName("Body1", NS_PREFIX, NS_URI));
+			sbe1.addChildElement(envelope.createName(
+					"TheGifAttachment", NS_PREFIX, NS_URI));
+
+			SOAPBodyElement sbe2 = bdy.addBodyElement(
+					envelope.createName("Body2", NS_PREFIX, NS_URI));
+
+			sbe2.addChildElement(envelope.createName(
+					"TheXmlAttachment", NS_PREFIX, NS_URI));
+
+			URL url1 = new URL("http://localhost:8080/SOAPMessage/attach.xml");
+			URL url2 = new URL("http://localhost:8080/SOAPMessage/attach.gif");
+			URL url3 = new URL("http://localhost:8080/SOAPMessage/attach.txt");
+			URL url4 = new URL("http://localhost:8080/SOAPMessage/attach.html");
+			URL url5 = new URL("http://localhost:8080/SOAPMessage/attach.jpeg");
+
+			// Set href on body elements using Content-Location headers and relative URI's
+			sbe1.setAttribute("href", url2.toString());
+			sbe2.setAttribute("href", url1.toString());
+
+			AttachmentPart ap1 = msg.createAttachmentPart(new DataHandler(url1));
+			AttachmentPart ap2 = msg.createAttachmentPart(new DataHandler(url2));
+			AttachmentPart ap3 = msg.createAttachmentPart(new DataHandler(url3));
+			AttachmentPart ap4 = msg.createAttachmentPart(new DataHandler(url4));
+			AttachmentPart ap5 = msg.createAttachmentPart(new DataHandler(url5));
+
+			ap1.setContentType("text/xml");
+			ap1.setContentId("<THEXML>");
+			ap1.setContentLocation(url1.toString());
+			ap2.setContentType("image/gif");
+			ap2.setContentId("<THEGIF>");
+			ap2.setContentLocation(url2.toString());
+			ap3.setContentType("text/plain");
+			ap3.setContentId("<THEPLAIN>");
+			ap3.setContentLocation(url3.toString());
+			ap4.setContentType("text/html");
+			ap4.setContentId("<THEHTML>");
+			ap4.setContentLocation(url4.toString());
+			ap5.setContentType("image/jpeg");
+			ap5.setContentId("<THEJPEG>");
+			ap5.setContentLocation(url5.toString());
+
+			// Add the attachments to the message.
+			msg.addAttachmentPart(ap1);
+			msg.addAttachmentPart(ap2);
+			msg.addAttachmentPart(ap3);
+			msg.addAttachmentPart(ap4);
+			msg.addAttachmentPart(ap5);
+			msg.saveChanges();
+
+			//Retrieve attachment with href=THEGIF
+			AttachmentPart myap = msg.getAttachment(sbe1);
+			if(myap == null) {
+				fail("Returned null (unexpected)");
+			} else if(!myap.getContentType().equals("image/gif")) {
+				fail("Wrong attachment was returned: Got Content-Type of "
+						+myap.getContentType()+", Expected Content-Type of image/gif");
+			}
+			
+			//Retrieve attachment with href=THEXML
+			myap = msg.getAttachment(sbe2);
+			if(myap == null) {
+				fail("Returned null (unexpected)");
+			} else if(!myap.getContentType().equals("text/xml")) {
+				fail("Wrong attachment was returned: Got Content-Type of "
+						+myap.getContentType()+", Expected Content-Type of text/xml");
+			}
+			
+			//Retrieve attachment with href=boo-hoo (expect null)
+			QName myqname = new QName("boo-hoo");
+			SOAPElement myse = SOAPFactory.newInstance().createElement(myqname);
+			myse.addTextNode("<theBooHooAttachment href=\"boo-hoo\"/>");
+			myap = msg.getAttachment(myse);
+			assertNull(myap);
+		} catch(Exception e) {
+			fail("Exception: " + e);
+		}
+	}
 
-    protected void setUp() throws Exception {
-        msg = MessageFactory.newInstance().createMessage();
-    }
-
-    public void testSaveRequired() {
-        try {
-            assertTrue("Save Required is False",msg.saveRequired());
-        } catch (Exception e) {
-            fail("Unexpected Exception : " + e);
-        }
-    }
-
-    public void testSaveRequired2() {
-        try {
-            msg.saveChanges();
-            assertFalse("Save Required is True",msg.saveRequired());
-        } catch (Exception e) {
-            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/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java?view=diff&rev=503658&r1=503657&r2=503658
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java Mon Feb  5 04:14:07 2007
@@ -15,12 +15,9 @@
  */
 package org.apache.axis2.saaj;
 
-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;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.soap.MessageFactory;
@@ -28,12 +25,11 @@
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPElement;
 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.transform.Source;
 import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamSource;
 
 import junit.framework.TestCase;
 
@@ -44,25 +40,6 @@
  * 
  */
 public class SOAPPartTest extends TestCase {
-    public void testGetContents() {
-        try {
-            ByteArrayInputStream ins = new ByteArrayInputStream(new byte[5]);
-            DataHandler dh = new DataHandler(new AttachmentTest("t").new Src(ins, "text/plain"));
-            InputStream in = dh.getInputStream();
-            StreamSource ssrc = new StreamSource(in);
-
-            SOAPPart sp = MessageFactory.newInstance().createMessage().getSOAPPart();
-            sp.setContent(ssrc);
-
-            Source ssrc2 = sp.getContent();
-            if (ssrc2 == null) {
-                fail("Contents were null");
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("Unexpected Exception " + e);
-        }
-    }
 
     public void testAddSource() {
         DOMSource domSource;
@@ -81,40 +58,19 @@
             SOAPHeader header = message.getSOAPHeader();
             if (header != null) {
                 Iterator iter1 = header.getChildElements();
-                System.out.println("Header contents:");
                 getContents(iter1, "");
             }
 
             SOAPBody body = message.getSOAPBody();
             Iterator iter2 = body.getChildElements();
-            System.out.println("Body contents:");
             getContents(iter2, "");
 
-            /* SOAPEnvelope envelope = soapPart.getEnvelope();
-            SOAPHeader header = envelope.getHeader();
-            assertEquals("Header", header.getLocalName());
-            assertEquals("soapenv", header.getPrefix());
-
-            Node firstChild = header.getFirstChild();
-            //assertEquals("Hello", firstChild.getLocalName());
-            //assertEquals("shw", firstChild.getPrefix());
-
-            SOAPBody body = envelope.getBody();
-            assertEquals("Body", body.getLocalName());
-            assertEquals("soapenv", body.getPrefix());
-
-            for(Iterator iter=body.getChildElements(); iter.hasNext();){
-                System.err.println("$$$ " + iter.next());
-            }*/
-
         } catch (Exception e) {
-            e.printStackTrace();
             fail("Unexpected Exception : " + e);
         }
     }
 
     public void getContents(Iterator iterator, String indent) {
-        System.err.println(iterator.hasNext());
         while (iterator.hasNext()) {
             Node node = (Node) iterator.next();
             SOAPElement element = null;
@@ -124,29 +80,77 @@
                 element = (SOAPElement) node;
 
                 Name name = element.getElementName();
-                System.out.println(indent + "Name is " + name.getQualifiedName());
 
                 Iterator attrs = element.getAllAttributes();
 
                 while (attrs.hasNext()) {
                     Name attrName = (Name) attrs.next();
-                    System.out.println(indent + " Attribute name is " +
-                                       attrName.getQualifiedName());
-                    System.out.println(indent + " Attribute value is " +
-                                       element.getAttributeValue(attrName));
+                    assertNotNull(attrName);
+                    //System.out.println(indent + " Attribute name is " +
+                    //                   attrName.getQualifiedName());
+                    //System.out.println(indent + " Attribute value is " +
+                    //                   element.getAttributeValue(attrName));
                 }
 
                 Iterator iter2 = element.getChildElements();
                 getContents(iter2, indent + " ");
             } else {
                 text = (Text) node;
-
                 String content = text.getValue();
-                System.out.println(indent + "Content is: " + content);
+                assertNotNull(content);
             }
         }
     }
     
+    
+    
+    public void testAddSource2() 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();
+        javax.xml.soap.SOAPBody body = soapEnv.getBody();
+        
+        assertTrue(header.addChildElement("ebxmlms1", "ch2", "http://test.apache.org") instanceof SOAPHeaderElement);
+        assertTrue(header.addHeaderElement(soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null);
+        assertTrue(header.addHeaderElement(new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null);
+
+        body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org");
+        soapMessage.saveChanges();
+        
+        javax.xml.soap.SOAPMessage soapMessage2 =
+            javax.xml.soap.MessageFactory.newInstance().createMessage();
+        SOAPPart soapPart = soapMessage2.getSOAPPart();
+        soapPart.setContent(soapMessage.getSOAPPart().getContent());
+        soapMessage2.saveChanges();
+        assertNotNull(soapMessage2);
+    }
+    
+    public void testAddSource3() 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();
+        javax.xml.soap.SOAPBody body = soapEnv.getBody();
+        
+        assertTrue(header.addChildElement("ebxmlms1", "ch2", "http://test.apache.org") instanceof SOAPHeaderElement);
+        assertTrue(header.addHeaderElement(soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null);
+        assertTrue(header.addHeaderElement(new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null);
+
+        body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org");
+        soapMessage.saveChanges();
+        
+        javax.xml.soap.SOAPMessage soapMessage2 =
+            javax.xml.soap.MessageFactory.newInstance().createMessage();
+        SOAPPart soapPart = soapMessage2.getSOAPPart();
+        soapPart.setContent(soapMessage.getSOAPPart().getContent());
+        soapMessage2.saveChanges();
+        assertNotNull(soapMessage2);
+    }
+
+    
     public void _testInputEncoding() {
         try {
         	DOMSource domSource;
@@ -162,17 +166,10 @@
             message.saveChanges();
             
             SOAPPart sp = message.getSOAPPart();
-            //sp.setContent(ssrc);
 
             String inputEncoding = sp.getInputEncoding();
-            if (inputEncoding == null) {
-                fail("Input Encoding is null");
-            }
-            else{
-            	System.out.println(inputEncoding);
-            }
+            assertNotNull(inputEncoding);
         } catch (Exception e) {
-            e.printStackTrace();
             fail("Unexpected Exception " + e);
         }
     }

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/TextTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/TextTest.java?view=diff&rev=503658&r1=503657&r2=503658
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/TextTest.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/TextTest.java Mon Feb  5 04:14:07 2007
@@ -144,9 +144,8 @@
         SOAPElement postalCode = delivery.addChildElement(name);
         postalCode.addTextNode("PostalCode015");
 
-        System.out.println("The message is:\n");
-        message.writeTo(System.out);
-        System.out.flush();
+        //message.writeTo(System.out);
+        //System.out.flush();
     }
 
     public void testComment() throws SOAPException, IOException {

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/integration/IntegrationTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/integration/IntegrationTest.java?view=diff&rev=503658&r1=503657&r2=503658
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/integration/IntegrationTest.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/integration/IntegrationTest.java Mon Feb  5 04:14:07 2007
@@ -93,6 +93,7 @@
         UtilServer.unDeployClientService();
     }
 
+
     public void testSendReceiveSimpleSOAPMessage() {
         try {
             MessageFactory mf = MessageFactory.newInstance();
@@ -107,7 +108,6 @@
 
             String requestStr = printSOAPMessage(request);
             String responseStr = printSOAPMessage(response);
-//            assertEquals(requestStr, responseStr);
             assertTrue(responseStr.indexOf("echo") != -1);
             sCon.close();
         } catch (SOAPException e) {
@@ -186,28 +186,6 @@
 
         sCon.close();
 
-        /*final SOAPBody respBody = response.getSOAPPart().getEnvelope().getBody();
-        System.out.println("------------------------------------");
-        for (Iterator childEleIter = respBody.getChildElements(); childEleIter.hasNext();) {
-            SOAPElement o = (SOAPElement) childEleIter.next();
-            System.out.println("@@@@@@@@@ o.tn=" + o.getTagName());
-            System.out.println("------------------------------------------");
-            for (Iterator iter = o.getChildElements(); iter.hasNext();) {
-                SOAPElement p = (SOAPElement) iter.next();
-                System.out.println("@@@@@@@@@ p.o=" + p);
-                System.out.println("@@@@@@@@@ p.pre=" + p.getPrefix());
-                System.out.println("@@@@@@@@@ p.ln=" + p.getLocalName());
-                System.out.println("@@@@@@@@@ p.tn=" + p.getTagName());
-                System.out.println("@@@@@@@@@ p.ns URI=" + p.getNamespaceURI());
-                System.out.println("@@@@@@@@@ p.Val=" + p.getValue());
-            }
-        }
-        System.out.println("------------------------------------");*/
-
-//        response.getSOAPPart().getEnvelope().getHeader().extractAllHeaderElements();
-//        sCon.call(response, ADDRESS);
-
-//        printSOAPMessage(response);
     }
 
     public void testSendReceiveNonRefAttachment() throws Exception {
@@ -220,12 +198,23 @@
         //Attach a text/plain object with the SOAP request
         String sampleMessage = "Sample Message: Hello World!";
         AttachmentPart textAttach = request.createAttachmentPart(sampleMessage, "text/plain");
-//        textAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
         request.addAttachmentPart(textAttach);
+        
+        
+        //Attach a java.awt.Image object to the SOAP request
+        String jpgfilename = "test-resources/axis2.jpg";
+        File myfile = new File(jpgfilename);
+        FileDataSource fds = new FileDataSource(myfile);
+        DataHandler imageDH = new DataHandler(fds);
+        AttachmentPart jpegAttach = request.createAttachmentPart(imageDH);
+        jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
+        jpegAttach.setContentType("image/jpg");
+        request.addAttachmentPart(jpegAttach);
+        
 
         SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
         SOAPMessage response = sCon.call(request, ADDRESS);
-/*
+
         int attachmentCount = response.countAttachments();
         assertTrue(attachmentCount == 2);
 
@@ -242,7 +231,7 @@
                 byte[] b = new byte[15000];
                 final int lengthRead = bais.read(b);
                 FileOutputStream fos =
-                        new FileOutputStream(new File("target/test-resources/result" + (i++) + ".jpg"));
+                        new FileOutputStream(new File("target/test-resources/axis2.jpg"));
                 fos.write(b, 0, lengthRead);
                 fos.flush();
                 fos.close();
@@ -250,7 +239,7 @@
                 assertTrue(attachment.getContentType().equals("image/jpeg")
                            || attachment.getContentType().equals("text/plain"));
             }
-        }*/
+        }
 
         sCon.close();
     }



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