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: package org.apache.axis2.jaxws.description;
020:
021: import junit.framework.TestCase;
022: import org.apache.log4j.BasicConfigurator;
023:
024: import javax.jws.WebService;
025: import javax.xml.ws.Provider;
026: import javax.xml.ws.WebServiceProvider;
027:
028: public class ServiceAnnotationTests extends TestCase {
029: static {
030: // Note you will probably need to increase the java heap size, for example
031: // -Xmx512m. This can be done by setting maven.junit.jvmargs in project.properties.
032: // To change the settings, edit the log4j.property file
033: // in the test-resources directory.
034: BasicConfigurator.configure();
035: }
036:
037: public void testWebServiceDefaults() {
038: String className = "WebServiceDefaultTest";
039: EndpointDescriptionJava testEndpointDesc = getEndpointDesc(WebServiceDefaultTest.class);
040: assertNotNull(testEndpointDesc.getAnnoWebService());
041: assertNull(testEndpointDesc.getAnnoWebServiceProvider());
042: assertEquals(className, testEndpointDesc
043: .getAnnoWebServiceName());
044: assertEquals("", testEndpointDesc
045: .getAnnoWebServiceEndpointInterface());
046: assertEquals("http://description.jaxws.axis2.apache.org/",
047: testEndpointDesc.getAnnoWebServiceTargetNamespace());
048: assertEquals(className + "Service", testEndpointDesc
049: .getAnnoWebServiceServiceName());
050: assertEquals(className + "Port", testEndpointDesc
051: .getAnnoWebServicePortName());
052: assertEquals("", testEndpointDesc
053: .getAnnoWebServiceWSDLLocation());
054: }
055:
056: public void testWebServiceProviderDefaults() {
057: String className = "WebServiceProviderDefaultTest";
058: EndpointDescriptionJava testEndpointDesc = getEndpointDesc(WebServiceProviderDefaultTest.class);
059: assertNull(testEndpointDesc.getAnnoWebService());
060: assertNotNull(testEndpointDesc.getAnnoWebServiceProvider());
061: // name element not allowed on WebServiceProvider
062: assertEquals("", testEndpointDesc.getAnnoWebServiceName());
063: // EndpointInterface element not allowed on WebServiceProvider
064: assertEquals("", testEndpointDesc
065: .getAnnoWebServiceEndpointInterface());
066: assertEquals("http://description.jaxws.axis2.apache.org/",
067: testEndpointDesc.getAnnoWebServiceTargetNamespace());
068: assertEquals(className + "Service", testEndpointDesc
069: .getAnnoWebServiceServiceName());
070: assertEquals(className + "Port", testEndpointDesc
071: .getAnnoWebServicePortName());
072: assertEquals("", testEndpointDesc
073: .getAnnoWebServiceWSDLLocation());
074: }
075:
076: public void testWebServiceName() {
077: String className = "WebServiceName";
078: EndpointDescriptionJava testEndpointDesc = getEndpointDesc(WebServiceName.class);
079: assertNotNull(testEndpointDesc.getAnnoWebService());
080: assertNull(testEndpointDesc.getAnnoWebServiceProvider());
081: assertEquals("WebServiceNameElement", testEndpointDesc
082: .getAnnoWebServiceName());
083: assertEquals("", testEndpointDesc
084: .getAnnoWebServiceEndpointInterface());
085: assertEquals("http://description.jaxws.axis2.apache.org/",
086: testEndpointDesc.getAnnoWebServiceTargetNamespace());
087: // Note that per JSR-181 MR Sec 4.1 pg 16, the portName uses WebService.name, but serviceName does not!
088: assertEquals(className + "Service", testEndpointDesc
089: .getAnnoWebServiceServiceName());
090: assertEquals("WebServiceNameElementPort", testEndpointDesc
091: .getAnnoWebServicePortName());
092: assertEquals("", testEndpointDesc
093: .getAnnoWebServiceWSDLLocation());
094: }
095:
096: public void testWebServiceNameAndPort() {
097: String className = "WebServiceNameAndPort";
098: EndpointDescriptionJava testEndpointDesc = getEndpointDesc(WebServiceNameAndPort.class);
099: assertNotNull(testEndpointDesc.getAnnoWebService());
100: assertNull(testEndpointDesc.getAnnoWebServiceProvider());
101: assertEquals("WebServiceNameAndPortElement", testEndpointDesc
102: .getAnnoWebServiceName());
103: assertEquals("", testEndpointDesc
104: .getAnnoWebServiceEndpointInterface());
105: assertEquals("http://description.jaxws.axis2.apache.org/",
106: testEndpointDesc.getAnnoWebServiceTargetNamespace());
107: // Note that per JSR-181 MR Sec 4.1 pg 16, the portName uses WebService.name, but serviceName does not!
108: assertEquals(className + "Service", testEndpointDesc
109: .getAnnoWebServiceServiceName());
110: assertEquals("WebServicePortName", testEndpointDesc
111: .getAnnoWebServicePortName());
112: assertEquals("", testEndpointDesc
113: .getAnnoWebServiceWSDLLocation());
114: }
115:
116: public void testWebServiceAll() {
117: String className = "WebServiceAll";
118: EndpointDescriptionJava testEndpointDesc = getEndpointDesc(WebServiceAll.class);
119: assertNotNull(testEndpointDesc.getAnnoWebService());
120: assertNull(testEndpointDesc.getAnnoWebServiceProvider());
121: assertEquals("WebServiceAll", testEndpointDesc
122: .getAnnoWebServiceName());
123: assertEquals(
124: "org.apache.axis2.jaxws.description.MyEndpointInterface",
125: testEndpointDesc.getAnnoWebServiceEndpointInterface());
126: assertEquals("http://namespace.target.jaxws.axis2.apache.org/",
127: testEndpointDesc.getAnnoWebServiceTargetNamespace());
128: assertEquals("WebServiceAllServiceElement", testEndpointDesc
129: .getAnnoWebServiceServiceName());
130: assertEquals("WebServiceAllPortElement", testEndpointDesc
131: .getAnnoWebServicePortName());
132: // TODO: When the JavaReflection-to-DBC converter is fixed to read in WSDL, then add this check back in.
133: // assertEquals("http://my.wsdl.location/foo.wsdl", testEndpointDesc.getAnnoWebServiceWSDLLocation());
134: }
135:
136: public void testWebServiceProviderAll() {
137: String className = "WebServiceProviderAll";
138: EndpointDescriptionJava testEndpointDesc = getEndpointDesc(WebServiceProviderAll.class);
139: assertNull(testEndpointDesc.getAnnoWebService());
140: assertNotNull(testEndpointDesc.getAnnoWebServiceProvider());
141: assertEquals("", testEndpointDesc.getAnnoWebServiceName());
142: assertEquals("", testEndpointDesc
143: .getAnnoWebServiceEndpointInterface());
144: assertEquals("http://namespace.target.jaxws.axis2.apache.org/",
145: testEndpointDesc.getAnnoWebServiceTargetNamespace());
146: assertEquals("WebServiceProviderAllServiceElement",
147: testEndpointDesc.getAnnoWebServiceServiceName());
148: assertEquals("WebServiceProviderAllPortElement",
149: testEndpointDesc.getAnnoWebServicePortName());
150: assertEquals("http://my.wsdl.other.location/foo.wsdl",
151: testEndpointDesc.getAnnoWebServiceWSDLLocation());
152:
153: }
154:
155: /*
156: * Method to return the endpoint interface description for a given implementation class.
157: */
158: private EndpointDescriptionJava getEndpointDesc(
159: Class implementationClass) {
160: // Use the description factory directly; this will be done within the JAX-WS runtime
161: ServiceDescription serviceDesc = DescriptionFactory
162: .createServiceDescription(implementationClass);
163: assertNotNull(serviceDesc);
164:
165: EndpointDescription[] endpointDesc = serviceDesc
166: .getEndpointDescriptions();
167: assertNotNull(endpointDesc);
168: assertEquals(1, endpointDesc.length);
169:
170: // TODO: How will the JAX-WS dispatcher get the appropriate port (i.e. endpoint)? Currently assumes [0]
171: EndpointDescription testEndpointDesc = endpointDesc[0];
172: return (EndpointDescriptionJava) testEndpointDesc;
173: }
174: }
175:
176: // ===============================================
177: // WebService Defaults test impl
178: // ===============================================
179:
180: @WebService()
181: class WebServiceDefaultTest {
182:
183: }
184:
185: @WebServiceProvider()
186: class WebServiceProviderDefaultTest implements Provider<String> {
187: public WebServiceProviderDefaultTest() {
188: }
189:
190: public String invoke(String obj) {
191: return null;
192: }
193:
194: }
195:
196: // ===============================================
197: // WebService Name test impl
198: // ===============================================
199: // Note that name is only allowed on @WebService; not @WebServiceProvider
200:
201: @WebService(name="WebServiceNameElement")
202: class WebServiceName {
203:
204: }
205:
206: @WebService(name="WebServiceNameAndPortElement",portName="WebServicePortName")
207: class WebServiceNameAndPort {
208:
209: }
210:
211: // ===============================================
212: // WebService All test impl
213: // ===============================================
214: // TODO: When the JavaReflection-to-DBC converter is fixed to read in the WSDL, then specify a valid WSDL file here
215:
216: @WebService(endpointInterface="org.apache.axis2.jaxws.description.MyEndpointInterface",targetNamespace="http://namespace.target.jaxws.axis2.apache.org/",serviceName="WebServiceAllServiceElement",portName="WebServiceAllPortElement")
217: class WebServiceAll {
218:
219: }
220:
221: @WebService()
222: interface MyEndpointInterface {
223:
224: }
225:
226: @WebServiceProvider(targetNamespace="http://namespace.target.jaxws.axis2.apache.org/",serviceName="WebServiceProviderAllServiceElement",portName="WebServiceProviderAllPortElement",wsdlLocation="http://my.wsdl.other.location/foo.wsdl")
227: class WebServiceProviderAll implements Provider<String> {
228: public WebServiceProviderAll() {
229: }
230:
231: public String invoke(String obj) {
232: return null;
233: }
234:
235: }
|