KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > SOAPElementTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis2.saaj;
17
18 import junit.framework.TestCase;
19
20 import javax.xml.soap.SOAPElement JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * @author Ashutosh Shahi ashutosh.shahi@gmail.com
25  *
26  */

27 public class SOAPElementTest extends TestCase {
28     
29     private SOAPElement JavaDoc soapElem;
30     
31     protected void setUp() throws Exception JavaDoc
32     {
33         soapElem = SOAPFactoryImpl.newInstance().createElement( "Test", "test", "http://test.apache.org/" );
34     }
35
36     public void testAddTextNode() throws Exception JavaDoc
37     {
38         assertNotNull( soapElem );
39         final String JavaDoc 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 JavaDoc soapElem ){
47         assertTrue( soapElem.hasChildNodes() );
48         List JavaDoc 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 JavaDoc toList( java.util.Iterator JavaDoc iter )
56     {
57         List JavaDoc list = new java.util.ArrayList JavaDoc();
58         while ( iter.hasNext() )
59         {
60             list.add( iter.next() );
61         }
62         return list;
63     }
64 }
65
Popular Tags