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

TestSOAPHeader

public class TestSOAPHeader extends junit.framework.TestCase
author
john.gregg@techarch.com
author
$Author: gdaniels $
version
$Revision: 257503 $

Fields Summary
public static final transient String
ACTOR
Field ACTOR
public static final transient String
HEADER_NAMESPACE
Field HEADER_NAMESPACE
protected org.apache.axis.message.SOAPEnvelope
env
Field env
protected org.apache.axis.message.SOAPHeaderElement
headerElement1
Field headerElement1
protected org.apache.axis.message.SOAPHeaderElement
headerElement2
Field headerElement2
String
xmlString
Constructors Summary
public TestSOAPHeader(String name)
Constructor TestSOAPHeader

param
name


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

param
argv

        TestSOAPHeader tester = new TestSOAPHeader("TestSOAPHeader");
        tester.setUp();
        tester.testExamineHeaderElements1();
        tester.testSoapHeadersBUG();
    
protected voidsetUp()
Method setUp

        env = new org.apache.axis.message.SOAPEnvelope();
        headerElement1 = new SOAPHeaderElement(HEADER_NAMESPACE, "SomeHeader1",
                "SomeValue1");
        headerElement1.setActor(ACTOR);
        env.addHeader(headerElement1);
        headerElement2 = new SOAPHeaderElement(HEADER_NAMESPACE, "SomeHeader2",
                "SomeValue2");
        headerElement2.setActor(Constants.URI_SOAP11_NEXT_ACTOR);
        env.addHeader(headerElement2);
    
public static junit.framework.Testsuite()
Method suite

return

        return new TestSuite(test.message.TestSOAPHeader.class);
    
protected voidtearDown()
Method tearDown

    
public voidtestExamineHeaderElements1()
Tests the happy path.

throws
Exception

        SOAPHeader header =
                (org.apache.axis.message.SOAPHeader) env.getHeader();
        Iterator iter = header.examineHeaderElements(ACTOR);

        // This would be a lot simpler if getHeadersByActor() were visible.
        SOAPHeaderElement headerElement = null;
        int expectedHeaders = 2;
        int foundHeaders = 0;

        while (iter.hasNext()) {
            headerElement = (SOAPHeaderElement) iter.next();
            if (Constants.URI_SOAP11_NEXT_ACTOR.equals(headerElement.getActor())
                    || ACTOR.equals(headerElement.getActor())) {
                foundHeaders++;
            }
        }
        assertEquals("Didn't find all the right actors.", expectedHeaders,
                foundHeaders);
    
public voidtestExamineHeaderElements2()
Tests when the user submits a null actor.

throws
Exception

        SOAPHeader header =
                (org.apache.axis.message.SOAPHeader) env.getHeader();
        Iterator iter = header.examineHeaderElements(null);

        // This would be a lot simpler if getHeadersByActor() were visible.
        SOAPHeaderElement headerElement = null;
        int expectedHeaders = 1;
        int foundHeaders = 0;

        while (iter.hasNext()) {
            headerElement = (SOAPHeaderElement) iter.next();
            if (Constants.URI_SOAP11_NEXT_ACTOR.equals(
                    headerElement.getActor())) {
                foundHeaders++;
            }
        }
        assertEquals("Didn't find all the right actors.", expectedHeaders,
                foundHeaders);
    
public voidtestExtractHeaderElements1()
Tests the happy path.

throws
Exception

        SOAPHeader header =
                (org.apache.axis.message.SOAPHeader) env.getHeader();
        Iterator iter = header.extractHeaderElements(ACTOR);

        // This would be a lot simpler if getHeadersByActor() were visible.
        SOAPHeaderElement headerElement = null;
        int expectedHeaders = 2;
        int foundHeaders = 0;

        while (iter.hasNext()) {
            headerElement = (SOAPHeaderElement) iter.next();
            if (Constants.URI_SOAP11_NEXT_ACTOR.equals(headerElement.getActor())
                    || ACTOR.equals(headerElement.getActor())) {
                foundHeaders++;
            }
        }
        assertEquals("Didn't find all the right actors.", expectedHeaders,
                foundHeaders);
    
public voidtestExtractHeaderElements2()
Tests when the user submits a null actor.

throws
Exception

        SOAPHeader header =
                (org.apache.axis.message.SOAPHeader) env.getHeader();
        Iterator iter = header.extractHeaderElements(null);

        // This would be a lot simpler if getHeadersByActor() were visible.
        SOAPHeaderElement headerElement = null;
        int expectedHeaders = 1;
        int foundHeaders = 0;

        while (iter.hasNext()) {
            headerElement = (SOAPHeaderElement) iter.next();
            if (Constants.URI_SOAP11_NEXT_ACTOR.equals(
                    headerElement.getActor())) {
                foundHeaders++;
            }
        }
        assertEquals("Didn't find all the right actors.", expectedHeaders,
                foundHeaders);
    
public voidtestSoapHeadersBUG()
Method testSoapHeadersBUG

param
filename
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 = sh.getChildElements();
        int count = 0;

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