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.transport.ssl;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.service.Service;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.functional.CounterCallback;
13  import org.mule.tck.functional.EventCallback;
14  import org.mule.tck.functional.FunctionalTestComponent;
15  import org.mule.tck.junit4.FunctionalTestCase;
16  import org.mule.tck.junit4.rule.DynamicPort;
17  import org.mule.tck.testmodels.mule.TestSedaService;
18  
19  import org.junit.Rule;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertTrue;
25  
26  public class SslFunctionalTestCase extends FunctionalTestCase 
27  {
28      private static int NUM_MESSAGES = 100;
29  
30      @Rule
31      public DynamicPort dynamicPort1 = new DynamicPort("port1");
32  
33      @Rule
34      public DynamicPort dynamicPort2 = new DynamicPort("port2");
35  
36      @Rule
37      public DynamicPort dynamicPort3 = new DynamicPort("port3");
38  
39      @Override
40      protected String getConfigResources()
41      {
42          return "ssl-functional-test.xml";
43      }
44  
45      @Test
46      public void testSend() throws Exception
47      {
48          MuleClient client = new MuleClient(muleContext);
49          MuleMessage result = client.send("sendEndpoint", TEST_MESSAGE, null);
50          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
51      }
52  
53      @Test
54      public void testSendMany() throws Exception
55      {
56          MuleClient client = new MuleClient(muleContext);
57          for (int i = 0; i < NUM_MESSAGES; ++i)
58          {
59              MuleMessage result = client.send("sendManyEndpoint", TEST_MESSAGE, null);
60              assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
61          }
62  
63          Service c = muleContext.getRegistry().lookupService("testComponent2");
64          assertTrue("Service should be a TestSedaService", c instanceof TestSedaService);
65          Object ftc = getComponent(c);
66          assertNotNull("Functional Test Service not found in the model.", ftc);
67          assertTrue("Service should be a FunctionalTestComponent", ftc instanceof FunctionalTestComponent);
68  
69          EventCallback cc = ((FunctionalTestComponent) ftc).getEventCallback();
70          assertNotNull("EventCallback is null", cc);
71          assertTrue("EventCallback should be a CounterCallback", cc instanceof CounterCallback);
72          assertEquals(NUM_MESSAGES, ((CounterCallback) cc).getCallbackCount());
73      }
74  
75      @Test
76      public void testAsynchronous() throws Exception
77      {
78          MuleClient client = new MuleClient(muleContext);
79          client.dispatch("asyncEndpoint", TEST_MESSAGE, null);
80          // MULE-2757
81          Thread.sleep(1000);
82          MuleMessage response = client.request("asyncEndpoint", 5000);
83          assertNotNull("Response is null", response);
84          assertEquals(TEST_MESSAGE + " Received Async", response.getPayloadAsString());
85      }
86  
87  }