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