KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > soap > SOAPHeaderTest


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
17 package org.apache.axis2.soap;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 public class SOAPHeaderTest extends SOAPHeaderTestCase {
23     protected boolean isThereException;
24
25     public SOAPHeaderTest(String JavaDoc testName) {
26         super(testName);
27     }
28
29     protected void setUp() throws Exception JavaDoc {
30         super.setUp();
31     }
32
33     //SOAP 1.1 Header Test (Programaticaly Created)--------------------------------------------------------------------------------
34
public void testSOAP11AddHeadearBlock() {
35         soap11Header.addHeaderBlock("echoOk1", namespace);
36         soap11Header.addHeaderBlock("echoOk2", namespace);
37         Iterator JavaDoc iterator = soap11Header.getChildren();
38         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
39         assertFalse("SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, getChildren method returns empty iterator", headerBlock1 == null);
40         assertTrue("SOAP 1.1 Header Test : - HeaderBlock1 local name mismatch", headerBlock1.getLocalName().equals("echoOk1"));
41         assertTrue("SOAP 1.1 Header Test : - HeaderBlock1 namespace uri mismatch", headerBlock1.getNamespace().getName().equals("http://www.example.org"));
42
43         SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();
44         assertFalse("SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, getChildren method returns an iterator with only one object", headerBlock2 == null);
45         assertTrue("SOAP 1.1 Header Test : - HeaderBlock2 local name mismatch", headerBlock2.getLocalName().equals("echoOk2"));
46         assertTrue("SOAP 1.1 Header Test : - HeaderBlock2 namespace uri mismatch", headerBlock2.getNamespace().getName().equals("http://www.example.org"));
47
48         assertTrue("SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, getChildren method returns an iterator with more than two object", iterator.next() == null);
49     }
50
51     public void testSOAP11ExamineHeaderBlocks() {
52         soap11Header.addHeaderBlock("echoOk1", namespace).setRole("http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver");
53         ;
54         soap11Header.addHeaderBlock("echoOk2", namespace).setRole("http://schemas.xmlsoap.org/soap/envelope/actor/next");
55         Iterator JavaDoc iterator = soap11Header.examineHeaderBlocks("http://schemas.xmlsoap.org/soap/envelope/actor/next");
56         iterator.hasNext();
57         SOAPHeaderBlock headerBlockWithRole1 = (SOAPHeaderBlock) iterator.next();
58         assertTrue("SOAP 1.1 Header Test : - headerBlockWithRole local name mismatch", headerBlockWithRole1.getLocalName().equals("echoOk2"));
59         assertTrue("SOAP 1.1 Header Test : - headerBlockWithRole role value mismatch", headerBlockWithRole1.getRole().equals("http://schemas.xmlsoap.org/soap/envelope/actor/next"));
60
61
62         assertFalse("SOAP 1.1 Header Test : - header has three headerBlocks with the given role, but examineHeaderBlocks(String role) method returns an iterator with more than three objects", iterator.hasNext());
63     }
64
65 // public void testSOAP11ExtractHeaderBlocks() {
66

67 // }
68

69
70
71     public void testSOAP11ExamineAllHeaderBlocks() {
72         soap11Header.addHeaderBlock("echoOk1", namespace);
73         soap11Header.addHeaderBlock("echoOk2", namespace);
74         Iterator JavaDoc iterator = soap11Header.examineAllHeaderBlocks();
75         iterator.hasNext();
76         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
77         assertFalse("SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns empty iterator", headerBlock1 == null);
78         assertTrue("SOAP 1.1 Header Test : - HeaderBlock1 local name mismatch", headerBlock1.getLocalName().equals("echoOk1"));
79         assertTrue("SOAP 1.1 Header Test : - HeaderBlock1 namespace uri mismatch", headerBlock1.getNamespace().getName().equals("http://www.example.org"));
80
81         iterator.hasNext();
82         SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();
83         assertFalse("SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns an iterator with only one object", headerBlock2 == null);
84         assertTrue("SOAP 1.1 Header Test : - HeaderBlock2 local name mismatch", headerBlock2.getLocalName().equals("echoOk2"));
85         assertTrue("SOAP 1.1 Header Test : - HeaderBlock2 namespace uri mismatch", headerBlock2.getNamespace().getName().equals("http://www.example.org"));
86
87         assertFalse("SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns an iterator with more than two object", iterator.hasNext());
88
89     }
90
91 // public void testSOAP11ExtractAllHeaderBlocks() {
92
//
93
// }
94

95
96     public void testSOAP11GetHeaderBolcksWithNSURI() {
97         soap11Header.addHeaderBlock("echoOk1", namespace);
98         soap11Header.addHeaderBlock("echoOk2", omFactory.createOMNamespace("http://www.test1.org", "test1"));
99         ArrayList JavaDoc arrayList = soap11Header.getHeaderBolcksWithNSURI("http://www.test1.org");
100         assertTrue("SOAP 1.1 Header Test : - getHeaderBolcksWithNSURI returns an arrayList of incorrect size", arrayList.size() == 1);
101         assertTrue("SOAP 1.1 Header Test : - headerBlock of given namespace uri mismatch", ((SOAPHeaderBlock) arrayList.get(0)).getNamespace().getName().equals("http://www.test1.org"));
102     }
103
104     //SOAP 1.2 Header Test (Programaticaly Created)----------------------------------------------------------------------------------
105
public void testSOAP12AddHeadearBlock() {
106         soap12Header.addHeaderBlock("echoOk1", namespace);
107         soap12Header.addHeaderBlock("echoOk2", namespace);
108         Iterator JavaDoc iterator = soap12Header.getChildren();
109         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
110         assertFalse("SOAP 1.2 Header Test : - After calling addHeaderBlock method, getChildren method returns empty iterator", headerBlock1 == null);
111         assertTrue("SOAP 1.2 Header Test : - HeaderBlock1 local name mismatch", headerBlock1.getLocalName().equals("echoOk1"));
112         assertTrue("SOAP 1.2 Header Test : - HeaderBlock1 namespace uri mismatch", headerBlock1.getNamespace().getName().equals("http://www.example.org"));
113
114         SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();
115         assertFalse("SOAP 1.2 Header Test : - After calling addHeaderBlock method, getChildren method returns an iterator with only one object", headerBlock2 == null);
116         assertTrue("SOAP 1.2 Header Test : - HeaderBlock2 local name mismatch", headerBlock2.getLocalName().equals("echoOk2"));
117         assertTrue("SOAP 1.2 Header Test : - HeaderBlock2 namespace uri mismatch", headerBlock2.getNamespace().getName().equals("http://www.example.org"));
118
119         assertTrue("SOAP 1.2 Header Test : - After calling addHeaderBlock method twice, getChildren method returns an iterator with more than two elements", iterator.next() == null);
120     }
121
122     public void testSOAP12ExamineHeaderBlocks() {
123         soap12Header.addHeaderBlock("echoOk1", namespace);
124         soap12Header.addHeaderBlock("echoOk2", namespace).setRole("http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver");
125         Iterator JavaDoc iterator = soap12Header.examineHeaderBlocks("http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver");
126         iterator.hasNext();
127         SOAPHeaderBlock headerBlockWithRole = (SOAPHeaderBlock) iterator.next();
128         assertTrue("SOAP 1.2 Header Test : - headerBlockWithRole local name mismatch", headerBlockWithRole.getLocalName().equals("echoOk2"));
129         assertTrue("SOAP 1.2 Header Test : - headerBlockWithRole role value mismatch", headerBlockWithRole.getRole().equals("http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver"));
130
131         assertFalse("SOAP 1.2 Header Test : - header has one headerBlock with role, but examineHeaderBlocks(String role) method returns an iterator with more than one object", iterator.hasNext());
132
133     }
134
135
136     public void testSOAP12ExamineMustUnderstandHeaderBlocks() {
137         soap12Header.addHeaderBlock("echoOk1", namespace).setRole("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
138
139         SOAPHeaderBlock headerBlock1 = soap12Header.addHeaderBlock("echoOk2", namespace);
140         headerBlock1.setRole("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
141         headerBlock1.setMustUnderstand(true);
142
143         soap12Header.addHeaderBlock("echoOk3", namespace).setMustUnderstand(true);
144
145         Iterator JavaDoc iterator = soap12Header.examineMustUnderstandHeaderBlocks("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
146         iterator.hasNext();
147         SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) iterator.next();
148         assertFalse("SOAP 1.2 Header Test : - examineMustUnderstandHeaderBlocks method returns empty iterator", headerBlock == null);
149         assertTrue("SOAP 1.2 Header Test : - HeaderBlock local name mismatch", headerBlock.getLocalName().equals("echoOk2"));
150         assertTrue("SOAP 1.2 Header Test : - HeaderBlock role value mismatch", headerBlock.getRole().equals("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));
151         assertFalse("SOAP 1.2 Header Test : - examineMustUnderstandHeaderBlocks method returns an iterator with more than one object", iterator.hasNext());
152     }
153
154     public void testSOAP12ExamineAllHeaderBlocks() {
155         soap12Header.addHeaderBlock("echoOk1", namespace);
156         soap12Header.addHeaderBlock("echoOk2", namespace);
157         Iterator JavaDoc iterator = soap12Header.examineAllHeaderBlocks();
158         iterator.hasNext();
159         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
160         assertFalse("SOAP 1.2 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns empty iterator", headerBlock1 == null);
161         assertTrue("SOAP 1.2 Header Test : - HeaderBlock1 local name mismatch", headerBlock1.getLocalName().equals("echoOk1"));
162         assertTrue("SOAP 1.2 Header Test : - HeaderBlock1 namespace uri mismatch", headerBlock1.getNamespace().getName().equals("http://www.example.org"));
163
164         SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();
165         assertFalse("SOAP 1.2 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns an iterator with only one object", headerBlock2 == null);
166         assertTrue("SOAP 1.2 Header Test : - HeaderBlock2 local name mismatch", headerBlock2.getLocalName().equals("echoOk2"));
167         assertTrue("SOAP 1.2 Header Test : - HeaderBlock2 namespace uri mismatch", headerBlock2.getNamespace().getName().equals("http://www.example.org"));
168
169         assertFalse("SOAP 1.2 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns an iterator with more than two object", iterator.hasNext());
170     }
171 // public void testSOAP12ExtractAllHeaderBlocks() {
172
//
173
// }
174

175     public void testSOAP12GetHeaderBolcksWithNSURI() {
176         soap12Header.addHeaderBlock("echoOk1", namespace);
177         soap12Header.addHeaderBlock("echoOk2", omFactory.createOMNamespace("http://www.test1.org", "test1"));
178         ArrayList JavaDoc arrayList = soap12Header.getHeaderBolcksWithNSURI("http://www.test1.org");
179         assertTrue("SOAP 1.2 Header Test : - getHeaderBolcksWithNSURI returns an arrayList of incorrect size", arrayList.size() == 1);
180         assertTrue("SOAP 1.2 Header Test : - headerBlock of given namespace uri, mismatch", ((SOAPHeaderBlock) arrayList.get(0)).getNamespace().getName().equals("http://www.test1.org"));
181     }
182
183     //SOAP 1.1 Header Test (With Parser)---------------------------------------------------------------------------------------------
184
public void testSOAP11ExamineHeaderBlocksWithParser() {
185         Iterator JavaDoc iterator = soap11HeaderWithParser.examineHeaderBlocks("http://schemas.xmlsoap.org/soap/actor/next");
186         iterator.hasNext();
187         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
188         assertEquals("SOAP 1.1 Header Test With Parser : - headerBlock1 localname mismatch", headerBlock1.getLocalName(), "From");
189         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock1 role value mismatch", headerBlock1.getRole().equals("http://schemas.xmlsoap.org/soap/actor/next"));
190         iterator.hasNext();
191         SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();
192         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock2 localname mmismatch", headerBlock2.getLocalName().equals("MessageID"));
193         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock2 role value mmismatch", headerBlock2.getRole().equals("http://schemas.xmlsoap.org/soap/actor/next"));
194
195         assertFalse("SOAP 1.1 Header Test With Parser : - examineHeaderBlocks(String role) method returns an iterator with more than two objects", iterator.hasNext());
196     }
197
198     public void testSOAP11ExamineMustUnderstandHeaderBlocksWithParser() {
199         Iterator JavaDoc iterator = soap11HeaderWithParser.examineMustUnderstandHeaderBlocks("http://schemas.xmlsoap.org/soap/actor/next");
200         iterator.hasNext();
201         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
202         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock1 localname mmismatch", headerBlock1.getLocalName().equals("MessageID"));
203         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock1 role value mmismatch", headerBlock1.getRole().equals("http://schemas.xmlsoap.org/soap/actor/next"));
204
205         assertFalse("SOAP 1.1 Header Test With Parser : - examineMustUnderstandHeaderBlocks(String role) method returns an iterator with more than one objects", iterator.hasNext());
206     }
207
208     public void testSOAP11ExamineAllHeaderBlocksWithParser() {
209         Iterator JavaDoc iterator = soap11HeaderWithParser.examineAllHeaderBlocks();
210         iterator.hasNext();
211         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
212         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock1 localname mmismatch", headerBlock1.getLocalName().equals("From"));
213         iterator.hasNext();
214         SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();
215         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock1 localname mmismatch", headerBlock2.getLocalName().equals("MessageID"));
216         iterator.hasNext();
217         SOAPHeaderBlock headerBlock3 = (SOAPHeaderBlock) iterator.next();
218         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock1 localname mmismatch", headerBlock3.getLocalName().equals("To"));
219
220         assertFalse("SOAP 1.1 Header Test With Parser : - examineAllHeaderBlocks method returns an iterator with more than three objects", iterator.hasNext());
221     }
222
223     public void testSOAP11GetHeaderBolcksWithNSURIWithParser() {
224         ArrayList JavaDoc arrayList = soap11HeaderWithParser.getHeaderBolcksWithNSURI("http://example.org/ts-tests");
225         assertTrue("SOAP 1.1 Header Test With Parser : - getHeaderBolcksWithNSURI returns an arrayList of incorrect size", arrayList.size() == 1);
226         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock of given namespace uri, local name mismatch", ((SOAPHeaderBlock) arrayList.get(0)).getLocalName().equals("MessageID"));
227         assertTrue("SOAP 1.1 Header Test With Parser : - headerBlock of given namespace uri, mismatch", ((SOAPHeaderBlock) arrayList.get(0)).getNamespace().getName().equals("http://example.org/ts-tests"));
228     }
229
230     //SOAP 1.2 Header Test (With Parser)-------------------------------------------------------------------------------------------
231
public void testSOAP12ExamineHeaderBlocksWithParser() {
232         Iterator JavaDoc iterator = soap12HeaderWithParser.examineHeaderBlocks("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
233         iterator.hasNext();
234         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
235         assertTrue("SOAP 1.2 Header Test With Parser : - headerBlock1 localname mmismatch", headerBlock1.getLocalName().equals("echoOk"));
236         assertTrue("SOAP 1.2 Header Test With Parser : - headerBlock1 role value mmismatch", headerBlock1.getRole().equals("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));
237         iterator.hasNext();
238         SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();
239         assertTrue("SOAP 1.2 Header Test With Parser : - headerBlock2 localname mmismatch", headerBlock2.getLocalName().equals("echoOk2"));
240         assertTrue("SOAP 1.2 Header Test With Parser : - headerBlock2 role value mmismatch", headerBlock2.getRole().equals("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));
241
242         assertFalse("SOAP 1.2 Header Test With Parser : - examineHeaderBlocks(String role) method returns an iterator with more than two objects", iterator.hasNext());
243     }
244
245     public void testSOAP12ExamineMustUnderstandHeaderBlocksWithParser() {
246         Iterator JavaDoc iterator = soap12HeaderWithParser.examineMustUnderstandHeaderBlocks("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
247         iterator.hasNext();
248         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
249         assertEquals("SOAP 1.2 Header Test With Parser : - headerBlock localname mmismatch", headerBlock1.getLocalName(), "echoOk");
250         assertEquals("SOAP 1.2 Header Test With Parser : - headerBlock role value mmismatch", headerBlock1.getRole(), "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
251
252         iterator.hasNext();
253         SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();
254         assertEquals("SOAP 1.2 Header Test With Parser : - headerBlock localname mmismatch", headerBlock2.getLocalName(), "echoOk2");
255         assertEquals("SOAP 1.2 Header Test With Parser : - headerBlock role value mmismatch", headerBlock1.getRole(), "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
256
257         assertFalse("SOAP 1.2 Header Test With Parser : - examineMustUnderstandHeaderBlocks(String role) method returns an iterator with more than one objects", iterator.hasNext());
258     }
259
260     public void testSOAP12ExamineAllHeaderBlocksWithParser() {
261         Iterator JavaDoc iterator = soap12HeaderWithParser.examineAllHeaderBlocks();
262         iterator.next();
263         SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();
264         assertTrue("SOAP 1.2 Header Test With Parser : - headerBlock1 localname mmismatch", headerBlock1.getLocalName().equals("echoOk"));
265         iterator.next();
266         SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();
267         assertTrue("SOAP 1.2 Header Test With Parser : - headerBlock1 localname mmismatch", headerBlock2.getLocalName().equals("echoOk1"));
268         iterator.next();
269         SOAPHeaderBlock headerBlock3 = (SOAPHeaderBlock) iterator.next();
270         assertTrue("SOAP 1.2 Header Test With Parser : - headerBlock1 localname mmismatch", headerBlock3.getLocalName().equals("echoOk2"));
271
272             assertFalse("SOAP 1.2 Header Test With Parser : - examineAllHeaderBlocks method returns an iterator with more than three objects", iterator.hasNext());
273     }
274
275     public void testSOAP12GetHeaderBolcksWithNSURIWithParser() {
276         ArrayList JavaDoc arrayList = soap12HeaderWithParser.getHeaderBolcksWithNSURI("http://example.org/ts-tests");
277         assertTrue("SOAP 1.2 Header Test With Parser : - getHeaderBolcksWithNSURI returns an arrayList of incorrect size", arrayList.size() == 1);
278         assertTrue("SOAP 1.2 Header Test With Parser : - headerBlock of given namespace uri, local name mismatch", ((SOAPHeaderBlock) arrayList.get(0)).getLocalName().equals("echoOk"));
279         assertTrue("SOAP 1.2 Header Test With Parser : - headerBlock of given namespace uri, mismatch", ((SOAPHeaderBlock) arrayList.get(0)).getNamespace().getName().equals("http://example.org/ts-tests"));
280     }
281 }
282
Popular Tags