You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/05/20 09:40:39 UTC
svn commit: r539840 - in
/jakarta/httpcomponents/httpcore/trunk/module-main/src:
main/java/org/apache/http/params/ test/java/org/apache/http/
test/java/org/apache/http/params/
Author: rolandw
Date: Sun May 20 00:40:37 2007
New Revision: 539840
URL: http://svn.apache.org/viewvc?view=rev&rev=539840
Log:
HTTPCORE-71, patch with renamed public method copy()
Added:
jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/
jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestAllParams.java (with props)
jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java (with props)
Modified:
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/TestAll.java
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java?view=diff&rev=539840&r1=539839&r2=539840
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java Sun May 20 00:40:37 2007
@@ -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 default parameters as this object, then calls
+ * {@link #copyParams(HttpParams)} to populate the copy.
+ * <br/>
+ * 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
+ * <i>local</i> parameters in this object.
+ * Defaults parameters available via {@link #getDefaults}
+ * are <i>not</i> copied.
+ */
+ public HttpParams copy() {
+ 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 <i>not</i> 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());
+ }
+ }
}
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/TestAll.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/TestAll.java?view=diff&rev=539840&r1=539839&r2=539840
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/TestAll.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/TestAll.java Sun May 20 00:40:37 2007
@@ -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());
Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestAllParams.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestAllParams.java?view=auto&rev=539840
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestAllParams.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestAllParams.java Sun May 20 00:40:37 2007
@@ -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
+ * <http://www.apache.org/>.
+ *
+ */
+
+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);
+ }
+
+}
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestAllParams.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestAllParams.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestAllParams.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java?view=auto&rev=539840
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java Sun May 20 00:40:37 2007
@@ -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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.params;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link BasicHttpParams}.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ */
+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.copy();
+ 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+"));
+ }
+
+}
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java
------------------------------------------------------------------------------
svn:mime-type = text/plain