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