1   /*
2    * $Id: HttpConnectorTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.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              /* expected */
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              /* expected */
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              /* expected */
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         // all kinds of timeouts are now being tested in TcpConnectorTestCase
107     }
108 }