Debian Codegraph @

test/providers/TestBasicProvider.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.providers;
18
19 import javax.wsdl.*;
20 import javax.wsdl.Definition;
21 import javax.wsdl.Input;
22 import javax.wsdl.Operation;
23 import javax.wsdl.PortType;
24 import javax.wsdl.factory.WSDLFactory;
25 import javax.xml.namespace.QName;
26
27 import org.apache.axis.MessageContext;
28 import org.apache.axis.configuration.XMLStringProvider;
29 import org.apache.axis.deployment.wsdd.WSDDConstants;
30 import org.apache.axis.deployment.wsdd.WSDDProvider;
31 import org.apache.axis.handlers.soap.SOAPService;
32 import org.apache.axis.providers.BasicProvider;
33 import org.apache.axis.server.AxisServer;
34 import org.apache.axis.transport.local.LocalTransport;
35 import org.w3c.dom.Document;
36
37 import junit.framework.TestCase;
38
39 /**
40 * Test if BasicProvider can generate WSDL out of metainformation provided in the
41 * WSDD descriptor.
42 *
43 * @author Thomas Bayer ([email protected])
44 *
45 */
46 public class TestBasicProvider extends TestCase {
47
48 static final QName PROVIDERQNAME = new QName( WSDDConstants.URI_WSDD_JAVA, WSDDDummyProvider.NAME);
49 static final String TNS = "http://axis.apache.org/test/provider/";
50 static final String SERVICE_NAME = "DummyProviderService";
51
52 static final String PORTTYPE = "DummyPort";
53 static final QName PORTTYPEQNAME = new QName( TNS, PORTTYPE);
54
55 private static AxisServer server;
56
57 static final String wsdd =
58 "<deployment xmlns=\"" + WSDDConstants.URI_WSDD + "\" "
59 + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
60 + "xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n"
61 + " <service name=\"" + SERVICE_NAME + "\" provider=\"java:DUMMY\">\n"
62 + " <parameter name=\"className\" value=\"" + TestBasicProvider.class.getName() + "\"/>"
63 + " <parameter name=\"wsdlPortType\" value=\"" + PORTTYPE + "\"/>"
64 + " <parameter name=\"wsdlTargetNamespace\" value=\"" + TNS + "\"/>"
65 + " <operation name=\"method1\">"
66 + " <parameter name=\"param1\" type=\"xsd:string\"/>"
67 + " </operation>"
68 + " </service>\n"
69 + "</deployment>";
70
71 public TestBasicProvider() {
72 super("test");
73 }
74
75 public TestBasicProvider(String s) {
76 super(s);
77 }
78
79 protected void setUp() throws Exception {
80
81 server = new AxisServer(new XMLStringProvider(wsdd));
82
83 LocalTransport transport;
84
85 transport = new LocalTransport(server);
86 transport.setRemoteService(SERVICE_NAME);
87
88 WSDDProvider.registerProvider( PROVIDERQNAME, new WSDDDummyProvider());
89 }
90
91 public void testGenerateWSDL() throws Exception {
92
93 SOAPService soapService = server.getService(SERVICE_NAME);
94
95 BasicProvider provider = (BasicProvider) soapService.getPivotHandler();
96
97 MessageContext mc = new MessageContext(server);
98 mc.setService(soapService);
99 mc.setProperty(MessageContext.TRANS_URL, "local");
100
101 provider.generateWSDL(mc);
102
103 Document wsdl = (Document) mc.getProperty("WSDL");
104 assertNotNull( "cannot create WSDL", wsdl);
105
106 Definition def = WSDLFactory.newInstance().newWSDLReader().readWSDL( null, wsdl);
107
108 PortType portType = def.getPortType( PORTTYPEQNAME);
109 assertNotNull( "cannot find porttype " + PORTTYPEQNAME, portType);
110
111 Operation operation = portType.getOperation( "method1", null, null);
112 assertNotNull( "cannot find operation ", operation);
113
114 Input input = operation.getInput();
115
116 javax.wsdl.Message message = def.getMessage( new QName( TNS, input.getName()));
117 assertNotNull( "cannot find message " + input.getName(), message);
118
119 Part part = message.getPart("param1");
120 assertEquals( "wrong type for part", part.getTypeName().getLocalPart(), "string");
121
122 }
123
124 public static void main(String args[]) throws Exception {
125 TestBasicProvider tester = new TestBasicProvider();
126 tester.setUp();
127 tester.testGenerateWSDL();
128 }
129
130 }