Adding more test cases for WebSocketEventDriver

This commit is contained in:
Joakim Erdfelt 2012-06-28 14:41:57 -07:00
parent 70b9f7245e
commit 256dec3e91
4 changed files with 82 additions and 4 deletions

View File

@ -127,7 +127,7 @@ public class WebSocketEventDriver implements Parser.Listener
return; return;
} }
if (!frameType.getSuperclass().isAssignableFrom(BaseFrame.class)) if (!BaseFrame.class.isAssignableFrom(frameType.getSuperclass()))
{ {
// not assignable // not assignable
return; return;

View File

@ -2,11 +2,13 @@ package org.eclipse.jetty.websocket.api;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.api.samples.AdapterConnectCloseSocket; import org.eclipse.jetty.websocket.api.samples.AdapterConnectCloseSocket;
import org.eclipse.jetty.websocket.api.samples.AnnotatedBasicSocket;
import org.eclipse.jetty.websocket.api.samples.AnnotatedByteArraySocket; import org.eclipse.jetty.websocket.api.samples.AnnotatedByteArraySocket;
import org.eclipse.jetty.websocket.api.samples.AnnotatedByteBufferSocket;
import org.eclipse.jetty.websocket.api.samples.AnnotatedFramesSocket;
import org.eclipse.jetty.websocket.api.samples.ListenerBasicSocket; import org.eclipse.jetty.websocket.api.samples.ListenerBasicSocket;
import org.eclipse.jetty.websocket.frames.BinaryFrame; import org.eclipse.jetty.websocket.frames.BinaryFrame;
import org.eclipse.jetty.websocket.frames.CloseFrame; import org.eclipse.jetty.websocket.frames.CloseFrame;
import org.eclipse.jetty.websocket.frames.PingFrame;
import org.eclipse.jetty.websocket.frames.TextFrame; import org.eclipse.jetty.websocket.frames.TextFrame;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -62,7 +64,7 @@ public class WebSocketEventDriverTest
@Test @Test
public void testAnnotated_ByteBuffer() public void testAnnotated_ByteBuffer()
{ {
AnnotatedBasicSocket socket = new AnnotatedBasicSocket(); AnnotatedByteBufferSocket socket = new AnnotatedByteBufferSocket();
WebSocketEventDriver driver = newDriver(socket); WebSocketEventDriver driver = newDriver(socket);
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname); LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
@ -77,6 +79,28 @@ public class WebSocketEventDriverTest
socket.capture.assertEventStartsWith(2,"onClose(1000,"); socket.capture.assertEventStartsWith(2,"onClose(1000,");
} }
@Test
public void testAnnotated_Frames()
{
AnnotatedFramesSocket socket = new AnnotatedFramesSocket();
WebSocketEventDriver driver = newDriver(socket);
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
driver.setConnection(conn);
driver.onConnect();
driver.onFrame(new PingFrame(StringUtil.getUtf8Bytes("PING")));
driver.onFrame(new TextFrame("Text Me"));
driver.onFrame(new BinaryFrame(StringUtil.getUtf8Bytes("Hello Bin")));
driver.onFrame(new CloseFrame(StatusCode.SHUTDOWN));
socket.capture.assertEventCount(5);
socket.capture.assertEventStartsWith(0,"onConnect(");
socket.capture.assertEventStartsWith(1,"onPingFrame(");
socket.capture.assertEventStartsWith(2,"onTextFrame(");
socket.capture.assertEventStartsWith(3,"onBaseFrame(BinaryFrame");
socket.capture.assertEventStartsWith(4,"onClose(1001,");
}
@Test @Test
public void testListener_Text() public void testListener_Text()
{ {

View File

@ -10,7 +10,7 @@ import org.eclipse.jetty.websocket.api.EventCapture;
import org.eclipse.jetty.websocket.api.WebSocketConnection; import org.eclipse.jetty.websocket.api.WebSocketConnection;
@WebSocket @WebSocket
public class AnnotatedBasicSocket public class AnnotatedByteBufferSocket
{ {
public EventCapture capture = new EventCapture(); public EventCapture capture = new EventCapture();

View File

@ -0,0 +1,54 @@
package org.eclipse.jetty.websocket.api.samples;
import org.eclipse.jetty.websocket.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.annotations.OnWebSocketFrame;
import org.eclipse.jetty.websocket.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.EventCapture;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.ControlFrame;
import org.eclipse.jetty.websocket.frames.PingFrame;
import org.eclipse.jetty.websocket.frames.TextFrame;
@WebSocket
public class AnnotatedFramesSocket
{
public EventCapture capture = new EventCapture();
@OnWebSocketFrame
public void onBaseFrame(BaseFrame frame)
{
capture.add("onBaseFrame(%s)",frame);
}
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
capture.add("onClose(%d, %s)",statusCode,capture.q(reason));
}
@OnWebSocketConnect
public void onConnect(WebSocketConnection conn)
{
capture.add("onConnect(%s)",conn);
}
@OnWebSocketFrame
public void onControlFrame(ControlFrame ping)
{
capture.add("onControlFrame(%s)",ping);
}
@OnWebSocketFrame
public void onPing(PingFrame ping)
{
capture.add("onPingFrame(%s)",ping);
}
@OnWebSocketFrame
public void onTextFrame(TextFrame text)
{
capture.add("onTextFrame(%s)",text);
}
}