View Javadoc

1   /*
2    * $Id: SslCertificateTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.tck.functional.FunctionalTestComponent;
17  
18  public class SslCertificateTestCase extends FunctionalTestCase
19  {
20      private static int NUM_MESSAGES = 100;
21  
22      protected String getConfigResources()
23      {
24          return "ssl-certificate-test.xml";
25      }
26  
27      public void testOnce() throws Exception
28      {
29          doTests(1);
30      }
31  
32      public void testMany() throws Exception
33      {
34          doTests(NUM_MESSAGES);
35      }
36  
37      protected void doTests(int n) throws Exception
38      {
39          FunctionalTestComponent ftc = (FunctionalTestComponent) getComponent("service");
40          assertNotNull(ftc);
41          assertNotNull(ftc.getEventCallback());
42  
43          SaveCertificateCallback callback = (SaveCertificateCallback) ftc.getEventCallback();
44          callback.clear();
45  
46          MuleClient client = new MuleClient(muleContext);
47          for (int i = 0; i < n; ++i)
48          {
49              callback.clear();
50              String msg = TEST_MESSAGE + n;
51              MuleMessage result = client.send("in", msg, null);
52              assertTrue(callback.isCalled());
53              assertNotNull("Null certificates", callback.getCertificates());
54              assertEquals(msg + " Received", result.getPayloadAsString());
55          }
56      }
57  }