View Javadoc

1   /*
2    * $Id: SslCertificatesTestCase.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  import java.security.cert.Certificate;
19  import java.util.Iterator;
20  
21  /**
22   * A different version of {@link org.mule.transport.ssl.SslCertificateTestCase} to see if we can get
23   * different timing.
24   */
25  public class SslCertificatesTestCase extends FunctionalTestCase
26  {
27      private static int NUM_MESSAGES = 100;
28  
29      protected String getConfigResources()
30      {
31          return "ssl-certificates-test.xml";
32      }
33  
34      public void testOnce() throws Exception
35      {
36          doTests(1);
37      }
38  
39      public void testMany() throws Exception
40      {
41          doTests(NUM_MESSAGES);
42      }
43  
44      protected void doTests(int n) throws Exception
45      {
46          FunctionalTestComponent ftc = (FunctionalTestComponent) getComponent("service");
47          assertNotNull(ftc);
48          assertNotNull(ftc.getEventCallback());
49  
50          SaveCertificatesCallback callback = (SaveCertificatesCallback) ftc.getEventCallback();
51          callback.clear();
52  
53          MuleClient client = new MuleClient(muleContext);
54          for (int i = 0; i < n; ++i)
55          {
56              String msg = TEST_MESSAGE + n;
57              MuleMessage result = client.send("in", msg, null);
58              assertEquals(msg  + " Received", result.getPayloadAsString());
59          }
60          Iterator<Certificate[]> certificates = callback.getCertificates().iterator();
61          for (int i = 0; i < n; ++i)
62          {
63              assertTrue("No cert at " + i, certificates.hasNext());
64              assertNotNull("Null cert at " + i, certificates.next());
65          }
66      }
67  }