trivial tests on exceptions and params to make coverage look better
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@555241 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3f02535b7a
commit
1e5ff31bbd
|
@ -47,6 +47,8 @@ public class TestAllConn extends TestCase {
|
|||
suite.addTest(TestRouteDirector.suite());
|
||||
suite.addTest(TestRouteTracker.suite());
|
||||
suite.addTest(TestScheme.suite());
|
||||
suite.addTest(TestParams.suite());
|
||||
suite.addTest(TestExceptions.suite());
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* $HeadURL$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.conn;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for exceptions.
|
||||
* Trivial, but it looks better in the Clover reports.
|
||||
*/
|
||||
public class TestExceptions extends TestCase {
|
||||
|
||||
public TestExceptions(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
String[] testCaseName = { TestExceptions.class.getName() };
|
||||
junit.textui.TestRunner.main(testCaseName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestExceptions.class);
|
||||
}
|
||||
|
||||
public void testCTX() {
|
||||
String msg = "sample exception message";
|
||||
ConnectTimeoutException ctx =
|
||||
new ConnectTimeoutException(msg);
|
||||
assertFalse(ctx.toString().indexOf(msg) < 0);
|
||||
assertSame(msg, ctx.getMessage());
|
||||
|
||||
ctx = new ConnectTimeoutException();
|
||||
assertNull(ctx.getMessage());
|
||||
}
|
||||
|
||||
public void testCPTX() {
|
||||
String msg = "sample exception message";
|
||||
ConnectionPoolTimeoutException cptx =
|
||||
new ConnectionPoolTimeoutException(msg);
|
||||
assertFalse(cptx.toString().indexOf(msg) < 0);
|
||||
assertSame(msg, cptx.getMessage());
|
||||
|
||||
cptx = new ConnectionPoolTimeoutException();
|
||||
assertNull(cptx.getMessage());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* $HeadURL$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.conn;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.conn.params.HttpConnectionManagerParams;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for parameters.
|
||||
* Trivial, but it looks better in the Clover reports.
|
||||
*/
|
||||
public class TestParams extends TestCase {
|
||||
|
||||
public final static
|
||||
HttpHost TARGET1 = new HttpHost("target1.test.invalid");
|
||||
public final static
|
||||
HostConfiguration HOSTCFG1 = new HostConfiguration(TARGET1,null,null);
|
||||
|
||||
|
||||
public TestParams(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
String[] testCaseName = { TestParams.class.getName() };
|
||||
junit.textui.TestRunner.main(testCaseName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestParams.class);
|
||||
}
|
||||
|
||||
|
||||
public void testBadArgs() {
|
||||
HttpParams params = new BasicHttpParams();
|
||||
|
||||
/* not checked
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
setMaxConnectionsPerHost(params, null, 3);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
setMaxConnectionsPerHost(null, HOSTCFG1, 3);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
setMaxConnectionsPerHost(params, HOSTCFG1, 0);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
}
|
||||
|
||||
/* not checked
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
getMaxConnectionsPerHost(params, null);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
getMaxConnectionsPerHost(null, HOSTCFG1);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
setMaxTotalConnections(null, 50);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
}
|
||||
|
||||
/* not checked
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
setMaxTotalConnections(null, 0);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
getMaxTotalConnections(null);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testDefMaxConn() {
|
||||
|
||||
HttpParams params = new BasicHttpParams();
|
||||
|
||||
int fdmcph = HttpConnectionManagerParams.
|
||||
getDefaultMaxConnectionsPerHost(params);
|
||||
|
||||
int fmcph = HttpConnectionManagerParams.
|
||||
getMaxConnectionsPerHost(params, HOSTCFG1);
|
||||
|
||||
assertEquals(fdmcph, fmcph);
|
||||
|
||||
int dmcph = fdmcph + 3;
|
||||
HttpConnectionManagerParams.
|
||||
setDefaultMaxConnectionsPerHost(params, dmcph);
|
||||
int ndmcph = HttpConnectionManagerParams.
|
||||
getDefaultMaxConnectionsPerHost(params);
|
||||
assertEquals(dmcph, ndmcph);
|
||||
|
||||
|
||||
int mcph = HttpConnectionManagerParams.
|
||||
getMaxConnectionsPerHost(params, HOSTCFG1);
|
||||
assertEquals(ndmcph, mcph);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue