1   /*
2    * $Id: SslFunctionalTestCase.java 12017 2008-06-12 09:04:04Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.FunctionalTestCase;
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 FunctionalTestCase 
23  {
24  
25      protected static String TEST_MESSAGE = "Test Request";
26      private static int NUM_MESSAGES = 100;
27  
28      protected String getConfigResources()
29      {
30          return "ssl-functional-test.xml";
31      }
32  
33      public void testSend() throws Exception
34      {
35          MuleClient client = new MuleClient();
36          MuleMessage result = client.send("sendEndpoint", TEST_MESSAGE, null);
37          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
38      }
39  
40      public void testSendMany() throws Exception
41      {
42          MuleClient client = new MuleClient();
43          for (int i = 0; i < NUM_MESSAGES; ++i)
44          {
45              MuleMessage result = client.send("sendManyEndpoint", TEST_MESSAGE, null);
46              assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
47          }
48  
49          Service c = muleContext.getRegistry().lookupService("testComponent2");
50          assertTrue("Service should be a TestSedaService", c instanceof TestSedaService);
51          Object ftc = getComponent(c);
52          assertNotNull("Functional Test Service not found in the model.", ftc);
53          assertTrue("Service should be a FunctionalTestComponent", ftc instanceof FunctionalTestComponent);
54  
55          EventCallback cc = ((FunctionalTestComponent) ftc).getEventCallback();
56          assertNotNull("EventCallback is null", cc);
57          assertTrue("EventCallback should be a CounterCallback", cc instanceof CounterCallback);
58          assertEquals(NUM_MESSAGES, ((CounterCallback) cc).getCallbackCount());
59      }
60  
61      public void testAsynchronous() throws Exception
62      {
63          MuleClient client = new MuleClient();
64          client.dispatch("asyncEndpoint", TEST_MESSAGE, null);
65          // MULE-2754
66          Thread.sleep(100);
67          MuleMessage response = client.request("asyncEndpoint", 5000);
68          assertNotNull("Response is null", response);
69          assertEquals(TEST_MESSAGE + " Received Async", response.getPayloadAsString());
70      }
71  
72  }