View Javadoc

1   /*
2    * $Id: JettyTestCase.java 23222 2011-10-19 17:35:57Z evangelinamrm $
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 static org.junit.Assert.assertEquals;
14  
15  import org.mule.api.MuleMessage;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.AbstractServiceAndFlowTestCase;
18  import org.mule.tck.junit4.rule.DynamicPort;
19  
20  import java.util.Arrays;
21  import java.util.Collection;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.apache.cxf.Bus;
26  import org.apache.cxf.BusFactory;
27  import org.apache.hello_world_soap_http.GreeterImpl;
28  import org.junit.AfterClass;
29  import org.junit.BeforeClass;
30  import org.junit.Rule;
31  import org.junit.Test;
32  import org.junit.runners.Parameterized.Parameters;
33  
34  public class JettyTestCase extends AbstractServiceAndFlowTestCase
35  {
36      private static final Bus defaultBus = BusFactory.getDefaultBus();
37  
38      @Rule
39      public DynamicPort dynamicPort = new DynamicPort("port1");
40  
41      public JettyTestCase(ConfigVariant variant, String configResources)
42      {
43          super(variant, configResources);
44      }
45  
46      @Parameters
47      public static Collection<Object[]> parameters()
48      {
49          return Arrays.asList(new Object[][]{
50              {ConfigVariant.SERVICE, "jetty-conf-service.xml"},
51              {ConfigVariant.FLOW, "jetty-conf-flow.xml"}
52          });
53      }      
54      
55      @BeforeClass
56      public static void setUpDefaultBus()
57      {
58          BusFactory.setDefaultBus(null);
59      }
60  
61      @AfterClass
62      public static void restoreDefaultBus()
63      {
64          BusFactory.setDefaultBus(defaultBus);
65      }
66  
67      @Test
68      public void testClientWithMuleClient() throws Exception
69      {
70          MuleClient client = new MuleClient(muleContext);
71          Map<String, Object> props = new HashMap<String, Object>();
72          props.put("operation", "greetMe");
73          MuleMessage result = client.send("clientEndpoint", "Dan", props);
74          assertEquals("Hello Dan", result.getPayload());
75  
76          GreeterImpl impl = getGreeter();
77  
78          Thread.sleep(3000);
79  
80          assertEquals(1, impl.getInvocationCount());
81      }
82  
83      private GreeterImpl getGreeter() throws Exception
84      {
85          Object instance = getComponent("greeterService");
86  
87          return (GreeterImpl) instance;
88      }
89  
90  }