Debian Codegraph @

test/faults/TestBeans.java

raw
1 /*
2 * Copyright 2002-2004 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 test.faults;
18
19 import org.apache.axis.client.Call;
20 import org.apache.axis.encoding.TypeMapping;
21 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
22 import org.apache.axis.encoding.ser.BeanSerializerFactory;
23 import org.apache.axis.constants.Style;
24 import org.apache.axis.Constants;
25 import org.apache.axis.AxisFault;
26 import test.GenericLocalTest;
27
28 import javax.xml.namespace.QName;
29 import javax.xml.rpc.ParameterMode;
30
31 /**
32 * Confirm that faults using beans work
33 */
34 public class TestBeans extends GenericLocalTest {
35 private QName TYPE_QNAME = new QName("ns", "dataType");
36
37 public TestBeans() {
38 super("service");
39 }
40
41 public TestBeans(String s) {
42 super(s);
43 }
44
45 protected void setUp() throws Exception {
46 super.setUp(false); // don't deploy here
47 TypeMapping tm = (TypeMapping)config.getTypeMappingRegistry().
48 getDefaultTypeMapping();
49 tm.register(BeanFault.class, TYPE_QNAME,
50 new BeanSerializerFactory(BeanFault.class, TYPE_QNAME),
51 new BeanDeserializerFactory(BeanFault.class, TYPE_QNAME));
52 deploy("service", this.getClass(), Style.WRAPPED);
53 //tm.register(BeanFault2.class, TYPE_QNAME,
54 // new BeanSerializerFactory(BeanFault2.class, TYPE_QNAME),
55 // new BeanDeserializerFactory(BeanFault2.class, TYPE_QNAME));
56 }
57
58 public void testBeanFault() throws Exception {
59 Call call = getCall();
60 call.setOperationStyle("wrapped");
61 call.setOperationUse("literal");
62 call.setEncodingStyle("");
63 call.registerTypeMapping(BeanFault.class, TYPE_QNAME,
64 new BeanSerializerFactory(BeanFault.class, TYPE_QNAME),
65 new BeanDeserializerFactory(BeanFault.class, TYPE_QNAME));
66 call.setReturnClass(BeanFault.class);
67 call.addParameter("arg0", Constants.XSD_STRING, ParameterMode.IN);
68 String data = "bean fault test - 1";
69 try {
70 call.invoke("echoString", new Object [] { data });
71 } catch (AxisFault af){
72 assertNotNull(af.detail);
73 assertEquals(BeanFault.class,af.detail.getClass());
74 assertEquals(data,((BeanFault)af.detail).getMessage());
75 return;
76 }
77 fail("did not catch fault");
78 }
79
80 public void testBeanFault2() throws Exception {
81 Call call = getCall();
82 call.setOperationStyle("wrapped");
83 call.setOperationUse("literal");
84 call.setEncodingStyle("");
85 call.registerTypeMapping(BeanFault2.class, TYPE_QNAME,
86 new BeanSerializerFactory(BeanFault2.class, TYPE_QNAME),
87 new BeanDeserializerFactory(BeanFault2.class, TYPE_QNAME));
88 call.setReturnClass(BeanFault2.class);
89 call.addParameter("arg0", Constants.XSD_STRING, ParameterMode.IN);
90 String data = "bean fault test - 2";
91 try {
92 call.invoke("echoString2", new Object [] { data });
93 } catch (AxisFault af){
94 assertNotNull(af.detail);
95 assertEquals(BeanFault2.class,af.detail.getClass());
96 assertEquals(data,((BeanFault2)af.detail).getMessage());
97 return;
98 }
99 fail("did not catch fault");
100 }
101
102 public String echoString(String data) throws BeanFault {
103 BeanFault f = new BeanFault();
104 f.setMessage(data);
105 throw f;
106 }
107
108 public String echoString2(String data) throws BeanFault2 {
109 BeanFault2 f = new BeanFault2(data);
110 throw f;
111 }
112 }