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 javax.jws.WebMethod;
022: import javax.jws.WebService;
023: import javax.xml.namespace.QName;
024: import javax.xml.ws.AsyncHandler;
025: import javax.xml.ws.Response;
026:
027: import java.util.concurrent.Future;
028:
029: import junit.framework.TestCase;
030:
031: /**
032: *
033: */
034: public class GetSyncOperationTests extends TestCase {
035:
036: public void testNoSyncOperation() {
037: ServiceDescription sDesc = DescriptionFactory
038: .createServiceDescription(null, new QName(
039: "org.apache.axis2.jaxws.description",
040: "syncOperationTestService2"),
041: javax.xml.ws.Service.class);
042: EndpointDescription eDesc = DescriptionFactory.updateEndpoint(
043: sDesc, AsyncOnlySEI.class, new QName(
044: "org.apache.axis2.jaxws.description",
045: "syncOperationTestPort2"),
046: DescriptionFactory.UpdateType.GET_PORT);
047: EndpointInterfaceDescription eiDesc = eDesc
048: .getEndpointInterfaceDescription();
049: OperationDescription opDescs[] = eiDesc.getOperations();
050: assertNotNull(opDescs);
051: assertEquals(2, opDescs.length);
052: // Make sure each of the async operations reference the sync opDesc
053: int asyncOperations = 0;
054: OperationDescription syncOpDescs[] = eiDesc
055: .getOperationForJavaMethod("echo");
056: assertNull(syncOpDescs);
057: for (OperationDescription opDesc : opDescs) {
058: if (opDesc.isJAXWSAsyncClientMethod()) {
059: asyncOperations++;
060: }
061: // Since there isn't a sync method in the (invalid) SEI, then this should return null
062: assertNull(opDesc.getSyncOperation());
063: }
064: assertEquals(2, asyncOperations);
065: }
066:
067: public void testSyncOperation() {
068: ServiceDescription sDesc = DescriptionFactory
069: .createServiceDescription(null, new QName(
070: "org.apache.axis2.jaxws.description",
071: "syncOperationTestService1"),
072: javax.xml.ws.Service.class);
073: EndpointDescription eDesc = DescriptionFactory.updateEndpoint(
074: sDesc, SyncAndAsyncSEI.class, new QName(
075: "org.apache.axis2.jaxws.description",
076: "syncOperationTestPort1"),
077: DescriptionFactory.UpdateType.GET_PORT);
078: EndpointInterfaceDescription eiDesc = eDesc
079: .getEndpointInterfaceDescription();
080: OperationDescription opDescs[] = eiDesc.getOperations();
081: assertNotNull(opDescs);
082: assertEquals(3, opDescs.length);
083: // Make sure each of the async operations reference the sync opDesc
084: int asyncOperations = 0;
085: OperationDescription syncOpDescs[] = eiDesc
086: .getOperationForJavaMethod("echo");
087: assertNotNull(syncOpDescs);
088: assertEquals(1, syncOpDescs.length);
089: OperationDescription syncOpDesc = syncOpDescs[0];
090:
091: for (OperationDescription opDesc : opDescs) {
092: if (opDesc.isJAXWSAsyncClientMethod()) {
093: asyncOperations++;
094: }
095: // Make sure all the operations point to the sync operation
096: assertEquals(syncOpDesc, opDesc.getSyncOperation());
097: }
098:
099: assertEquals(2, asyncOperations);
100: }
101:
102: }
103:
104: @WebService
105: interface AsyncOnlySEI {
106: // Note this is an INVALID SEI since it only contains the
107: // JAXWS client async methods, and not the corresponding sync
108: // method.
109: @WebMethod(operationName="echo")
110: public Response<String> echoAsync(String toEcho);
111:
112: @WebMethod(operationName="echo")
113: public Future<?> echoAsync(String toEcho,
114: AsyncHandler<String> asyncHandler);
115: }
116:
117: @WebService
118: interface SyncAndAsyncSEI {
119: @WebMethod(operationName="echo")
120: public Response<String> echoAsync(String toEcho);
121:
122: @WebMethod(operationName="echo")
123: public Future<?> echoAsync(String toEcho,
124: AsyncHandler<String> asyncHandler);
125:
126: @WebMethod(operationName="echo")
127: public String echo(String toEcho);
128: }
|