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;
021:
022: import java.lang.reflect.Method;
023:
024: import javax.xml.namespace.QName;
025: import javax.xml.ws.Service;
026:
027: import junit.framework.TestCase;
028: import org.apache.axis2.jaxws.spi.ServiceDelegate;
029:
030: /**
031: * Directly test the Description classes built via annotations without a WSDL file.
032: * These tests focus on combinations of the following:
033: * - A generic service (no annotations)
034: * - A generated service (annotations)
035: * - An SEI
036: */
037: public class AnnotationDescriptionTests extends TestCase {
038:
039: /*
040: * ========================================================================
041: * ServiceDescription Tests
042: * ========================================================================
043: */
044: public void testCreateService() {
045: String namespaceURI = "http://ws.apache.org/axis2/tests";
046: String localPart = "EchoServiceAnnotated";
047: Service service = Service.create(null, new QName(namespaceURI,
048: localPart));
049: ServiceDelegate serviceDelegate = DescriptionTestUtils2
050: .getServiceDelegate(service);
051: ServiceDescription serviceDescription = serviceDelegate
052: .getServiceDescription();
053: String portLocalPart = "EchoServiceAnnotatedPort";
054: QName portQName = new QName(namespaceURI, portLocalPart);
055: DocLitWrappedProxy dlwp = service.getPort(portQName,
056: DocLitWrappedProxy.class);
057:
058: // Validate that the Endpoint and EndpointInterface Descriptions were created correctly
059: EndpointDescription endpointDescription = serviceDescription
060: .getEndpointDescription(portQName);
061: assertNotNull("Endpoint not created ", endpointDescription);
062: EndpointInterfaceDescription endpointInterfaceDescription = endpointDescription
063: .getEndpointInterfaceDescription();
064: assertNotNull("EndpointInterface not created",
065: endpointInterfaceDescription);
066: // Verify we can get the same endpoint description based on the SEI class
067: EndpointDescription[] fromSEIClass = serviceDescription
068: .getEndpointDescription(DocLitWrappedProxy.class);
069: assertEquals(1, fromSEIClass.length);
070: assertEquals(endpointDescription, fromSEIClass[0]);
071:
072: // Test getOperation methods parameter validation
073: OperationDescription[] operationResultArray = endpointInterfaceDescription
074: .getOperation((QName) null);
075: assertNull(operationResultArray);
076: operationResultArray = endpointInterfaceDescription
077: .getOperation(new QName("", ""));
078: assertNull(operationResultArray);
079: OperationDescription operationResult = endpointInterfaceDescription
080: .getOperation((Method) null);
081: assertNull(operationResult);
082:
083: // Test getOperations(): Number of methods on SEI should match number of operationDescriptions
084: Method[] seiMethods = DocLitWrappedProxy.class.getMethods();
085: operationResultArray = endpointInterfaceDescription
086: .getOperations();
087: assertEquals(
088: "Number of SEI methods and operations did not match",
089: seiMethods.length, operationResultArray.length);
090:
091: // Test getOperation(QName)
092: // Verify @WebMethod.name is used if present. See the SEI class annotations for more information
093: // The SEI has @WebMethod annotations that override the name of "invokeAsync", so none should be found.
094: QName javaMethodQName = new QName("", "invokeAsync");
095: operationResultArray = endpointInterfaceDescription
096: .getOperation(javaMethodQName);
097: assertNull(operationResultArray);
098: // The SEI has @WebMethod annotations that name three operations "invoke"
099: javaMethodQName = new QName("", "invoke");
100: operationResultArray = endpointInterfaceDescription
101: .getOperation(javaMethodQName);
102: assertNotNull(operationResultArray);
103: assertEquals(3, operationResultArray.length);
104:
105: // Test getOperation(Method)
106: // Verify an SEI method lookup works
107: operationResult = endpointInterfaceDescription
108: .getOperation(seiMethods[0]);
109: assertNotNull(operationResult);
110: // Verify a non-SEI method returns a null
111: operationResult = endpointInterfaceDescription
112: .getOperation(this .getClass().getMethods()[0]);
113: assertNull(operationResult);
114: }
115:
116: /*
117: * TO TEST
118: * - Invalid namespace. TNS in annotation doesn't match one from getPort
119: * - Multiple service.getPort() calls with same SEI and different QName, and that serviceDesc.getEndpointDesc(Class) returns multielement array
120: * - Test service.getPort(..) with same QName; should return same descrpption
121: */
122: /*
123: public void testValidServiceGetEndpoint() {
124: QName validPortQname = new QName("http://ws.apache.org/axis2/tests", "EchoPort");
125: EndpointDescription endpointDescription = serviceDescription.getEndpointDescription(validPortQname);
126: assertNotNull("EndpointDescription should be found", endpointDescription);
127: }
128:
129: public void testInvalidLocalpartServiceGetEndpoint() {
130: QName validPortQname = new QName("http://ws.apache.org/axis2/tests", "InvalidEchoPort");
131: EndpointDescription endpointDescription = serviceDescription.getEndpointDescription(validPortQname);
132: assertNull("EndpointDescription should not be found", endpointDescription);
133: }
134:
135: public void testInvalidNamespaceServiceGetEndpoint() {
136: QName validPortQname = new QName("http://ws.apache.org/axis2/tests/INVALID", "EchoPort");
137: EndpointDescription endpointDescription = serviceDescription.getEndpointDescription(validPortQname);
138: assertNull("EndpointDescription should not be found", endpointDescription);
139: }
140: */
141: }
|