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