~ubuntu-branches/ubuntu/trusty/httpcomponents-core/trusty

« back to all changes in this revision

Viewing changes to httpcore/src/test/java/org/apache/http/protocol/TestHttpExecutionContext.java

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2010-06-12 08:37:34 UTC
  • Revision ID: james.westby@ubuntu.com-20100612083734-1y8kp6qm4sjk60az
Tags: upstream-4.0.1
ImportĀ upstreamĀ versionĀ 4.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/test/java/org/apache/http/protocol/TestHttpExecutionContext.java $
 
3
 * $Revision: 558111 $
 
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
 
13
 *
 
14
 *   http://www.apache.org/licenses/LICENSE-2.0
 
15
 *
 
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
 
21
 * under the License.
 
22
 * ====================================================================
 
23
 *
 
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/>.
 
28
 *
 
29
 */
 
30
 
 
31
package org.apache.http.protocol;
 
32
 
 
33
import junit.framework.*;
 
34
 
 
35
 
 
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 {
 
39
 
 
40
    // ------------------------------------------------------------ Constructor
 
41
    public TestHttpExecutionContext(String testName) {
 
42
        super(testName);
 
43
    }
 
44
 
 
45
    // ------------------------------------------------------------------- Main
 
46
    public static void main(String args[]) {
 
47
        String[] testCaseName = { TestHttpExecutionContext.class.getName() };
 
48
        junit.textui.TestRunner.main(testCaseName);
 
49
    }
 
50
 
 
51
    // ------------------------------------------------------- TestCase Methods
 
52
 
 
53
    public static Test suite() {
 
54
        return new TestSuite(TestHttpExecutionContext.class);
 
55
    }
 
56
 
 
57
    public void testContextOperations() {
 
58
        HttpContext parentContext = new SyncBasicHttpContext(null); 
 
59
        HttpContext currentContext = new SyncBasicHttpContext(parentContext); 
 
60
 
 
61
        parentContext.setAttribute("param1", "1");
 
62
        parentContext.setAttribute("param2", "2");
 
63
        currentContext.setAttribute("param3", "3");
 
64
        currentContext.setAttribute("param2", "4");
 
65
        
 
66
        assertEquals("1", parentContext.getAttribute("param1"));
 
67
        assertEquals("2", parentContext.getAttribute("param2"));
 
68
        assertEquals(null, parentContext.getAttribute("param3"));
 
69
        
 
70
        assertEquals("1", currentContext.getAttribute("param1"));
 
71
        assertEquals("4", currentContext.getAttribute("param2"));
 
72
        assertEquals("3", currentContext.getAttribute("param3"));
 
73
        assertEquals(null, currentContext.getAttribute("param4"));
 
74
        
 
75
        currentContext.removeAttribute("param1");
 
76
        currentContext.removeAttribute("param2");
 
77
        currentContext.removeAttribute("param3");
 
78
        currentContext.removeAttribute("param4");
 
79
 
 
80
        assertEquals("1", currentContext.getAttribute("param1"));
 
81
        assertEquals("2", currentContext.getAttribute("param2"));
 
82
        assertEquals(null, currentContext.getAttribute("param3"));
 
83
        assertEquals(null, currentContext.getAttribute("param4"));
 
84
    }
 
85
 
 
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"));
 
91
    }
 
92
 
 
93
    public void testContextInvalidInput() throws Exception {
 
94
        HttpContext currentContext = new SyncBasicHttpContext(null); 
 
95
        try {
 
96
            currentContext.setAttribute(null, null);
 
97
            fail("IllegalArgumentException should have been thrown");
 
98
        } catch (IllegalArgumentException ex) {
 
99
            // expected
 
100
        }
 
101
        try {
 
102
            currentContext.getAttribute(null);
 
103
            fail("IllegalArgumentException should have been thrown");
 
104
        } catch (IllegalArgumentException ex) {
 
105
            // expected
 
106
        }
 
107
        try {
 
108
            currentContext.removeAttribute(null);
 
109
            fail("IllegalArgumentException should have been thrown");
 
110
        } catch (IllegalArgumentException ex) {
 
111
            // expected
 
112
        }
 
113
    }
 
114
    
 
115
}