1 16 package org.apache.axis2.saaj; 17 18 import junit.framework.TestCase; 19 20 import javax.xml.soap.SOAPElement ; 21 import java.util.List ; 22 23 27 public class SOAPElementTest extends TestCase { 28 29 private SOAPElement soapElem; 30 31 protected void setUp() throws Exception 32 { 33 soapElem = SOAPFactoryImpl.newInstance().createElement( "Test", "test", "http://test.apache.org/" ); 34 } 35 36 public void testAddTextNode() throws Exception 37 { 38 assertNotNull( soapElem ); 39 final String value = "foo"; 40 soapElem.addTextNode( value ); 41 assertEquals( value, soapElem.getValue() ); 42 TextImpl text = assertContainsText( soapElem ); 43 assertEquals( value, text.getValue() ); 44 } 45 46 private TextImpl assertContainsText( SOAPElement soapElem ){ 47 assertTrue( soapElem.hasChildNodes() ); 48 List childElems = toList( soapElem.getChildElements() ); 49 assertTrue( childElems.size() == 1 ); 50 NodeImpl node = (NodeImpl) childElems.get( 0 ); 51 assertTrue( node instanceof TextImpl ); 52 return (TextImpl) node; 53 } 54 55 private List toList( java.util.Iterator iter ) 56 { 57 List list = new java.util.ArrayList (); 58 while ( iter.hasNext() ) 59 { 60 list.add( iter.next() ); 61 } 62 return list; 63 } 64 } 65 | Popular Tags |