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.endpoint.InboundEndpoint;
10  import org.mule.api.service.Service;
11  import org.mule.api.transport.Connector;
12  import org.mule.tck.testmodels.fruit.Orange;
13  import org.mule.transport.AbstractConnectorTestCase;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.fail;
19  
20  public class SslConnectorTestCase extends AbstractConnectorTestCase
21  {
22      @Override
23      public Connector createConnector() throws Exception
24      {
25          SslConnector cnn = new SslConnector(muleContext);
26          cnn.setName("SslConnector");
27          cnn.setKeyStore("serverKeystore");
28          cnn.setClientKeyStore("clientKeystore");
29          cnn.setClientKeyStorePassword("mulepassword");
30          cnn.setKeyPassword("mulepassword");
31          cnn.setKeyStorePassword("mulepassword");
32          cnn.setTrustStore("trustStore");
33          cnn.setTrustStorePassword("mulepassword");
34          cnn.getDispatcherThreadingProfile().setDoThreading(false);
35          return cnn;
36      }
37  
38      @Test
39      public void testClientConnector() throws Exception
40      {
41          SslConnector cnn = new SslConnector(muleContext);
42          cnn.setClientKeyStore("clientKeystore");
43          cnn.setClientKeyStorePassword("mulepassword");
44          cnn.getDispatcherThreadingProfile().setDoThreading(false);
45      }
46  
47      @Override
48      public String getTestEndpointURI()
49      {
50          return "ssl://localhost:56801";
51      }
52  
53      @Override
54      public Object getValidMessage() throws Exception
55      {
56          return "Hello".getBytes();
57      }
58  
59      @Test
60      public void testValidListener() throws Exception
61      {
62          Service service = getTestService("orange", Orange.class);
63          Connector connector = getConnector();
64  
65          InboundEndpoint endpoint2 =
66              muleContext.getEndpointFactory().getInboundEndpoint("ssl://localhost:30303");
67  
68          connector.registerListener(endpoint2, getSensingNullMessageProcessor(), service);
69          try
70          {
71              connector.registerListener(endpoint2, getSensingNullMessageProcessor(), service);
72              fail("cannot register on the same endpointUri");
73          }
74          catch (Exception e)
75          {
76              // expected
77          }
78      }
79  
80      @Test
81      public void testProperties() throws Exception
82      {
83          SslConnector c = (SslConnector)getConnector();
84  
85          c.setSendBufferSize(1024);
86          assertEquals(1024, c.getSendBufferSize());
87          c.setSendBufferSize(0);
88          assertEquals(SslConnector.DEFAULT_BUFFER_SIZE, c.getSendBufferSize());
89      }
90  
91  }