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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
package org.simpleframework.http.core;
import org.simpleframework.http.core.Conversation;
import junit.framework.TestCase;
public class ConversationTest extends TestCase {
private MockRequest request;
private MockResponse response;
private Conversation support;
public void setUp() {
request = new MockRequest();
response = new MockResponse();
support = new Conversation(request, response);
}
public void testWebSocket() {
request.setMajor(1);
request.setMinor(1);
response.setValue("Connection", "upgrade");
assertFalse(support.isWebSocket());
assertFalse(support.isTunnel());
assertTrue(support.isKeepAlive());
request.setValue("Upgrade", "WebSocket");
assertFalse(support.isWebSocket());
assertFalse(support.isTunnel());
assertTrue(support.isKeepAlive());
response.setCode(101);
response.setValue("Upgrade", "websocket");
assertTrue(support.isWebSocket());
assertTrue(support.isTunnel());
assertTrue(support.isKeepAlive());
}
public void testConnectTunnel() {
request.setMajor(1);
request.setMinor(1);
response.setCode(404);
request.setMethod("CONNECT");
assertFalse(support.isWebSocket());
assertFalse(support.isTunnel());
assertTrue(support.isKeepAlive());
response.setCode(200);
assertFalse(support.isWebSocket());
assertTrue(support.isTunnel());
assertTrue(support.isKeepAlive());
}
public void testResponse() {
request.setMajor(1);
request.setMinor(1);
response.setValue("Content-Length", "10");
response.setValue("Connection", "close");
assertFalse(support.isKeepAlive());
assertTrue(support.isPersistent());
assertEquals(support.getContentLength(), 10);
assertEquals(support.isChunkedEncoded(), false);
request.setMinor(0);
assertFalse(support.isKeepAlive());
assertFalse(support.isPersistent());
response.setValue("Connection", "keep-alive");
assertTrue(support.isKeepAlive());
assertFalse(support.isPersistent());
response.setValue("Transfer-Encoding", "chunked");
assertTrue(support.isChunkedEncoded());
assertTrue(support.isKeepAlive());
}
public void testConversation() {
request.setMajor(1);
request.setMinor(1);
support.setChunkedEncoded();
assertEquals(response.getValue("Transfer-Encoding"), "chunked");
assertEquals(response.getValue("Connection"), "keep-alive");
assertTrue(support.isKeepAlive());
assertTrue(support.isPersistent());
request.setMinor(0);
support.setChunkedEncoded();
assertEquals(response.getValue("Connection"), "close");
assertFalse(support.isKeepAlive());
request.setMajor(1);
request.setMinor(1);
response.setValue("Content-Length", "10");
response.setValue("Connection", "close");
assertFalse(support.isKeepAlive());
assertTrue(support.isPersistent());
assertEquals(support.getContentLength(), 10);
request.setMinor(0);
assertFalse(support.isKeepAlive());
assertFalse(support.isPersistent());
response.setValue("Connection", "keep-alive");
assertTrue(support.isKeepAlive());
assertFalse(support.isPersistent());
response.setValue("Transfer-Encoding", "chunked");
assertTrue(support.isChunkedEncoded());
assertTrue(support.isKeepAlive());
}
}
|