FileDocCategorySizeDatePackage
TestSOAPElement.javaAPI DocApache Axis 1.43699Sat Apr 22 18:57:28 BST 2006test.saaj

TestSOAPElement

public class TestSOAPElement extends TestCase
Test case for Axis impl of SAAJ {@link SOAPElement} interface ({@link org.apache.axis.message.MessageElement}).
author
Ian P. Springer

Fields Summary
private SOAPElement
soapElem
Constructors Summary
Methods Summary
private javax.xml.soap.TextassertContainsText(javax.xml.soap.SOAPElement soapElem)

        assertTrue( soapElem.hasChildNodes() );
        List childElems = toList( soapElem.getChildElements() );
        assertTrue( childElems.size() == 1 );
        Node node = (Node) childElems.get( 0 );
        assertTrue( node instanceof Text );
        return (Text) node;
    
protected voidsetUp()

        soapElem = SOAPFactory.newInstance().createElement( "Test", "test", "http://test.apache.org/" );
    
public voidtestAddTextNode()
Test for Axis impl of {@link SOAPElement#addTextNode(String)}.

throws
Exception on error

        assertNotNull( soapElem );
        final String value = "foo";
        soapElem.addTextNode( value );
        assertEquals( value, soapElem.getValue() );
        Text text = assertContainsText( soapElem );
        assertEquals( value, text.getValue() );
    
public voidtestGetElementsByTagName()

    	String soapMessageWithLeadingComment =
    		"<?xml version='1.0' encoding='UTF-8'?>" + 
			"<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
			"<env:Body>" +
                "<echo>" +
                " <data>\n" +
                "   <tag name=\"First\" >\n" +
                "      <Line> One </Line>\n" +
                "      <Line> Two </Line>\n" +
                "   </tag>\n" +
                "   <tag name =\"Second\" >\n" +
                "      <Line> Three </Line>\n" +
                "      <Line> Four </Line>\n" +
                "   </tag>\n" +
                "   <tag name =\"Third\" >\n" +
                "      <Line> Five </Line>\n" +
                "      <Line> Six </Line>\n" +
                "   </tag>\n" +
                "</data>" +
                "</echo>" +
            "</env:Body>" +
			"</env:Envelope>";
    	
    	MessageFactory factory = MessageFactory.newInstance();
    	SOAPMessage message =
    		factory.createMessage(new MimeHeaders(), 
    				new ByteArrayInputStream(soapMessageWithLeadingComment.getBytes()));
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope envelope = (SOAPEnvelope) part.getEnvelope();
        NodeList nodes = envelope.getElementsByTagName("tag");
        assertEquals(nodes.getLength(), 3);
        NodeList nodes2 = envelope.getElementsByTagName("Line");
        assertEquals(nodes2.getLength(), 6);

        NodeList nodes3 = part.getElementsByTagName("tag");
        assertEquals(nodes3.getLength(), 3);
        NodeList nodes4 = part.getElementsByTagName("Line");
        assertEquals(nodes4.getLength(), 6);
    
private java.util.ListtoList(java.util.Iterator iter)

        List list = new ArrayList();
        while ( iter.hasNext() )
        {
            list.add( iter.next() );
        }
        return list;