1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 package org.seasar.remoting.axis.deployment;
47
48 import java.awt.Color;
49 import java.io.InputStream;
50 import java.io.Serializable;
51 import java.util.Arrays;
52 import java.util.Enumeration;
53 import java.util.HashSet;
54 import java.util.Set;
55 import java.util.Vector;
56
57 import javax.xml.namespace.QName;
58
59 import org.apache.axis.deployment.wsdd.WSDDConstants;
60 import org.apache.axis.deployment.wsdd.WSDDTypeMapping;
61 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
62 import org.apache.axis.encoding.ser.BeanSerializerFactory;
63 import org.apache.axis.providers.java.JavaProvider;
64 import org.apache.axis.utils.XMLUtils;
65 import org.seasar.extension.unit.S2TestCase;
66 import org.seasar.framework.container.ComponentDef;
67 import org.seasar.framework.util.ResourceUtil;
68 import org.seasar.remoting.axis.ServiceDef;
69 import org.seasar.remoting.axis.TypeMappingDef;
70 import org.w3c.dom.Element;
71 import org.w3c.dom.Node;
72 import org.w3c.dom.NodeList;
73
74 /***
75 * @author koichik
76 */
77 public class WSDDS2ServiceTest extends S2TestCase {
78 public WSDDS2ServiceTest(String name) {
79 super(name);
80 }
81
82 public void setUp() {
83 include("WSDDS2ServiceTest.dicon");
84 }
85
86 public void testNoInterface() throws Exception {
87 ComponentDef cd = getComponentDef("no");
88 WSDDS2Service s2Service = new WSDDS2Service(cd);
89
90 assertEquals("1", new QName("no"), s2Service.getQName());
91 assertEquals("2", "no", s2Service.getServiceDesc().getName());
92 assertEquals("3", "org.seasar.remoting.axis.deployment.WSDDS2ServiceTest$NoInterface",
93 s2Service.getParameter(JavaProvider.OPTION_CLASSNAME));
94 assertEquals("4", new QName(WSDDConstants.URI_WSDD_JAVA, "S2RPC"), s2Service
95 .getProviderQName());
96 assertNull("5", s2Service.getParameter(JavaProvider.OPTION_ALLOWEDMETHODS));
97 }
98
99 public void testIgnoreInterface() throws Exception {
100 ComponentDef cd = getComponentDef("ignore");
101 WSDDS2Service s2Service = new WSDDS2Service(cd);
102
103 assertEquals("1", new QName("ignore"), s2Service.getQName());
104 assertEquals("2", "ignore", s2Service.getServiceDesc().getName());
105 assertEquals("3", "org.seasar.remoting.axis.deployment.WSDDS2ServiceTest$IgnoreInterface",
106 s2Service.getParameter(JavaProvider.OPTION_CLASSNAME));
107 assertEquals("4", new QName(WSDDConstants.URI_WSDD_JAVA, "S2RPC"), s2Service
108 .getProviderQName());
109 assertNull("5", s2Service.getParameter(JavaProvider.OPTION_ALLOWEDMETHODS));
110 }
111
112 public void testOneInterface() throws Exception {
113 ComponentDef cd = getComponentDef("one");
114 WSDDS2Service s2Service = new WSDDS2Service(cd);
115
116 assertEquals("1", new QName("one"), s2Service.getQName());
117 assertEquals("2", "one", s2Service.getServiceDesc().getName());
118 assertEquals("3", "java.lang.Runnable", s2Service
119 .getParameter(JavaProvider.OPTION_CLASSNAME));
120 assertEquals("4", new QName(WSDDConstants.URI_WSDD_JAVA, "S2RPC"), s2Service
121 .getProviderQName());
122 assertNull("5", s2Service.getParameter(JavaProvider.OPTION_ALLOWEDMETHODS));
123 }
124
125 public void testTwoInterface() throws Exception {
126 ComponentDef cd = getComponentDef("two");
127 WSDDS2Service s2Service = new WSDDS2Service(cd);
128
129 assertEquals("1", new QName("two"), s2Service.getQName());
130 assertEquals("2", "two", s2Service.getServiceDesc().getName());
131 assertEquals("3", "org.seasar.remoting.axis.deployment.WSDDS2ServiceTest$TwoInterface",
132 s2Service.getParameter(JavaProvider.OPTION_CLASSNAME));
133 assertEquals("4", new QName(WSDDConstants.URI_WSDD_JAVA, "S2RPC"), s2Service
134 .getProviderQName());
135
136 Set allowMethods = new HashSet(Arrays.asList(s2Service.getParameter(
137 JavaProvider.OPTION_ALLOWEDMETHODS).split(" ")));
138 assertEquals("5", 3, allowMethods.size());
139 assertTrue("6", allowMethods.contains("run"));
140 assertTrue("7", allowMethods.contains("hasMoreElements"));
141 assertTrue("8", allowMethods.contains("nextElement"));
142 }
143
144 public void testServiceType() throws Exception {
145 ComponentDef cd = getComponentDef("two");
146 ServiceDef sd = new ServiceDef();
147 sd.setServiceType(Comparable.class);
148 WSDDS2Service s2Service = new WSDDS2Service(cd, sd);
149
150 assertEquals("1", "java.lang.Comparable", s2Service
151 .getParameter(JavaProvider.OPTION_CLASSNAME));
152 assertNull("2", s2Service.getParameter(JavaProvider.OPTION_ALLOWEDMETHODS));
153 }
154
155 public void testAlloeMethods() throws Exception {
156 ComponentDef cd = getComponentDef("two");
157 ServiceDef sd = new ServiceDef();
158 sd.setAllowedMethods("run hasMoreElements");
159 WSDDS2Service s2Service = new WSDDS2Service(cd, sd);
160
161 assertEquals("1", "org.seasar.remoting.axis.deployment.WSDDS2ServiceTest$TwoInterface",
162 s2Service.getParameter(JavaProvider.OPTION_CLASSNAME));
163
164 Set allowMethods = new HashSet(Arrays.asList(s2Service.getParameter(
165 JavaProvider.OPTION_ALLOWEDMETHODS).split(" ")));
166 assertEquals("2", 2, allowMethods.size());
167 assertTrue("3", allowMethods.contains("run"));
168 assertTrue("4", allowMethods.contains("hasMoreElements"));
169 }
170
171 public void testProvider() throws Exception {
172 ComponentDef cd = getComponentDef("no");
173 ServiceDef sd = new ServiceDef();
174 sd.setProvider("MSG");
175 WSDDS2Service s2Service = new WSDDS2Service(cd, sd);
176
177 assertEquals("1", new QName(WSDDConstants.URI_WSDD_JAVA, "S2MSG"), s2Service
178 .getProviderQName());
179 }
180
181 public void testTypeMapping() throws Exception {
182 ComponentDef cd = getComponentDef("no");
183 TypeMappingDef tmd = new TypeMappingDef();
184 tmd.setType(Color.class);
185 tmd.setLocalPart("COLOR");
186 tmd.setNamespaceURI("http://www.seasar.org/");
187 tmd.setNamespacePrefix("cc");
188 ServiceDef sd = new ServiceDef();
189 sd.addTypeMapping(tmd);
190 WSDDS2Service s2Service = new WSDDS2Service(cd, sd);
191
192 Vector typeMappings = s2Service.getTypeMappings();
193 assertEquals("1", 1, typeMappings.size());
194 WSDDTypeMapping tm = (WSDDTypeMapping) typeMappings.get(0);
195 assertEquals("2", new QName("http://www.seasar.org/", "COLOR", "cc"), tm.getQName());
196 assertEquals("3", BeanSerializerFactory.class, tm.getSerializer());
197 assertEquals("4", BeanDeserializerFactory.class, tm.getDeserializer());
198 }
199
200 public void testWSDD() throws Exception {
201 InputStream is = ResourceUtil
202 .getResourceAsStream("org/seasar/remoting/axis/deployment/WSDDS2ServiceTest.wsdd");
203 Element documentElement = XMLUtils.newDocument(is).getDocumentElement();
204 Element serviceElement = null;
205 NodeList children = documentElement.getChildNodes();
206 for (int i = 0; i < children.getLength(); i++) {
207 Node thisNode = children.item(i);
208 if (thisNode instanceof Element) {
209 serviceElement = (Element) thisNode;
210 break;
211 }
212 }
213
214 ComponentDef cd = getComponentDef("one");
215 WSDDS2Service s2Service = new WSDDS2Service(cd, serviceElement);
216 assertEquals("0", new QName(WSDDConstants.URI_WSDD_JAVA, "S2RPC"), s2Service
217 .getProviderQName());
218 }
219
220 public static class NoInterface {
221 public void foo() {
222 }
223 }
224
225 public static class IgnoreInterface implements Serializable {
226 public void foo() {
227 }
228 }
229
230 public static class OneInterface implements Runnable, Serializable {
231 public void run() {
232 }
233 }
234
235 public static class TwoInterface implements Runnable, Enumeration, Serializable {
236 public void run() {
237 }
238
239 public boolean hasMoreElements() {
240 return false;
241 }
242
243 public Object nextElement() {
244 return null;
245 }
246 }
247 }