View Javadoc

1   /*
2    * $Id: HttpsConnectorTestCase.java 22377 2011-07-11 12:41:42Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.http;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.endpoint.InboundEndpoint;
15  import org.mule.api.lifecycle.InitialisationException;
16  import org.mule.api.service.Service;
17  import org.mule.api.transport.Connector;
18  import org.mule.tck.testmodels.fruit.Orange;
19  import org.mule.transport.AbstractConnectorTestCase;
20  import org.mule.transport.tcp.TcpConnector;
21  
22  import java.io.IOException;
23  
24  import org.junit.Test;
25  
26  import static org.junit.Assert.assertEquals;
27  
28  
29  public class HttpsConnectorTestCase extends AbstractConnectorTestCase
30  {
31  
32      @Override
33      public Connector createConnector() throws Exception
34      {
35          return createConnector(muleContext, false);
36      }
37  
38      public static HttpsConnector createConnector(MuleContext context, boolean initialised)
39          throws IOException, InitialisationException
40      {
41          HttpsConnector cnn = new HttpsConnector(muleContext);
42          cnn.setName("HttpsConnector");
43          cnn.setKeyStore("serverKeystore");
44          cnn.setClientKeyStore("clientKeystore");
45          cnn.setClientKeyStorePassword("mulepassword");
46          cnn.setKeyPassword("mulepassword");
47          cnn.setKeyStorePassword("mulepassword");
48          cnn.setTrustStore("trustStore");
49          cnn.setTrustStorePassword("mulepassword");
50          cnn.getDispatcherThreadingProfile().setDoThreading(false);
51  
52          if (initialised)
53          {
54              cnn.initialise();
55          }
56          return cnn;
57      }
58  
59      public String getTestEndpointURI()
60      {
61          return "https://localhost:60127";
62      }
63  
64      public Object getValidMessage() throws Exception
65      {
66          return "Hello".getBytes();
67      }
68  
69      @Test
70      public void testValidListener() throws Exception
71      {
72          Service service = getTestService("orange", Orange.class);
73          InboundEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint(
74              getTestEndpointURI());
75  
76          getConnector().registerListener(endpoint, getSensingNullMessageProcessor(), service);
77      }
78  
79      @Test
80      public void testProperties() throws Exception
81      {
82          HttpsConnector c = (HttpsConnector)getConnector();
83  
84          c.setSendBufferSize(1024);
85          assertEquals(1024, c.getSendBufferSize());
86          c.setSendBufferSize(0);
87          assertEquals(TcpConnector.DEFAULT_BUFFER_SIZE, c.getSendBufferSize());
88  
89          // all kinds of timeouts are tested in TcpConnectorTestCase now
90      }
91  }