2
* $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/test/java/org/apache/http/protocol/TestHttpExecutionContext.java $
4
* $Date: 2007-07-20 22:01:50 +0200 (Fri, 20 Jul 2007) $
5
* ====================================================================
6
* Licensed to the Apache Software Foundation (ASF) under one
7
* or more contributor license agreements. See the NOTICE file
8
* distributed with this work for additional information
9
* regarding copyright ownership. The ASF licenses this file
10
* to you under the Apache License, Version 2.0 (the
11
* "License"); you may not use this file except in compliance
12
* with the License. You may obtain a copy of the License at
14
* http://www.apache.org/licenses/LICENSE-2.0
16
* Unless required by applicable law or agreed to in writing,
17
* software distributed under the License is distributed on an
18
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19
* KIND, either express or implied. See the License for the
20
* specific language governing permissions and limitations
22
* ====================================================================
24
* This software consists of voluntary contributions made by many
25
* individuals on behalf of the Apache Software Foundation. For more
26
* information on the Apache Software Foundation, please see
27
* <http://www.apache.org/>.
31
package org.apache.http.protocol;
33
import junit.framework.*;
36
// the name of this test is historic, the implementation classes of HttpContext
37
// have been renamed to BasicHttpContext and SyncBasicHttpContext
38
public class TestHttpExecutionContext extends TestCase {
40
// ------------------------------------------------------------ Constructor
41
public TestHttpExecutionContext(String testName) {
45
// ------------------------------------------------------------------- Main
46
public static void main(String args[]) {
47
String[] testCaseName = { TestHttpExecutionContext.class.getName() };
48
junit.textui.TestRunner.main(testCaseName);
51
// ------------------------------------------------------- TestCase Methods
53
public static Test suite() {
54
return new TestSuite(TestHttpExecutionContext.class);
57
public void testContextOperations() {
58
HttpContext parentContext = new SyncBasicHttpContext(null);
59
HttpContext currentContext = new SyncBasicHttpContext(parentContext);
61
parentContext.setAttribute("param1", "1");
62
parentContext.setAttribute("param2", "2");
63
currentContext.setAttribute("param3", "3");
64
currentContext.setAttribute("param2", "4");
66
assertEquals("1", parentContext.getAttribute("param1"));
67
assertEquals("2", parentContext.getAttribute("param2"));
68
assertEquals(null, parentContext.getAttribute("param3"));
70
assertEquals("1", currentContext.getAttribute("param1"));
71
assertEquals("4", currentContext.getAttribute("param2"));
72
assertEquals("3", currentContext.getAttribute("param3"));
73
assertEquals(null, currentContext.getAttribute("param4"));
75
currentContext.removeAttribute("param1");
76
currentContext.removeAttribute("param2");
77
currentContext.removeAttribute("param3");
78
currentContext.removeAttribute("param4");
80
assertEquals("1", currentContext.getAttribute("param1"));
81
assertEquals("2", currentContext.getAttribute("param2"));
82
assertEquals(null, currentContext.getAttribute("param3"));
83
assertEquals(null, currentContext.getAttribute("param4"));
86
public void testEmptyContextOperations() {
87
HttpContext currentContext = new SyncBasicHttpContext(null);
88
assertEquals(null, currentContext.getAttribute("param1"));
89
currentContext.removeAttribute("param1");
90
assertEquals(null, currentContext.getAttribute("param1"));
93
public void testContextInvalidInput() throws Exception {
94
HttpContext currentContext = new SyncBasicHttpContext(null);
96
currentContext.setAttribute(null, null);
97
fail("IllegalArgumentException should have been thrown");
98
} catch (IllegalArgumentException ex) {
102
currentContext.getAttribute(null);
103
fail("IllegalArgumentException should have been thrown");
104
} catch (IllegalArgumentException ex) {
108
currentContext.removeAttribute(null);
109
fail("IllegalArgumentException should have been thrown");
110
} catch (IllegalArgumentException ex) {