1   /*
2    * $Id: SslConnectorTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.providers.ssl;
12  
13  import org.mule.impl.MuleDescriptor;
14  import org.mule.impl.endpoint.MuleEndpointURI;
15  import org.mule.tck.providers.AbstractConnectorTestCase;
16  import org.mule.tck.testmodels.fruit.Orange;
17  import org.mule.umo.UMOComponent;
18  import org.mule.umo.endpoint.UMOEndpoint;
19  import org.mule.umo.lifecycle.InitialisationException;
20  import org.mule.umo.provider.UMOConnector;
21  
22  import java.io.IOException;
23  
24  public class SslConnectorTestCase extends AbstractConnectorTestCase
25  {
26  
27      public UMOConnector getConnector() throws Exception
28      {
29          return createConnector(true);
30      }
31  
32      public static SslConnector createConnector(boolean initialised)
33          throws InitialisationException, IOException
34      {
35          SslConnector cnn = new SslConnector();
36          cnn.setName("SslConnector");
37          cnn.setKeyStore("serverKeystore");
38          cnn.setClientKeyStore("clientKeystore");
39          cnn.setClientKeyStorePassword("mulepassword");
40          cnn.setKeyPassword("mulepassword");
41          cnn.setStorePassword("mulepassword");
42          cnn.setTrustStore("trustStore");
43          cnn.setTrustStorePassword("mulepassword");
44          cnn.getDispatcherThreadingProfile().setDoThreading(false);
45          if (initialised)
46          {
47              cnn.initialise();
48          }
49          return cnn;
50      }
51  
52      public void testClientConnector() throws Exception
53      {
54          SslConnector cnn = new SslConnector();
55          cnn.setClientKeyStore("clientKeystore");
56          cnn.setClientKeyStorePassword("mulepassword");
57          cnn.getDispatcherThreadingProfile().setDoThreading(false);
58          cnn.initialise();
59      }
60  
61      public String getTestEndpointURI()
62      {
63          return "ssl://localhost:56801";
64      }
65  
66      public Object getValidMessage() throws Exception
67      {
68          return "Hello".getBytes();
69      }
70  
71      public void testValidListener() throws Exception
72      {
73          MuleDescriptor d = getTestDescriptor("orange", Orange.class.getName());
74          UMOComponent component = getTestComponent(d);
75          UMOEndpoint endpoint = getTestEndpoint("Test", UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
76          endpoint.setEndpointURI(null);
77          endpoint.setConnector(connector);
78  
79          try
80          {
81              connector.registerListener(component, endpoint);
82              fail("cannot register with null endpointUri");
83          }
84          catch (Exception e)
85          {
86              /* expected */
87          }
88  
89          endpoint.setEndpointURI(null);
90          try
91          {
92              connector.registerListener(component, endpoint);
93              fail("cannot register with empty endpointUri");
94          }
95          catch (Exception e)
96          {
97              /* expected */
98          }
99  
100         endpoint.setEndpointURI(new MuleEndpointURI("ssl://localhost:30303"));
101         connector.registerListener(component, endpoint);
102         try
103         {
104             // connector.registerListener(component, endpoint);
105             // fail("cannot register on the same endpointUri");
106         }
107         catch (Exception e)
108         {
109             /* expected */
110         }
111     }
112 
113     public void testProperties() throws Exception
114     {
115         SslConnector c = (SslConnector)connector;
116 
117         c.setSendBufferSize(1024);
118         assertEquals(1024, c.getSendBufferSize());
119         c.setSendBufferSize(0);
120         assertEquals(SslConnector.DEFAULT_BUFFER_SIZE, c.getSendBufferSize());
121     }
122 
123 }