1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 realm1 = "realm1";
52 public final String realm2 = "realm2";
53
54
55
56 public TestHttpState(String testName) {
57 super(testName);
58 }
59
60
61 public static void main(String args[]) {
62 String[] testCaseName = { TestHttpState.class.getName() };
63 junit.textui.TestRunner.main(testCaseName);
64 }
65
66
67
68 public static Test suite() {
69 return new TestSuite(TestHttpState.class);
70 }
71
72
73
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 }