01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.exception;
20:
21: import javax.xml.ws.ProtocolException;
22: import javax.xml.ws.WebServiceException;
23:
24: import junit.framework.TestCase;
25: import org.apache.axis2.jaxws.ExceptionFactory;
26:
27: /**
28: * Tests the ExceptionFactory
29: */
30: public class ExceptionFactoryTests extends TestCase {
31: private static final String sampleText = "Sample";
32:
33: /**
34: * @param name
35: */
36: public ExceptionFactoryTests(String name) {
37: super (name);
38: }
39:
40: /**
41: * @teststrategy Tests creation of a WebServiceException
42: */
43: public void testExceptionFactory00() throws Exception {
44: try {
45: throw ExceptionFactory.makeWebServiceException(sampleText);
46: } catch (WebServiceException e) {
47: assertTrue(sampleText.equals(e.getMessage()));
48: assertTrue(e.getCause() == null);
49: }
50: }
51:
52: /**
53: * @teststrategy Tests creation of a WebServiceException from another WebServiceException
54: */
55: public void testExceptionFactory01() throws Exception {
56: try {
57: WebServiceException wse = (WebServiceException) ExceptionFactory
58: .makeWebServiceException(sampleText);
59: throw ExceptionFactory.makeWebServiceException(wse);
60: } catch (WebServiceException e) {
61: // Should only be a single WebServiceException
62: assertTrue(sampleText.equals(e.getMessage()));
63: assertTrue(e.getCause() == null);
64: }
65: }
66:
67: /**
68: * @teststrategy Tests creation of a WebServiceException->WebServiceException->ProtocolException
69: */
70: public void testExceptionFactory02() throws Exception {
71: ProtocolException pe = new ProtocolException(sampleText);
72: try {
73: WebServiceException wse = (WebServiceException) ExceptionFactory
74: .makeWebServiceException(pe);
75: throw ExceptionFactory.makeWebServiceException(wse);
76: } catch (WebServiceException e) {
77: // Should only be a single WebServiceException with a Protocol Exception
78: assertTrue(sampleText.equals(e.getMessage()));
79: assertTrue(e.getCause() == null);
80: }
81: }
82:
83: /**
84: * @teststrategy Tests creation of a WebServiceException->WebServiceException->NullPointerException
85: */
86: public void testExceptionFactory03() throws Exception {
87: NullPointerException npe = new NullPointerException();
88: try {
89: WebServiceException wse = (WebServiceException) ExceptionFactory
90: .makeWebServiceException(npe);
91: throw ExceptionFactory.makeWebServiceException(wse);
92: } catch (WebServiceException e) {
93: // Should only be a single WebServiceException with a Protocol Exception
94: assertTrue(e.getCause() == npe);
95: assertTrue(e.getCause().getMessage() == null);
96: }
97: }
98:
99: }
|