View Javadoc

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