View Javadoc

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