001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.jaxws.description.builder;
021:
022: import junit.framework.TestCase;
023:
024: import javax.jws.WebParam.Mode;
025:
026: /**
027: * Directly test the Description classes built via annotations without a WSDL file. These tests
028: * focus on combinations of the following: - A generic service (no annotations) - A generated
029: * service (annotations) - An SEI
030: */
031: public class DescriptionBuilderTests extends TestCase {
032:
033: /*
034: * ========================================================================
035: * ServiceDescription Tests
036: * ========================================================================
037: */
038: public void testCreateWebServiceAnnot() {
039: String name = "EchoServiceAnnotated";
040: String targetNamespace = "http://description.jaxws.axis2.apache.org/";
041: String serviceName = "EchoServiceName";
042: String wsdlLocation = "http://EchoService/wsdl";
043: String endpointInterface = "EchoServiceEndpointInterface";
044: String portName = "EchoServiceAnnotatedPort";
045:
046: WebServiceAnnot webServiceAnnotImpl1 = WebServiceAnnot
047: .createWebServiceAnnotImpl();
048:
049: WebServiceAnnot webServiceAnnotImpl2 = WebServiceAnnot
050: .createWebServiceAnnotImpl(name, targetNamespace,
051: serviceName, wsdlLocation, endpointInterface,
052: portName);
053:
054: DescriptionBuilderComposite descriptionBuilderComposite = new DescriptionBuilderComposite();
055:
056: descriptionBuilderComposite
057: .setWebServiceAnnot(webServiceAnnotImpl2);
058:
059: WebServiceAnnot webServiceAnnotImpl3 = descriptionBuilderComposite
060: .getWebServiceAnnot();
061:
062: assertNotNull("WebService name not set", webServiceAnnotImpl3
063: .name());
064: assertNotNull("WebService targetNamespace not set",
065: webServiceAnnotImpl3.targetNamespace());
066: assertNotNull("WebService serviceName not set",
067: webServiceAnnotImpl3.serviceName());
068: assertNotNull("WebService wsdlLocation not set",
069: webServiceAnnotImpl3.wsdlLocation());
070: assertNotNull("WebService endpointInterface not set",
071: webServiceAnnotImpl3.endpointInterface());
072:
073: System.out.println("WebService name:"
074: + webServiceAnnotImpl3.name());
075: }
076:
077: public void testCreateWebServiceProviderAnnot() {
078: String name = "EchoServiceAnnotated";
079: String targetNamespace = "http://description.jaxws.axis2.apache.org/";
080: String serviceName = "EchoServiceName";
081: String wsdlLocation = "http://EchoService/wsdl";
082: String endpointInterface = "EchoServiceEndpointInterface";
083: String portName = "EchoServiceAnnotatedPort";
084:
085: WebServiceProviderAnnot webServiceProviderAnnot = WebServiceProviderAnnot
086: .createWebServiceAnnotImpl();
087:
088: webServiceProviderAnnot.setPortName(portName);
089: webServiceProviderAnnot.setServiceName(serviceName);
090: webServiceProviderAnnot.setTargetNamespace(targetNamespace);
091: webServiceProviderAnnot.setWsdlLocation(wsdlLocation);
092:
093: DescriptionBuilderComposite descriptionBuilderComposite = new DescriptionBuilderComposite();
094:
095: descriptionBuilderComposite
096: .setWebServiceProviderAnnot(webServiceProviderAnnot);
097:
098: WebServiceProviderAnnot webServiceProviderAnnot3 = descriptionBuilderComposite
099: .getWebServiceProviderAnnot();
100:
101: assertEquals("WebServiceProvider port name not set properly",
102: webServiceProviderAnnot3.portName(), portName);
103: assertEquals(
104: "WebServiceProvider targetNamespace not set properly",
105: webServiceProviderAnnot3.targetNamespace(),
106: targetNamespace);
107: assertEquals("WebServiceProvider serviceName not set properly",
108: webServiceProviderAnnot3.serviceName(), serviceName);
109: assertEquals(
110: "WebServiceProvider wsdlLocation not set properly",
111: webServiceProviderAnnot3.wsdlLocation(), wsdlLocation);
112: System.out.println("WebService name:"
113: + webServiceProviderAnnot3.portName());
114: }
115:
116: public void testCreateWebMethodAnnot() {
117: String operationName = "echoStringMethod";
118: String action = "urn:EchoStringMethod";
119: boolean exclude = true;
120:
121: WebMethodAnnot webMethodAnnot = WebMethodAnnot
122: .createWebMethodAnnotImpl();
123:
124: webMethodAnnot.setOperationName(operationName);
125: webMethodAnnot.setAction(action);
126: webMethodAnnot.setExclude(exclude);
127:
128: DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
129: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
130:
131: mdc.setWebMethodAnnot(webMethodAnnot);
132: mdc.setMethodName(operationName);
133: dbc.addMethodDescriptionComposite(mdc);
134:
135: WebMethodAnnot webMethodAnnot3 = dbc
136: .getMethodDescriptionComposite(operationName, 1)
137: .getWebMethodAnnot();
138:
139: assertEquals("WebMethod operation name not set properly",
140: webMethodAnnot3.operationName(), operationName);
141: assertEquals("WebMethod action not set properly",
142: webMethodAnnot3.action(), action);
143: assertEquals("WebMethod exclude flag not set properly",
144: webMethodAnnot3.exclude(), exclude);
145: }
146:
147: public void testCreateWebParamAnnot() {
148:
149: String name = "arg0";
150: String partName = "sku";
151: String targetNamespace = "http://description.jaxws.axis2.apache.org/";
152: Mode mode = Mode.IN;
153: boolean header = true;
154:
155: WebParamAnnot webParamAnnot = WebParamAnnot
156: .createWebParamAnnotImpl();
157:
158: webParamAnnot.setName(name);
159: webParamAnnot.setPartName(partName);
160: webParamAnnot.setMode(mode);
161: webParamAnnot.setTargetNamespace(targetNamespace);
162: webParamAnnot.setHeader(header);
163:
164: DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
165:
166: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
167: pdc.setWebParamAnnot(webParamAnnot);
168: pdc.setParameterType("int");
169:
170: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
171: mdc.setMethodName("TestMethod1");
172:
173: try {
174: //First test adds this pdc out of bounds
175: mdc.addParameterDescriptionComposite(pdc, 1);
176: } catch (IndexOutOfBoundsException e) {
177: // Expected flow
178: } catch (Exception e) {
179: fail("Caught unexpected exception" + e);
180: }
181:
182: try {
183: //Now, add it at the proper position
184: mdc.addParameterDescriptionComposite(pdc, 0);
185: } catch (IndexOutOfBoundsException e) {
186: // Expected flow
187: } catch (Exception e) {
188: fail("Caught unexpected exception" + e);
189: }
190:
191: dbc.addMethodDescriptionComposite(mdc);
192:
193: WebParamAnnot webParamAnnot3 = dbc
194: .getMethodDescriptionComposite("TestMethod1", 1)
195: .getParameterDescriptionComposite(0).getWebParamAnnot();
196:
197: assertEquals("WebMethod name not set properly", webParamAnnot3
198: .name(), name);
199: assertEquals("WebMethod PartName not set properly",
200: webParamAnnot3.partName(), partName);
201: assertEquals("WebMethod Mode flag not set properly",
202: webParamAnnot3.mode(), mode);
203: assertEquals("WebMethod Target Namespace not set properly",
204: webParamAnnot3.targetNamespace(), targetNamespace);
205: assertEquals("WebMethod Header not set properly",
206: webParamAnnot3.header(), header);
207:
208: assertEquals("Unable to convert string to parameterTypeClass",
209: pdc.getParameterTypeClass().getName(), "int");
210: }
211:
212: }
|