KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > TestHttpState


1 /*
2  * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpState.java,v 1.3.2.1 2004/02/22 18:21:16 olegk Exp $
3  * $Revision: 1.3.2.1 $
4  * $Date: 2004/02/22 18:21:16 $
5  * ====================================================================
6  *
7  * Copyright 1999-2004 The Apache Software Foundation
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ====================================================================
21  *
22  * This software consists of voluntary contributions made by many
23  * individuals on behalf of the Apache Software Foundation. For more
24  * information on the Apache Software Foundation, please see
25  * <http://www.apache.org/>.
26  *
27  * [Additional notices, if required by prior licensing conditions]
28  *
29  */

30
31 package org.apache.commons.httpclient;
32
33 import junit.framework.*;
34
35 /**
36  *
37  * Simple tests for {@link HttpState}.
38  *
39  * @author Rodney Waldhoff
40  * @author <a HREF="mailto:jsdever@apache.org">Jeff Dever</a>
41  * @author Sean C. Sullivan
42  *
43  * @version $Id: TestHttpState.java,v 1.3.2.1 2004/02/22 18:21:16 olegk Exp $
44  *
45  */

46 public class TestHttpState extends TestCase {
47
48     public final Credentials creds1 = new UsernamePasswordCredentials("user1", "pass1");
49     public final Credentials creds2 = new UsernamePasswordCredentials("user2", "pass2");
50
51     public final String JavaDoc realm1 = "realm1";
52     public final String JavaDoc realm2 = "realm2";
53
54
55     // ------------------------------------------------------------ Constructor
56
public TestHttpState(String JavaDoc testName) {
57         super(testName);
58     }
59
60     // ------------------------------------------------------------------- Main
61
public static void main(String JavaDoc args[]) {
62         String JavaDoc[] testCaseName = { TestHttpState.class.getName() };
63         junit.textui.TestRunner.main(testCaseName);
64     }
65
66     // ------------------------------------------------------- TestCase Methods
67

68     public static Test suite() {
69         return new TestSuite(TestHttpState.class);
70     }
71
72
73     // ----------------------------------------------------------- Test Methods
74

75     public void testHttpStateCredentials() {
76         HttpState state = new HttpState();
77     state.setCredentials(realm1, creds1);
78     state.setCredentials(realm2, creds2);
79         assertEquals(creds1, state.getCredentials(realm1));
80         assertEquals(creds2, state.getCredentials(realm2));
81     }
82
83     public void testToString()
84     {
85         HttpState state = new HttpState();
86         assertNotNull(state.toString());
87         
88         state.addCookie(new Cookie("foo", "bar", "yeah"));
89         assertNotNull(state.toString());
90
91         state.addCookie(new Cookie("flub", "duck", "yuck"));
92         assertNotNull(state.toString());
93
94         state.setCredentials(realm1, creds1);
95         assertNotNull(state.toString());
96         
97         state.setProxyCredentials(realm2, creds2);
98         assertNotNull(state.toString());
99     }
100
101     public void testHttpStateNoCredentials() {
102         HttpState state = new HttpState();
103         assertEquals(null, state.getCredentials("bogus"));
104     }
105
106     public void testHttpStateDefaultCredentials() {
107         HttpState state = new HttpState();
108     state.setCredentials(null, creds1);
109     state.setCredentials(realm2, creds2);
110         assertEquals(creds1, state.getCredentials("bogus"));
111     }
112
113
114     public void testHttpStateProxyCredentials() {
115         HttpState state = new HttpState();
116     state.setProxyCredentials(realm1, creds1);
117     state.setProxyCredentials(realm2, creds2);
118         assertEquals(creds1, state.getProxyCredentials(realm1));
119         assertEquals(creds2, state.getProxyCredentials(realm2));
120     }
121
122     public void testHttpStateProxyNoCredentials() {
123         HttpState state = new HttpState();
124         assertEquals(null, state.getProxyCredentials("bogus"));
125     }
126
127     public void testHttpStateProxyDefaultCredentials() {
128         HttpState state = new HttpState();
129     state.setProxyCredentials(null, creds1);
130     state.setProxyCredentials(realm2, creds2);
131         assertEquals(creds1, state.getProxyCredentials("bogus"));
132     }
133
134 }
135
Popular Tags