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: */package org.apache.cxf.systest.jaxws;
019:
020: import java.util.concurrent.Executor;
021:
022: import javax.jws.WebService;
023: import javax.xml.ws.Response;
024:
025: import org.apache.cxf.greeter_control.AbstractGreeterImpl;
026: import org.apache.cxf.greeter_control.BasicGreeterService;
027: import org.apache.cxf.greeter_control.Greeter;
028: import org.apache.cxf.greeter_control.types.GreetMeResponse;
029: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
030: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
031: import org.junit.BeforeClass;
032: import org.junit.Test;
033:
034: /**
035: *
036: */
037: public class JaxwsExecutorTest extends AbstractBusClientServerTestBase {
038:
039: public static class Server extends AbstractBusTestServerBase {
040:
041: protected void run() {
042: GreeterImpl implementor = new GreeterImpl();
043: String address = "http://localhost:9020/SoapContext/GreeterPort";
044: javax.xml.ws.Endpoint.publish(address, implementor);
045: }
046:
047: public static void main(String[] args) {
048: try {
049: Server s = new Server();
050: s.start();
051: } catch (Exception ex) {
052: ex.printStackTrace();
053: System.exit(-1);
054: } finally {
055: System.out.println("done!");
056: }
057: }
058:
059: @WebService(serviceName="BasicGreeterService",portName="GreeterPort",endpointInterface="org.apache.cxf.greeter_control.Greeter",targetNamespace="http://cxf.apache.org/greeter_control",wsdlLocation="testutils/greeter_control.wsdl")
060: public class GreeterImpl extends AbstractGreeterImpl {
061: }
062: }
063:
064: @BeforeClass
065: public static void startServers() throws Exception {
066: assertTrue("server did not launch correctly",
067: launchServer(Server.class));
068: }
069:
070: @Test
071: public void testUseCustomExecutorOnClient() throws Exception {
072: BasicGreeterService service = new BasicGreeterService();
073:
074: class CustomExecutor implements Executor {
075:
076: private int count;
077:
078: public void execute(Runnable command) {
079: count++;
080: command.run();
081: }
082:
083: public int getCount() {
084: return count;
085: }
086: }
087:
088: CustomExecutor executor = new CustomExecutor();
089: service.setExecutor(executor);
090: assertSame(executor, service.getExecutor());
091:
092: Greeter proxy = service.getGreeterPort();
093:
094: assertEquals(0, executor.getCount());
095:
096: Response<GreetMeResponse> response = proxy.greetMeAsync("cxf");
097: int waitCount = 0;
098: while (!response.isDone() && waitCount < 10) {
099: Thread.sleep(100);
100: waitCount++;
101: }
102: assertTrue("Response still not received.", response.isDone());
103:
104: assertEquals(1, executor.getCount());
105: }
106:
107: }
|