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.RequestWrapper;
026: import javax.xml.ws.ResponseWrapper;
027: import javax.xml.ws.WebFault;
028:
029: /** Tests the request and response wrappers. */
030: public class WrapperPackageTests extends TestCase {
031: static {
032: // Note you will probably need to increase the java heap size, for example
033: // -Xmx512m. This can be done by setting maven.junit.jvmargs in project.properties.
034: // To change the settings, edit the log4j.property file
035: // in the test-resources directory.
036: BasicConfigurator.configure();
037: }
038:
039: public void testSEIPackageWrapper() {
040: EndpointInterfaceDescription eiDesc = getEndpointInterfaceDesc(SEIPackageWrapper.class);
041: OperationDescription opDesc = eiDesc.getOperation("method1");
042: String requestWrapperClass = opDesc
043: .getRequestWrapperClassName();
044:
045: // The algorithm to find the response wrapper is not defined by the specification.
046: // The marshalling layer (jaxws) can use proprietary mechanisms to find, build or operate
047: // without the wrapper class.
048:
049: //assertEquals("org.apache.axis2.jaxws.description.Method1", requestWrapperClass);
050: assertEquals(null, requestWrapperClass);
051:
052: String responseWrapperClass = opDesc
053: .getResponseWrapperClassName();
054: //assertEquals("org.apache.axis2.jaxws.description.Method1Response", responseWrapperClass);
055: assertEquals(null, responseWrapperClass);
056:
057: FaultDescription fDesc = opDesc.getFaultDescriptions()[0];
058: String faultExceptionClass = fDesc.getExceptionClassName();
059: assertEquals(
060: "org.apache.axis2.jaxws.description.Method1Exception",
061: faultExceptionClass);
062: String faultBeanClass = fDesc.getFaultBean();
063: assertEquals(
064: "org.apache.axis2.jaxws.description.ExceptionBean",
065: faultBeanClass);
066:
067: }
068:
069: public void testSEISubPackageWrapper() {
070: EndpointInterfaceDescription eiDesc = getEndpointInterfaceDesc(SEISubPackageWrapper.class);
071: OperationDescription opDesc = eiDesc
072: .getOperation("subPackageMethod1");
073: // The algorithm to find the response wrapper is not defined by the specification.
074: // The marshalling layer (jaxws) can use proprietary mechanisms to find, build or operate
075: // without the wrapper class.
076:
077: String requestWrapperClass = opDesc
078: .getRequestWrapperClassName();
079: //assertEquals("org.apache.axis2.jaxws.description.jaxws.SubPackageMethod1", requestWrapperClass);
080: assertEquals(null, requestWrapperClass);
081: String responseWrapperClass = opDesc
082: .getResponseWrapperClassName();
083: //assertEquals("org.apache.axis2.jaxws.description.jaxws.SubPackageMethod1Response", responseWrapperClass);
084: assertEquals(null, responseWrapperClass);
085: FaultDescription fDesc = opDesc.getFaultDescriptions()[0];
086: String faultExceptionClass = fDesc.getExceptionClassName();
087: assertEquals(
088: "org.apache.axis2.jaxws.description.SubPackageException",
089: faultExceptionClass);
090: String faultBeanClass = fDesc.getFaultBean();
091: // Due to the missing getFaultInfo, the runtime must find or build a fault bean.
092: assertEquals("", faultBeanClass);
093: //assertEquals("org.apache.axis2.jaxws.description.jaxws.SubPackageExceptionBean", faultBeanClass);
094:
095: }
096:
097: /*
098: * Method to return the endpoint interface description for a given implementation class.
099: */
100: private EndpointInterfaceDescription getEndpointInterfaceDesc(
101: Class implementationClass) {
102: // Use the description factory directly; this will be done within the JAX-WS runtime
103: ServiceDescription serviceDesc = DescriptionFactory
104: .createServiceDescription(implementationClass);
105: assertNotNull(serviceDesc);
106:
107: EndpointDescription[] endpointDesc = serviceDesc
108: .getEndpointDescriptions();
109: assertNotNull(endpointDesc);
110: assertEquals(1, endpointDesc.length);
111:
112: // TODO: How will the JAX-WS dispatcher get the appropriate port (i.e. endpoint)? Currently assumes [0]
113: EndpointDescription testEndpointDesc = endpointDesc[0];
114: EndpointInterfaceDescription testEndpointInterfaceDesc = testEndpointDesc
115: .getEndpointInterfaceDescription();
116: assertNotNull(testEndpointInterfaceDesc);
117:
118: return testEndpointInterfaceDesc;
119: }
120: }
121:
122: @WebService()
123: class SEIPackageWrapper {
124: @RequestWrapper()
125: @ResponseWrapper()
126: public String method1(String string) throws Method1Exception {
127: return string;
128: }
129: }
130:
131: class Method1 {
132:
133: }
134:
135: class Method1Response {
136:
137: }
138:
139: @WebFault()
140: class Method1Exception extends Exception {
141: public ExceptionBean getFaultInfo() {
142: return null;
143: }
144: }
145:
146: class ExceptionBean {
147:
148: }
149:
150: @WebFault
151: class SubPackageException extends Exception {
152: // No getFaultInfo method
153: }
154:
155: @WebService()
156: class SEISubPackageWrapper {
157: @RequestWrapper()
158: @ResponseWrapper()
159: public String subPackageMethod1(String string)
160: throws SubPackageException {
161: return string;
162: }
163: }
|