Adding more test cases for WebSocketEventDriver
This commit is contained in:
parent
70b9f7245e
commit
256dec3e91
|
@ -127,7 +127,7 @@ public class WebSocketEventDriver implements Parser.Listener
|
|||
return;
|
||||
}
|
||||
|
||||
if (!frameType.getSuperclass().isAssignableFrom(BaseFrame.class))
|
||||
if (!BaseFrame.class.isAssignableFrom(frameType.getSuperclass()))
|
||||
{
|
||||
// not assignable
|
||||
return;
|
||||
|
|
|
@ -2,11 +2,13 @@ package org.eclipse.jetty.websocket.api;
|
|||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
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.AnnotatedByteBufferSocket;
|
||||
import org.eclipse.jetty.websocket.api.samples.AnnotatedFramesSocket;
|
||||
import org.eclipse.jetty.websocket.api.samples.ListenerBasicSocket;
|
||||
import org.eclipse.jetty.websocket.frames.BinaryFrame;
|
||||
import org.eclipse.jetty.websocket.frames.CloseFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.frames.TextFrame;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -62,7 +64,7 @@ public class WebSocketEventDriverTest
|
|||
@Test
|
||||
public void testAnnotated_ByteBuffer()
|
||||
{
|
||||
AnnotatedBasicSocket socket = new AnnotatedBasicSocket();
|
||||
AnnotatedByteBufferSocket socket = new AnnotatedByteBufferSocket();
|
||||
WebSocketEventDriver driver = newDriver(socket);
|
||||
|
||||
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
|
||||
|
@ -77,6 +79,28 @@ public class WebSocketEventDriverTest
|
|||
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
|
||||
public void testListener_Text()
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.eclipse.jetty.websocket.api.EventCapture;
|
|||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
|
||||
@WebSocket
|
||||
public class AnnotatedBasicSocket
|
||||
public class AnnotatedByteBufferSocket
|
||||
{
|
||||
public EventCapture capture = new EventCapture();
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue