1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.grinder.plugin.http;
23
24 import java.net.InetAddress;
25
26 import HTTPClient.NVPair;
27 import junit.framework.TestCase;
28
29
30
31
32
33
34
35 public class TestHTTPPluginConnectionDefaults extends TestCase {
36
37 public void testHTTPPluginConnectionDefaults() throws Exception {
38 final HTTPPluginConnectionDefaults defaults =
39 new HTTPPluginConnectionDefaults();
40
41 assertFalse(defaults.getFollowRedirects());
42 defaults.setFollowRedirects(true);
43 assertTrue(defaults.getFollowRedirects());
44
45 assertTrue(defaults.getUseCookies());
46 defaults.setUseCookies(false);
47 assertFalse(defaults.getUseCookies());
48
49 assertFalse(defaults.getUseContentEncoding());
50 defaults.setUseContentEncoding(true);
51 assertTrue(defaults.getUseContentEncoding());
52
53 assertFalse(defaults.getUseTransferEncoding());
54 defaults.setUseTransferEncoding(true);
55 assertTrue(defaults.getUseTransferEncoding());
56
57 assertFalse(defaults.getUseAuthorizationModule());
58 defaults.setUseAuthorizationModule(true);
59 assertTrue(defaults.getUseAuthorizationModule());
60
61 assertFalse(defaults.getVerifyServerDistinguishedName());
62 defaults.setVerifyServerDistinguishedName(true);
63 assertTrue(defaults.getVerifyServerDistinguishedName());
64
65 assertEquals(0, defaults.getDefaultHeaders().length);
66 final NVPair[] nicePair = { new NVPair("a", "b"), new NVPair("c", "d"), };
67 defaults.setDefaultHeaders(nicePair);
68 assertSame(nicePair, defaults.getDefaultHeaders());
69
70 assertEquals(0, defaults.getTimeout());
71 defaults.setTimeout(123);
72 assertEquals(123, defaults.getTimeout());
73
74 assertNull(defaults.getProxyHost());
75 assertEquals(0, defaults.getProxyPort());
76 defaults.setProxyServer("foo", 7289);
77 assertEquals("foo", defaults.getProxyHost());
78 assertEquals(7289, defaults.getProxyPort());
79
80 assertEquals(null, defaults.getLocalAddress());
81
82 try {
83 defaults.setLocalAddress("unknown host");
84 fail("Expected URLException");
85 }
86 catch (URLException e) {
87 }
88
89 assertEquals(null, defaults.getLocalAddress());
90 defaults.setLocalAddress(InetAddress.getLocalHost().getHostAddress());
91 assertEquals(InetAddress.getLocalHost(), defaults.getLocalAddress());
92
93 assertEquals(0, defaults.getBandwidthLimit());
94 defaults.setBandwidthLimit(99);
95 assertEquals(99, defaults.getBandwidthLimit());
96
97
98 defaults.close();
99 }
100
101 public void testSingleton() {
102 assertNotNull(HTTPPluginConnectionDefaults.getConnectionDefaults());
103 assertSame(HTTPPluginConnectionDefaults.getConnectionDefaults(),
104 HTTPPluginConnectionDefaults.getConnectionDefaults());
105 }
106 }