Index: module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java =================================================================== --- module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java (revision 0) +++ module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java (revision 0) @@ -0,0 +1,97 @@ +/* + * $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 + * . + * + */ + +package org.apache.http.params; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit tests for {@link BasicHttpParams}. + * + * @author Roland Weber + */ +public class TestBasicHttpParams extends TestCase { + + public TestBasicHttpParams(String testName) { + super(testName); + } + + public static void main(String args[]) { + String[] testCaseName = { TestBasicHttpParams.class.getName() }; + junit.textui.TestRunner.main(testCaseName); + } + + public static Test suite() { + return new TestSuite(TestBasicHttpParams.class); + } + + + + public void testCopyParams() { + BasicHttpParams parent = new BasicHttpParams(); + BasicHttpParams child = new BasicHttpParams(parent); + parent.setParameter("parent", "something"); + child.setParameter("child", "something"); + + HttpParams copy = child.copyParams(); + assertSame("copied parameters have wrong class", + child.getClass(), copy.getClass()); + assertEquals("local parameter missing in copy", + "something", copy.getParameter("child")); + assertEquals("default parameter missing in copy", + "something", copy.getParameter("parent")); + + // now modify stuff to make sure the copy is a copy + child.setParameter("child", "else-child"); + assertEquals("modification in child reflected in copy", + "something", copy.getParameter("child")); + child.setParameter("child+", "something"); + assertNull("new parameter in child reflected in copy", + copy.getParameter("child+")); + + copy.setParameter("child", "else-copy"); + assertEquals("modification in copy reflected in child", + "else-child", child.getParameter("child")); + copy.setParameter("copy+", "something"); + assertNull("new parameter in copy reflected in child", + child.getParameter("copy+")); + + // and modify the parent to make sure there is only one + parent.setParameter("parent+", "something"); + assertEquals("parent parameter not known in child", + "something", child.getParameter("parent+")); + assertEquals("parent parameter not known in copy", + "something", copy.getParameter("parent+")); + } + +} Property changes on: module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Date Author Id Revision HeadURL Name: svn:eol-style + native Index: module-main/src/test/java/org/apache/http/params/TestAllParams.java =================================================================== --- module-main/src/test/java/org/apache/http/params/TestAllParams.java (revision 0) +++ module-main/src/test/java/org/apache/http/params/TestAllParams.java (revision 0) @@ -0,0 +1,52 @@ +/* + * $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 + * . + * + */ + +package org.apache.http.params; + +import junit.framework.*; + +public class TestAllParams extends TestCase { + + public TestAllParams(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTest(TestBasicHttpParams.suite()); + return suite; + } + + public static void main(String args[]) { + String[] testCaseName = { TestAllParams.class.getName() }; + junit.textui.TestRunner.main(testCaseName); + } + +} Property changes on: module-main/src/test/java/org/apache/http/params/TestAllParams.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Date Author Id Revision HeadURL Name: svn:eol-style + native Index: module-main/src/test/java/org/apache/http/TestAll.java =================================================================== --- module-main/src/test/java/org/apache/http/TestAll.java (revision 539752) +++ module-main/src/test/java/org/apache/http/TestAll.java (working copy) @@ -35,6 +35,7 @@ import org.apache.http.impl.entity.TestAllEntityImpl; import org.apache.http.impl.io.TestAllIO; import org.apache.http.message.TestAllMessage; +import org.apache.http.params.TestAllParams; import org.apache.http.protocol.TestAllProtocol; import org.apache.http.util.TestAllUtil; @@ -50,6 +51,7 @@ TestSuite suite = new TestSuite(); suite.addTest(TestAllUtil.suite()); + suite.addTest(TestAllParams.suite()); suite.addTest(TestHttpExceptions.suite()); suite.addTest(TestHttpVersion.suite()); Index: module-main/src/main/java/org/apache/http/params/BasicHttpParams.java =================================================================== --- module-main/src/main/java/org/apache/http/params/BasicHttpParams.java (revision 539756) +++ module-main/src/main/java/org/apache/http/params/BasicHttpParams.java (working copy) @@ -32,7 +32,9 @@ package org.apache.http.params; import java.io.Serializable; +import java.util.Map; import java.util.HashMap; +import java.util.Iterator; import org.apache.http.params.HttpParams; @@ -212,4 +214,46 @@ this.parameters = null; } + + /** + * Creates a copy of these parameters. + * The implementation here instantiates {@link BasicHttpParams} + * with the same defaults as this object, then calls + * {@link #copyParams(HttpParams)} to populate the copy. + *
+ * Derived classes which have to change the class that is + * instantiated can override this method here. Derived classes + * which have to change how the copy is populated can override + * {@link #copyParams(HttpParams)}. + * + * @return a new set of params holding a copy of the + * local parameters in this object. + * Defaults parameters available via {@link #getDefaults} + * are not copied. + */ + public HttpParams copyParams() { + BasicHttpParams bhp = new BasicHttpParams(this.defaults); + copyParams(bhp); + return bhp; + } + + /** + * Copies the locally defined parameters to the argument parameters. + * Default parameters accessible via {@link #getDefaults} + * are not copied. + * This method is called from {@link #copyParams()}. + * + * @param target the parameters to which to copy + */ + protected void copyParams(HttpParams target) { + if (this.parameters == null) + return; + + Iterator iter = parameters.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry me = (Map.Entry) iter.next(); + if (me.getKey() instanceof String) + target.setParameter((String)me.getKey(), me.getValue()); + } + } }