001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.messaging;
018:
019: import java.util.Properties;
020:
021: import junit.framework.TestCase;
022:
023: import org.apache.commons.httpclient.HttpClient;
024: import org.apache.commons.httpclient.HttpConnectionManager;
025: import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
026: import org.apache.commons.httpclient.SimpleHttpConnectionManager;
027: import org.apache.commons.httpclient.cookie.CookiePolicy;
028: import org.junit.Test;
029: import org.kuali.rice.config.SimpleConfig;
030: import org.kuali.rice.core.Core;
031:
032: import edu.iu.uis.eden.messaging.serviceconnectors.HttpInvokerConnector;
033:
034: /**
035: * A test which tests the RemoteResourceServiceLocatorImpl class.
036: *
037: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
038: */
039: public class HttpInvokerConnectorConfigurationTest extends TestCase {
040:
041: /**
042: * Tests the configuration and initialization of the HttpClient which is
043: * used for the invocation of remote service calls.
044: */
045: @Test
046: public void testHttpClientConfiguration() throws Exception {
047: // test the default configuration
048: Core.init(new SimpleConfig());
049: HttpInvokerConnector httpConnector = new HttpInvokerConnector(
050: new ServiceInfo());
051: HttpClient httpClient = httpConnector.getHttpClient();
052:
053: HttpConnectionManager connectionManager = httpClient
054: .getHttpConnectionManager();
055: assertTrue(
056: "Should be a multi-threaded connection manager.",
057: connectionManager instanceof MultiThreadedHttpConnectionManager);
058: int defaultMaxConnectionsPerHost = connectionManager
059: .getParams().getDefaultMaxConnectionsPerHost();
060: assertEquals(20, defaultMaxConnectionsPerHost);
061: assertEquals(20, connectionManager.getParams()
062: .getMaxTotalConnections());
063: assertEquals(10000, connectionManager.getParams()
064: .getConnectionTimeout());
065: assertEquals(10000, httpClient.getParams()
066: .getConnectionManagerTimeout());
067: assertEquals(CookiePolicy.RFC_2109, httpClient.getParams()
068: .getCookiePolicy());
069:
070: // re-init the core with some of these paramters changed
071: SimpleConfig config = new SimpleConfig();
072: Properties properties = config.getProperties();
073: properties.put("http.connection-manager.max-total", "500");
074: properties.put("http.connection-manager.timeout", "5000");
075: properties.put("http.connection.timeout", "15000");
076: properties.put("http.somerandomproperty", "thisismyproperty");
077: properties.put("http.authentication.preemptive", "false");
078: Core.init(config);
079:
080: httpConnector = new HttpInvokerConnector(new ServiceInfo());
081: httpClient = httpConnector.getHttpClient();
082:
083: connectionManager = httpClient.getHttpConnectionManager();
084: assertTrue(
085: "Should be a multi-threaded connection manager.",
086: connectionManager instanceof MultiThreadedHttpConnectionManager);
087: defaultMaxConnectionsPerHost = connectionManager.getParams()
088: .getDefaultMaxConnectionsPerHost();
089: assertEquals(20, defaultMaxConnectionsPerHost);
090: assertEquals(500, connectionManager.getParams()
091: .getMaxTotalConnections());
092: assertEquals(15000, connectionManager.getParams()
093: .getConnectionTimeout());
094: assertEquals(5000, httpClient.getParams()
095: .getConnectionManagerTimeout());
096: assertEquals(CookiePolicy.RFC_2109, httpClient.getParams()
097: .getCookiePolicy());
098: assertFalse(httpClient.getParams().isAuthenticationPreemptive());
099:
100: // do another one that checks that booleans are working properly
101: config = new SimpleConfig();
102: properties = config.getProperties();
103: properties.put("http.authentication.preemptive", "true");
104: Core.init(config);
105:
106: httpConnector = new HttpInvokerConnector(new ServiceInfo());
107: httpClient = httpConnector.getHttpClient();
108:
109: assertTrue(httpClient.getParams().isAuthenticationPreemptive());
110:
111: // check setting the classname of the connection manager
112: config = new SimpleConfig();
113: properties = config.getProperties();
114: properties.put("http.connection-manager.class",
115: MyHttpConnectionManager.class.getName());
116: Core.init(config);
117:
118: httpConnector = new HttpInvokerConnector(new ServiceInfo());
119: httpClient = httpConnector.getHttpClient();
120:
121: connectionManager = httpClient.getHttpConnectionManager();
122: assertTrue("Should be a MyHttpConnectionManager.",
123: connectionManager instanceof MyHttpConnectionManager);
124:
125: // now try setting the retry handler which expects an object that we can't pipe through our
126: // String-based configuration. This is an illegal parameter to configure and we should
127: // recieve a WorkflowRuntimeException
128: config = new SimpleConfig();
129: properties = config.getProperties();
130: properties.put("http.method.retry-handler", "badparm");
131: Core.init(config);
132:
133: try {
134: httpConnector = new HttpInvokerConnector(new ServiceInfo());
135: fail("An exception should have been thrown because the retry handler is an illegal parameter.");
136: } catch (Exception e) {
137: //nothing to do here
138: }
139:
140: }
141:
142: public static class MyHttpConnectionManager extends
143: SimpleHttpConnectionManager {
144: // nothing extra needed
145: }
146:
147: }
|