FileDocCategorySizeDatePackage
TestHeaders.javaAPI DocApache Axis 1.44294Sat Apr 22 18:57:26 BST 2006test.saaj

TestHeaders

public class TestHeaders extends TestCase

Fields Summary
private final String
actor
private final String
localName
private final String
namespace
private final String
prefix
String
xmlString
Constructors Summary
public TestHeaders(String name)

        super(name);
    
Methods Summary
public voidtestAddingHeaderElements()

        SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
        SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
        SOAPHeader header = soapEnv.getHeader();
        header.addChildElement("ebxmlms");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        soapMessage.writeTo(baos);
        String xml = new String(baos.toByteArray());
        assertTrue(xml.indexOf("ebxmlms") != -1);
    
public voidtestAddingHeaderElements2()

    
    
         
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage soapMessage = mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
        SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
        SOAPHeader header = soapEnv.getHeader();

        Name headerName = soapEnv.createName(localName, prefix, prefix);
        SOAPHeaderElement he = header.addHeaderElement(headerName);
        he.setActor(actor);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        soapMessage.writeTo(baos);
        
        String xml = new String(baos.toByteArray());
        assertTrue(xml.indexOf(localName) != -1);
    
public voidtestExamineAllHeaders()

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage soapMessage = mf.createMessage();
        SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
        SOAPHeader hdr = envelope.getHeader();
        SOAPHeaderElement she1 = hdr.addHeaderElement(envelope.createName("foo1", "f1", "foo1-URI"));
        she1.setActor("actor-URI");

        Iterator iterator = hdr.examineAllHeaderElements();
        SOAPHeaderElement she = null;
        int cnt = 0;
        while (iterator.hasNext()) {
            cnt++;
            she = (SOAPHeaderElement) iterator.next();
            assertEquals(she, she1);
        }
        assertEquals(1, cnt);
        iterator = hdr.examineAllHeaderElements();
        assertTrue(iterator.hasNext());
    
public voidtestExtractAllHeaders()

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage soapMessage = mf.createMessage();
        SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
        SOAPHeader hdr = envelope.getHeader();
        SOAPHeaderElement she1 = hdr.addHeaderElement(envelope.createName("foo1", "f1", "foo1-URI"));
        she1.setActor("actor-URI");

        Iterator iterator = hdr.extractAllHeaderElements();
        SOAPHeaderElement she = null;
        int cnt = 0;
        while (iterator.hasNext()) {
            cnt++;
            she = (SOAPHeaderElement) iterator.next();
            assertEquals(she, she1);
        }
        assertEquals(1, cnt);
        iterator = hdr.extractAllHeaderElements();
        assertTrue(!iterator.hasNext());