summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/test/java/org/simpleframework/http/core/ConversationTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'simple/simple-http/src/test/java/org/simpleframework/http/core/ConversationTest.java')
-rw-r--r--simple/simple-http/src/test/java/org/simpleframework/http/core/ConversationTest.java126
1 files changed, 126 insertions, 0 deletions
diff --git a/simple/simple-http/src/test/java/org/simpleframework/http/core/ConversationTest.java b/simple/simple-http/src/test/java/org/simpleframework/http/core/ConversationTest.java
new file mode 100644
index 0000000..00855c2
--- /dev/null
+++ b/simple/simple-http/src/test/java/org/simpleframework/http/core/ConversationTest.java
@@ -0,0 +1,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());
+ }
+}