FileDocCategorySizeDatePackage
TestSOAPBody.javaAPI DocApache Axis 1.45630Sat Apr 22 18:57:26 BST 2006test.message

TestSOAPBody

public class TestSOAPBody extends junit.framework.TestCase
author
john.gregg@techarch.com
author
$Author: venkat $
version
$Revision: 261460 $

Fields Summary
String
xmlString
Constructors Summary
public TestSOAPBody(String name)
Constructor TestSOAPBody

param
name

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] argv)
Method main

param
argv

        TestSOAPBody tester = new TestSOAPBody("TestSOAPBody");
        tester.testSoapBodyBUG();
    
public static junit.framework.Testsuite()
Method suite

return

        return new TestSuite(test.message.TestSOAPBody.class);
    
public voidtestSaveChanges()
Method testSaveChanges

throws
Exception

        MimeHeaders mimeheaders = new MimeHeaders();

        mimeheaders.addHeader("Content-Type", "text/xml");
        ByteArrayInputStream instream = new ByteArrayInputStream(xmlString.getBytes());
        MessageFactory factory =
                MessageFactory.newInstance();
        SOAPMessage msg =
                factory.createMessage(mimeheaders, instream);
        org.apache.axis.client.AxisClient axisengine =
                new org.apache.axis.client.AxisClient();

        ((Message) msg).setMessageContext(
                new org.apache.axis.MessageContext(axisengine));
        SOAPPart sp = msg.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();

        Node myNode = (Element) sb.getElementsByTagName("City").item(0);
        myNode.replaceChild( myNode.getOwnerDocument().createTextNode("NY"), myNode.getFirstChild());

        msg.saveChanges();
        
        sp = msg.getSOAPPart();
        se = sp.getEnvelope();
        sb = se.getBody();
        myNode = (Element) sb.getElementsByTagName("City").item(0);
        Node city = myNode.getFirstChild();
        assertEquals("City name did not change to NY", city.toString(), "NY");
    
public voidtestSoapBodyBUG()
Method testSoapBodyBUG

throws
Exception


             
         
        MimeHeaders mimeheaders = new MimeHeaders();

        mimeheaders.addHeader("Content-Type", "text/xml");
        ByteArrayInputStream instream = new ByteArrayInputStream(xmlString.getBytes());
        MessageFactory factory =
                MessageFactory.newInstance();
        SOAPMessage msg =
                factory.createMessage(mimeheaders, instream);
        org.apache.axis.client.AxisClient axisengine =
                new org.apache.axis.client.AxisClient();

        // need to set it not null , if not nullpointer in sp.getEnvelope()
        ((org.apache.axis.Message) msg).setMessageContext(
                new org.apache.axis.MessageContext(axisengine));
        SOAPPart sp = msg.getSOAPPart();
        javax.xml.soap.SOAPEnvelope se = sp.getEnvelope();
        javax.xml.soap.SOAPHeader sh = se.getHeader();
        SOAPBody sb = se.getBody();
        Iterator it = sb.getChildElements();
        int count = 0;

        while (it.hasNext()) {
            SOAPBodyElement el = (SOAPBodyElement) it.next();
            count++;
            Name name = el.getElementName();
            System.out.println("Element:" + el);
            System.out.println("BODY ELEMENT NAME:" + name.getPrefix() + ":"
                    + name.getLocalName() + " " + name.getURI());
        }
        assertTrue(count == 1);