1
2
3
4
5
6
7
8
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 public UMOConnector getConnector() throws Exception
29 {
30 return createConnector(true);
31 }
32
33 public static HttpsConnector createConnector(boolean initialised)
34 throws IOException, InitialisationException
35 {
36 HttpsConnector cnn = new HttpsConnector();
37 cnn.setName("HttpsConnector");
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.setDefaultResponseTransformer(new UMOMessageToHttpResponse());
46 cnn.getDispatcherThreadingProfile().setDoThreading(false);
47 if (initialised)
48 {
49 cnn.initialise();
50 }
51 return cnn;
52 }
53
54 public String getTestEndpointURI()
55 {
56 return "https://localhost:60127";
57 }
58
59 public Object getValidMessage() throws Exception
60 {
61 return "Hello".getBytes();
62 }
63
64 public void testValidListener() throws Exception
65 {
66 HttpsConnector connector = (HttpsConnector)getConnector();
67
68 MuleDescriptor d = getTestDescriptor("orange", Orange.class.getName());
69 UMOComponent component = getTestComponent(d);
70 UMOEndpoint endpoint = getTestEndpoint("Test", UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
71 endpoint.setEndpointURI(null);
72 endpoint.setConnector(connector);
73
74 try
75 {
76 connector.registerListener(component, endpoint);
77 fail("cannot register with null endpointUri");
78 }
79 catch (Exception e)
80 {
81
82 }
83
84 endpoint.setEndpointURI(null);
85 try
86 {
87 connector.registerListener(component, endpoint);
88 fail("cannot register with empty endpointUri");
89 }
90 catch (Exception e)
91 {
92
93 }
94
95 endpoint.setEndpointURI(new MuleEndpointURI("https://localhost:0"));
96 connector.registerListener(component, endpoint);
97 try
98 {
99 connector.registerListener(component, endpoint);
100 fail("cannot register on the same endpointUri");
101 }
102 catch (Exception e)
103 {
104
105 }
106
107 connector.dispose();
108 }
109
110 public void testProperties() throws Exception
111 {
112 HttpsConnector c = (HttpsConnector)getConnector();
113
114 c.setSendBufferSize(1024);
115 assertEquals(1024, c.getSendBufferSize());
116 c.setSendBufferSize(0);
117 assertEquals(TcpConnector.DEFAULT_BUFFER_SIZE, c.getSendBufferSize());
118
119 c.dispose();
120
121 }
122 }