View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.cxf.jaxws;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.tck.junit4.rule.DynamicPort;
13  
14  import java.util.HashMap;
15  import java.util.Map;
16  
17  import org.apache.cxf.Bus;
18  import org.apache.cxf.BusFactory;
19  import org.apache.hello_world_soap_http.GreeterImpl;
20  import org.junit.AfterClass;
21  import org.junit.BeforeClass;
22  import org.junit.Rule;
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertEquals;
26  
27  public class JettyTestCase extends FunctionalTestCase
28  {
29      private static final Bus defaultBus = BusFactory.getDefaultBus();
30  
31      @Rule
32      public DynamicPort dynamicPort = new DynamicPort("port1");
33  
34      @Override
35      protected String getConfigResources()
36      {
37          return "jetty-conf.xml";
38      }
39  
40      @BeforeClass
41      public static void setUpDefaultBus()
42      {
43          BusFactory.setDefaultBus(null);
44      }
45  
46      @AfterClass
47      public static void restoreDefaultBus()
48      {
49          BusFactory.setDefaultBus(defaultBus);
50      }
51  
52      @Test
53      public void testClientWithMuleClient() throws Exception
54      {
55          MuleClient client = new MuleClient(muleContext);
56          Map<String, Object> props = new HashMap<String, Object>();
57          props.put("operation", "greetMe");
58          MuleMessage result = client.send("clientEndpoint", "Dan", props);
59          assertEquals("Hello Dan", result.getPayload());
60  
61          GreeterImpl impl = getGreeter();
62  
63          Thread.sleep(3000);
64  
65          assertEquals(1, impl.getInvocationCount());
66      }
67  
68      private GreeterImpl getGreeter() throws Exception
69      {
70          Object instance = getComponent("greeterService");
71  
72          return (GreeterImpl) instance;
73      }
74  
75  }