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.tcp.TcpConnector;
16 import org.mule.tck.providers.AbstractConnectorTestCase;
17 import org.mule.tck.testmodels.fruit.Orange;
18 import org.mule.umo.UMOComponent;
19 import org.mule.umo.endpoint.UMOEndpoint;
20 import org.mule.umo.provider.UMOConnector;
21
22 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
23
24 public class HttpConnectorTestCase extends AbstractConnectorTestCase
25 {
26 public UMOConnector getConnector() throws Exception
27 {
28 HttpConnector c = new HttpConnector();
29 c.setName("HttpConnector");
30 c.initialise();
31 return c;
32 }
33
34 public String getTestEndpointURI()
35 {
36 return "http://localhost:60127";
37 }
38
39 public Object getValidMessage() throws Exception
40 {
41 return "Hello".getBytes();
42 }
43
44 public void testValidListener() throws Exception
45 {
46 HttpConnector connector = (HttpConnector)getConnector();
47
48 MuleDescriptor d = getTestDescriptor("orange", Orange.class.getName());
49 UMOComponent component = getTestComponent(d);
50 UMOEndpoint endpoint = getTestEndpoint("Test", UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
51 endpoint.setEndpointURI(null);
52 endpoint.setConnector(connector);
53
54 try
55 {
56 connector.registerListener(component, endpoint);
57 fail("cannot register with null endpointUri");
58 }
59 catch (Exception e)
60 {
61
62 }
63
64 endpoint.setEndpointURI(null);
65 try
66 {
67 connector.registerListener(component, endpoint);
68 fail("cannot register with empty endpointUri");
69 }
70 catch (Exception e)
71 {
72
73 }
74
75 endpoint.setEndpointURI(new MuleEndpointURI("http://localhost:0"));
76 connector.registerListener(component, endpoint);
77 try
78 {
79 connector.registerListener(component, endpoint);
80 fail("cannot register on the same endpointUri");
81 }
82 catch (Exception e)
83 {
84
85 }
86
87 connector.dispose();
88 }
89
90 public void testProperties() throws Exception
91 {
92 HttpConnector c = (HttpConnector)getConnector();
93
94 c.setSendBufferSize(1024);
95 assertEquals(1024, c.getSendBufferSize());
96 c.setSendBufferSize(0);
97 assertEquals(TcpConnector.DEFAULT_BUFFER_SIZE, c.getSendBufferSize());
98
99 int maxThreadsActive = c.getDispatcherThreadingProfile().getMaxThreadsActive();
100 HttpConnectionManagerParams params = c.getClientConnectionManager().getParams();
101 assertEquals(maxThreadsActive, params.getDefaultMaxConnectionsPerHost());
102 assertEquals(maxThreadsActive, params.getMaxTotalConnections());
103
104 c.dispose();
105
106
107 }
108 }