001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java $
003: * $Revision: 610763 $
004: * $Date: 2008-01-10 13:01:13 +0100 (Thu, 10 Jan 2008) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.params;
033:
034: import junit.framework.Test;
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: /**
039: * Unit tests for {@link BasicHttpParams}.
040: *
041: * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
042: */
043: public class TestBasicHttpParams extends TestCase {
044:
045: public TestBasicHttpParams(String testName) {
046: super (testName);
047: }
048:
049: public static void main(String args[]) {
050: String[] testCaseName = { TestBasicHttpParams.class.getName() };
051: junit.textui.TestRunner.main(testCaseName);
052: }
053:
054: public static Test suite() {
055: return new TestSuite(TestBasicHttpParams.class);
056: }
057:
058: public void testCopyParams() {
059: HttpParams parent = new BasicHttpParams();
060: HttpParams child = new DefaultedHttpParams(
061: new BasicHttpParams(), parent);
062: parent.setParameter("parent", "something");
063: child.setParameter("child", "something");
064:
065: HttpParams copy = child.copy();
066: assertSame("copied parameters have wrong class", child
067: .getClass(), copy.getClass());
068: assertEquals("local parameter missing in copy", "something",
069: copy.getParameter("child"));
070: assertEquals("default parameter missing in copy", "something",
071: copy.getParameter("parent"));
072:
073: // now modify stuff to make sure the copy is a copy
074: child.setParameter("child", "else-child");
075: assertEquals("modification in child reflected in copy",
076: "something", copy.getParameter("child"));
077: child.setParameter("child+", "something");
078: assertNull("new parameter in child reflected in copy", copy
079: .getParameter("child+"));
080:
081: copy.setParameter("child", "else-copy");
082: assertEquals("modification in copy reflected in child",
083: "else-child", child.getParameter("child"));
084: copy.setParameter("copy+", "something");
085: assertNull("new parameter in copy reflected in child", child
086: .getParameter("copy+"));
087:
088: // and modify the parent to make sure there is only one
089: parent.setParameter("parent+", "something");
090: assertEquals("parent parameter not known in child",
091: "something", child.getParameter("parent+"));
092: assertEquals("parent parameter not known in copy", "something",
093: copy.getParameter("parent+"));
094: }
095:
096: public void testRemoveParam() {
097: BasicHttpParams params = new BasicHttpParams();
098: params.setParameter("param1", "paramValue1");
099: assertTrue("The parameter should be removed successfully",
100: params.removeParameter("param1"));
101: assertFalse("The parameter should not be present", params
102: .removeParameter("param1"));
103:
104: //try a remove from an empty params
105: params = new BasicHttpParams();
106: assertFalse("The parameter should not be present", params
107: .removeParameter("param1"));
108: }
109:
110: }
|