KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
22
23 /**
24  * @author Ashutosh Shahi ashutosh.shahi@gmail.com
25  *
26  */

27 public class HeadersTest extends TestCase {
28     
29     private final String JavaDoc actor = "ACTOR#1";
30     private final String JavaDoc localName = "Local1";
31     private final String JavaDoc namespace = "http://ws.apache.org";
32     private final String JavaDoc prefix = "P1";
33     
34     public HeadersTest(String JavaDoc name) {
35         super(name);
36     }
37     
38     public void testAddingHeaderElements() throws Exception JavaDoc {
39         javax.xml.soap.SOAPMessage JavaDoc soapMessage = javax.xml.soap.MessageFactory.newInstance().createMessage();
40         javax.xml.soap.SOAPEnvelope JavaDoc soapEnv = soapMessage.getSOAPPart().getEnvelope();
41         javax.xml.soap.SOAPHeader JavaDoc header = soapEnv.getHeader();
42         header.addChildElement("ebxmlms");
43         
44         /*ByteArrayOutputStream baos = new ByteArrayOutputStream();
45         soapMessage.writeTo(baos);
46         String xml = new String(baos.toByteArray());
47         assertTrue(xml.indexOf("ebxmlms") != -1);*/

48         
49         Iterator JavaDoc it = header.getChildElements();
50         boolean b = false;
51         while(it.hasNext()){
52             SOAPElement JavaDoc el = (SOAPElement JavaDoc) it.next();
53             String JavaDoc lName = el.getNodeName();
54             if(lName.equalsIgnoreCase("ebxmlms")){
55                 b = true;
56                 break;
57             }
58         }
59         assertTrue(b);
60     }
61
62 }
63
Popular Tags