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