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.module.client.MuleClient;
11  import org.mule.tck.functional.FunctionalTestComponent;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.junit4.rule.DynamicPort;
14  
15  import org.junit.Rule;
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertTrue;
21  
22  public class SslCertificateTestCase extends FunctionalTestCase
23  {
24  
25      private static int NUM_MESSAGES = 100;
26  
27      @Rule
28      public DynamicPort dynamicPort = new DynamicPort("port1");
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "ssl-certificate-test.xml";
34      }
35  
36      @Test
37      public void testOnce() throws Exception
38      {
39          doTests(1);
40      }
41  
42      @Test
43      public void testMany() throws Exception
44      {
45          doTests(NUM_MESSAGES);
46      }
47  
48      protected void doTests(int n) throws Exception
49      {
50          FunctionalTestComponent ftc = (FunctionalTestComponent) getComponent("service");
51          assertNotNull(ftc);
52          assertNotNull(ftc.getEventCallback());
53  
54          SaveCertificateCallback callback = (SaveCertificateCallback) ftc.getEventCallback();
55          callback.clear();
56  
57          MuleClient client = new MuleClient(muleContext);
58          for (int i = 0; i < n; ++i)
59          {
60              callback.clear();
61              String msg = TEST_MESSAGE + n;
62              MuleMessage result = client.send("in", msg, null);
63              assertTrue(callback.isCalled());
64              assertNotNull("Null certificates", callback.getCertificates());
65              assertEquals(msg + " Received", result.getPayloadAsString());
66          }
67      }
68  }