KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.axis2.om.OMAbstractFactory;
20 import org.apache.axis2.om.OMOutput;
21 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
22
23 public class SOAPFaultTest extends SOAPFaultTestCase {
24
25     public SOAPFaultTest(String JavaDoc testName) {
26         super(testName);
27     }
28
29     protected void setUp() throws Exception JavaDoc {
30         super.setUp();
31     }
32
33     //SOAP 1.1 Fault Test (Programaticaly created)-----------------------------------------------------------------------------------
34
public void testSOAP11SetCode() {
35         soap11Fault.setCode(soap11Factory.createSOAPFaultCode(soap11Fault));
36         assertNotNull("SOAP 1.1 Fault Test:- After calling setCode method, Fault has no code", soap11Fault.getCode());
37         try {
38             soap11Fault.setCode(soap12Factory.createSOAPFaultCode(soap12Fault));
39             fail("SOAP12FaultCode should not not be set in to a SOAP11Fault");
40         } catch (Exception JavaDoc e) {
41         }
42     }
43
44     public void testSOAP11GetCode() {
45         assertTrue("SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a code", soap11Fault.getCode() == null);
46         soap11Fault.setCode(soap11Factory.createSOAPFaultCode(soap11Fault));
47         assertFalse("SOAP 1.1 Fault Test:- After calling setCode method, Fault has no code", soap11Fault.getCode() == null);
48     }
49
50     public void testSOAP11SetReason() {
51         soap11Fault.setReason(soap11Factory.createSOAPFaultReason(soap11Fault));
52         assertFalse("SOAP 1.1 Fault Test:- After calling setReason method, Fault has no reason", soap11Fault.getReason() == null);
53         try {
54             soap11Fault.setReason(soap12Factory.createSOAPFaultReason(soap12Fault));
55             fail("SOAP12FaultReason should not be set in to a SOAP11Fault");
56
57         } catch (Exception JavaDoc e) {
58             assertTrue(true);
59         }
60     }
61
62     public void testSOAP11GetReason() {
63         assertTrue("SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a reason", soap11Fault.getReason() == null);
64         soap11Fault.setReason(soap11Factory.createSOAPFaultReason(soap11Fault));
65         assertFalse("SOAP 1.1 Fault Test:- After calling setReason method, Fault has no reason", soap11Fault.getReason() == null);
66     }
67
68     public void testSOAP11SetNode() {
69         soap11Fault.setNode(soap11Factory.createSOAPFaultNode(soap11Fault));
70         assertFalse("SOAP 1.1 Fault Test:- After calling setNode method, Fault has no node", soap11Fault.getNode() == null);
71         try {
72             soap11Fault.setNode(soap12Factory.createSOAPFaultNode(soap12Fault));
73             fail("SOAP12FaultNode should not be set in to a SOAP11Fault");
74
75         } catch (Exception JavaDoc e) {
76             assertTrue(true);
77
78         }
79     }
80
81     public void testSOAP11GetNode() {
82         assertTrue("SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a node", soap11Fault.getNode() == null);
83         soap11Fault.setNode(soap11Factory.createSOAPFaultNode(soap11Fault));
84         assertFalse("SOAP 1.1 Fault Test:- After calling setNode method, Fault has no node", soap11Fault.getNode() == null);
85     }
86
87     public void testSOAP11SetRole() {
88         soap11Fault.setRole(soap11Factory.createSOAPFaultRole(soap11Fault));
89         assertFalse("SOAP 1.1 Fault Test:- After calling setRole method, Fault has no role", soap11Fault.getRole() == null);
90         try {
91             soap11Fault.setRole(soap12Factory.createSOAPFaultRole(soap12Fault));
92             fail("SOAP12FaultRole should not be set in to a SOAP11Fault");
93         } catch (Exception JavaDoc e) {
94             assertTrue(true);
95         }
96     }
97
98     public void testSOAP11GetRole() {
99         assertTrue("SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a role", soap11Fault.getRole() == null);
100         soap11Fault.setRole(soap11Factory.createSOAPFaultRole(soap11Fault));
101         assertFalse("SOAP 1.1 Fault Test:- After calling setRole method, Fault has no role", soap11Fault.getRole() == null);
102     }
103
104     public void testSOAP11SetDetail() {
105         soap11Fault.setDetail(soap11Factory.createSOAPFaultDetail(soap11Fault));
106         assertFalse("SOAP 1.1 Fault Test:- After calling setDetail method, Fault has no detail", soap11Fault.getDetail() == null);
107         try {
108             soap11Fault.setDetail(soap12Factory.createSOAPFaultDetail(soap12Fault));
109             fail("SOAP12FaultDetail should not be set in to a SOAP11Fault");
110         } catch (Exception JavaDoc e) {
111             assertTrue(true);
112         }
113     }
114
115     public void testSOAP11GetDetail() {
116         assertTrue("SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a detail", soap11Fault.getDetail() == null);
117         soap11Fault.setDetail(soap11Factory.createSOAPFaultDetail(soap11Fault));
118         assertFalse("SOAP 1.1 Fault Test:- After calling setDetail method, Fault has no detail", soap11Fault.getDetail() == null);
119     }
120
121     //SOAP 1.2 Fault Test ((Programaticaly created)--------------------------------------------------------------------------------
122
public void testSOAP12SetCode() {
123         soap12Fault.setCode(soap12Factory.createSOAPFaultCode(soap12Fault));
124         assertFalse("SOAP 1.2 Fault Test:- After calling setCode method, Fault has no code", soap12Fault.getCode() == null);
125         assertTrue("SOAP 1.2 Fault Test:- Code local name mismatch", soap12Fault.getCode().getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));
126         try {
127             soap12Fault.setCode(soap11Factory.createSOAPFaultCode(soap11Fault));
128             fail("SOAP11FaultCode should not be set in to a SOAP12Fault");
129         } catch (Exception JavaDoc e) {
130             assertTrue(true);
131         }
132     }
133
134     public void testSOAP12GetCode() {
135         assertTrue("SOAP 1.2 Fault Test:- After creating a SOAP12Fault, it has a code", soap12Fault.getCode() == null);
136         soap12Fault.setCode(soap12Factory.createSOAPFaultCode(soap12Fault));
137         assertFalse("SOAP 1.2 Fault Test:- After calling setCode method, Fault has no code", soap12Fault.getCode() == null);
138         assertTrue("SOAP 1.2 Fault Test:- Fault code local name mismatch", soap12Fault.getCode().getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));
139     }
140
141     public void testSOAP12SetReason() {
142         soap12Fault.setReason(soap12Factory.createSOAPFaultReason(soap12Fault));
143         assertFalse("SOAP 1.2 Fault Test:- After calling setReason method, Fault has no reason", soap12Fault.getReason() == null);
144         assertTrue("SOAP 1.2 Fault Test:- Fault reason local name mismatch", soap12Fault.getReason().getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));
145         try {
146             soap12Fault.setReason(soap11Factory.createSOAPFaultReason(soap11Fault));
147             fail("SOAP11FaultReason should not be set in to a SOAP12Fault");
148
149         } catch (Exception JavaDoc e) {
150             assertTrue(true);
151         }
152     }
153
154     public void testSOAP12GetReason() {
155         assertTrue("SOAP 1.2 Fault Test:- After creating a SOAP12Fault, it has a reason", soap12Fault.getReason() == null);
156         soap12Fault.setReason(soap12Factory.createSOAPFaultReason(soap12Fault));
157         assertFalse("SOAP 1.2 Fault Test:- After calling setReason method, Fault has no reason", soap12Fault.getReason() == null);
158         assertTrue("SOAP 1.2 Fault Test:- Fault reason local name mismatch", soap12Fault.getReason().getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));
159     }
160
161     public void testSOAP12SetNode() {
162         soap12Fault.setNode(soap12Factory.createSOAPFaultNode(soap12Fault));
163         assertFalse("SOAP 1.2 Fault Test:- After calling setNode method, Fault has no node", soap12Fault.getNode() == null);
164         assertTrue("SOAP 1.2 Fault Test:- Fault node local name mismatch", soap12Fault.getNode().getLocalName().equals(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));
165         try {
166             soap12Fault.setNode(soap11Factory.createSOAPFaultNode(soap11Fault));
167             fail("SOAP11FaultNode should nott be set in to a SOAP12Fault");
168
169         } catch (Exception JavaDoc e) {
170             assertTrue(true);
171         }
172     }
173
174     public void testSOAP12GetNode() {
175         assertTrue("SOAP 1.2 Fault Test:- After creating a SOAP12Fault, it has a node", soap12Fault.getNode() == null);
176         soap12Fault.setNode(soap12Factory.createSOAPFaultNode(soap12Fault));
177         assertFalse("SOAP 1.2 Fault Test:- After calling setNode method, Fault has no node", soap12Fault.getNode() == null);
178         assertTrue("SOAP 1.2 Fault Test:- Fault node local name mismatch", soap12Fault.getNode().getLocalName().equals(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));
179     }
180
181     public void testSOAP12SetRole() {
182         soap12Fault.setRole(soap12Factory.createSOAPFaultRole(soap12Fault));
183         assertFalse("SOAP 1.2 :- After calling setRole method, Fault has no role", soap12Fault.getRole() == null);
184         assertTrue("SOAP 1.2 Fault Test:- Fault role local name mismatch", soap12Fault.getRole().getLocalName().equals(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));
185         try {
186             soap12Fault.setRole(soap11Factory.createSOAPFaultRole(soap11Fault));
187             fail("SOAP11FaultRole should not be set in to a SOAP12Fault");
188         } catch (Exception JavaDoc e) {
189             assertTrue(true);
190         }
191     }
192
193     public void testSOAP12GetRole() {
194         assertTrue("SOAP 1.2 Fault Test:- After creating a SOAP11Fault, it has a role", soap12Fault.getRole() == null);
195         soap12Fault.setRole(soap12Factory.createSOAPFaultRole(soap12Fault));
196         assertFalse("SOAP 1.2 Fault Test:- After calling setRole method, Fault has no role", soap12Fault.getRole() == null);
197         assertTrue("SOAP 1.2 Fault Test:- Fault role local name mismatch", soap12Fault.getRole().getLocalName().equals(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));
198     }
199
200     public void testSOAP12SetDetail() {
201         soap12Fault.setDetail(soap12Factory.createSOAPFaultDetail(soap12Fault));
202         assertFalse("SOAP 1.2 Fault Test:- After calling setDetaile method, Fault has no detail", soap12Fault.getDetail() == null);
203         assertTrue("SOAP 1.2 Fault Test:- Fault detail local name mismatch", soap12Fault.getDetail().getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
204         try {
205             soap12Fault.setDetail(soap11Factory.createSOAPFaultDetail(soap11Fault));
206             fail("SOAP11FaultDetail should not be set in to a SOAP12Fault");
207
208         } catch (Exception JavaDoc e) {
209             assertTrue(true);
210         }
211     }
212
213     public void testSOAP12GetDetail() {
214         assertTrue("SOAP 1.2 Fault Test:- After creating a SOAP12Fault, it has a detail", soap12Fault.getDetail() == null);
215         soap12Fault.setDetail(soap12Factory.createSOAPFaultDetail(soap12Fault));
216         assertFalse("SOAP 1.2 Fault Test:- After calling setDetail method, Fault has no detail", soap12Fault.getDetail() == null);
217         assertTrue("SOAP 1.2 Fault Test:- Fault detail local name mismatch", soap12Fault.getDetail().getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
218     }
219
220     //SOAP 1.1 Fault Test (With parser)
221
public void testSOAP11GetCodeWithParser() {
222         assertFalse("SOAP 1.1 Fault Test with parser: - getCode method returns null", soap11FaultWithParser.getCode() == null);
223     }
224
225     public void testSOAP11GetRoleWithParser() {
226         assertFalse("SOAP 1.1 Fault Test with parser: - getRole method returns null", soap11FaultWithParser.getRole() == null);
227     }
228
229     public void testSOAP11GetDetailWithParser() {
230         assertFalse("SOAP 1.1 Fault Test with parser: - getDetail method returns null", soap11FaultWithParser.getDetail() == null);
231     }
232
233     //SOAP 1.2 Fault Test (With parser)
234
public void testSOAP12GetCodeWithParser() {
235         assertFalse("SOAP 1.2 Fault Test with parser: - getCode method returns null", soap12FaultWithParser.getCode() == null);
236         assertTrue("SOAP 1.2 Fault Test with parser: - Fault code local name mismatch", soap12FaultWithParser.getCode().getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));
237     }
238
239     public void testSOAP12GetReasonWithParser() {
240         assertFalse("SOAP 1.2 Fault Test with parser: - getReason method returns null", soap12FaultWithParser.getReason() == null);
241         assertTrue("SOAP 1.2 Fault Test with parser: - Fault reason local name mismatch", soap12FaultWithParser.getReason().getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));
242     }
243
244     public void testSOAP12GetNodeWithParser() {
245         assertFalse("SOAP 1.2 Fault Test with parser: - getNode method returns null", soap12FaultWithParser.getNode() == null);
246         assertTrue("SOAP 1.2 Fault Test with parser: - Fault node local name mismatch", soap12FaultWithParser.getNode().getLocalName().equals(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));
247     }
248
249     public void testSOAP12GetRoleWithParser() {
250         assertFalse("SOAP 1.2 Fault Test with parser: - getRole method returns null", soap12FaultWithParser.getRole() == null);
251         assertTrue("SOAP 1.2 Fault Test with parser: - Fault role local name mismatch", soap12FaultWithParser.getRole().getLocalName().equals(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));
252     }
253
254     public void testSOAP12GetDetailWithParser() {
255         assertFalse("SOAP 1.2 Fault Test with parser: - getDetail method returns null", soap12FaultWithParser.getDetail() == null);
256         assertTrue("SOAP 1.2 Fault Test with parser: - Fault detail local name mismatch", soap12FaultWithParser.getDetail().getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
257     }
258
259     public void testMoreChildrenAddition() {
260         OMOutput output = null;
261         try {
262             output = new OMOutput(System.out, false);
263             SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
264             SOAPEnvelope envelope = soapFactory.getDefaultFaultEnvelope();
265
266             assertNotNull("Default FaultEnvelope must have a SOAPFault in it", envelope.getBody().getFault());
267             assertNotNull("Default FaultEnvelope must have a SOAPFaultCode in it", envelope.getBody().getFault().getCode());
268             assertNotNull("Default FaultEnvelope must have a SOAPFaultCodeValue in it", envelope.getBody().getFault().getCode().getValue());
269             assertNotNull("Default FaultEnvelope must have a SOAPFaultReason in it", envelope.getBody().getFault().getReason());
270             assertNotNull("Default FaultEnvelope must have a SOAPFaultText in it", envelope.getBody().getFault().getReason().getSOAPText());
271
272             SOAPEnvelope soapEnvelope = soapFactory.getDefaultFaultEnvelope();
273             String JavaDoc errorCodeString = "Some Error occurred !!";
274             soapEnvelope.getBody().getFault().getCode().getValue().setText(errorCodeString);
275
276             SOAPFaultCode code = soapEnvelope.getBody().getFault().getCode();
277             envelope.getBody().getFault().setCode(code);
278
279             assertTrue("Parent Value of Code has not been set to new fault", code.getParent() == envelope.getBody().getFault());
280             assertTrue("Parent Value of Code is still pointing to old fault", code.getParent() != soapEnvelope.getBody().getFault());
281             assertNull("Old fault must not have a fault code", soapEnvelope.getBody().getFault().getCode());
282             assertEquals("The SOAP Code value must be "+errorCodeString, errorCodeString, envelope.getBody().getFault().getCode().getValue().getText());
283
284         } catch (Exception JavaDoc e) {
285             fail(e.getMessage());
286         }
287
288
289     }
290 }
Popular Tags