View Javadoc

1   /*
2    * $Id: SslFunctionalTestCase.java 20756 2010-12-15 19:20:32Z dzapata $
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.transport.ssl;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.service.Service;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.DynamicPortTestCase;
17  import org.mule.tck.functional.CounterCallback;
18  import org.mule.tck.functional.EventCallback;
19  import org.mule.tck.functional.FunctionalTestComponent;
20  import org.mule.tck.testmodels.mule.TestSedaService;
21  
22  public class SslFunctionalTestCase extends DynamicPortTestCase 
23  {
24      private static int NUM_MESSAGES = 100;
25  
26      protected String getConfigResources()
27      {
28          return "ssl-functional-test.xml";
29      }
30  
31      public void testSend() throws Exception
32      {
33          MuleClient client = new MuleClient(muleContext);
34          MuleMessage result = client.send("sendEndpoint", TEST_MESSAGE, null);
35          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
36      }
37  
38      public void testSendMany() throws Exception
39      {
40          MuleClient client = new MuleClient(muleContext);
41          for (int i = 0; i < NUM_MESSAGES; ++i)
42          {
43              MuleMessage result = client.send("sendManyEndpoint", TEST_MESSAGE, null);
44              assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
45          }
46  
47          Service c = muleContext.getRegistry().lookupService("testComponent2");
48          assertTrue("Service should be a TestSedaService", c instanceof TestSedaService);
49          Object ftc = getComponent(c);
50          assertNotNull("Functional Test Service not found in the model.", ftc);
51          assertTrue("Service should be a FunctionalTestComponent", ftc instanceof FunctionalTestComponent);
52  
53          EventCallback cc = ((FunctionalTestComponent) ftc).getEventCallback();
54          assertNotNull("EventCallback is null", cc);
55          assertTrue("EventCallback should be a CounterCallback", cc instanceof CounterCallback);
56          assertEquals(NUM_MESSAGES, ((CounterCallback) cc).getCallbackCount());
57      }
58  
59      public void testAsynchronous() throws Exception
60      {
61          MuleClient client = new MuleClient(muleContext);
62          client.dispatch("asyncEndpoint", TEST_MESSAGE, null);
63          // MULE-2757
64          Thread.sleep(100);
65          MuleMessage response = client.request("asyncEndpoint", 5000);
66          assertNotNull("Response is null", response);
67          assertEquals(TEST_MESSAGE + " Received Async", response.getPayloadAsString());
68      }
69  
70      @Override
71      protected int getNumPortsToFind()
72      {
73          return 3;
74      }
75  }