org.webbitserver.stub
Class StubConnection

java.lang.Object
  extended by org.webbitserver.stub.StubDataHolder
      extended by org.webbitserver.stub.StubConnection
All Implemented Interfaces:
Executor, DataHolder, EventSourceConnection, HttpConnection, WebSocketConnection

public class StubConnection
extends StubDataHolder
implements EventSourceConnection, WebSocketConnection

Implementation of EventSourceConnection and WebSocketConnection that is easy to construct and makes it easy to inspect results. Useful for testing.


Constructor Summary
StubConnection()
           
StubConnection(HttpRequest httpRequest)
           
 
Method Summary
 StubConnection close()
           
 boolean closed()
           
 StubConnection data(String key, Object value)
          Store data value by key.
 void execute(Runnable command)
           
 Executor handlerExecutor()
           
 HttpRequest httpRequest()
           
 StubConnection httpRequest(HttpRequest httpRequest)
           
 StubConnection ping(byte[] message)
          Sends a ping frame
 StubConnection pong(byte[] message)
          Sends a pong frame
 StubConnection send(byte[] message)
          Sends a binary frame
 StubConnection send(byte[] message, int offset, int length)
          Sends a binary frame
 StubConnection send(EventSourceMessage message)
           
 StubConnection send(String message)
          Sends a text frame
 List<byte[]> sentBinaryMessages()
           
 List<String> sentMessages()
           
 List<byte[]> sentPings()
           
 List<byte[]> sentPongs()
           
 String version()
           
 StubConnection version(String version)
           
 
Methods inherited from class org.webbitserver.stub.StubDataHolder
data, data, dataKeys
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.webbitserver.DataHolder
data, data, dataKeys
 

Constructor Detail

StubConnection

public StubConnection(HttpRequest httpRequest)

StubConnection

public StubConnection()
Method Detail

httpRequest

public HttpRequest httpRequest()
Specified by:
httpRequest in interface HttpConnection

send

public StubConnection send(EventSourceMessage message)
Specified by:
send in interface EventSourceConnection

httpRequest

public StubConnection httpRequest(HttpRequest httpRequest)

send

public StubConnection send(String message)
Description copied from interface: WebSocketConnection
Sends a text frame

Specified by:
send in interface WebSocketConnection
Parameters:
message - frame payload
Returns:
this

send

public StubConnection send(byte[] message)
Description copied from interface: WebSocketConnection
Sends a binary frame

Specified by:
send in interface WebSocketConnection
Parameters:
message - frame payload
Returns:
this

send

public StubConnection send(byte[] message,
                           int offset,
                           int length)
Description copied from interface: WebSocketConnection
Sends a binary frame

Specified by:
send in interface WebSocketConnection
Parameters:
message - frame payload
offset - The offset within the array of the first byte to be written; must be non-negative and no larger than message.length
length - The maximum number of bytes to be written to the given array; must be non-negative and no larger than message.length - offset
Returns:
this

ping

public StubConnection ping(byte[] message)
Description copied from interface: WebSocketConnection
Sends a ping frame

Specified by:
ping in interface WebSocketConnection
Parameters:
message - the payload of the ping
Returns:
this

pong

public StubConnection pong(byte[] message)
Description copied from interface: WebSocketConnection
Sends a pong frame

Specified by:
pong in interface WebSocketConnection
Parameters:
message - the payload of the ping
Returns:
this

close

public StubConnection close()
Specified by:
close in interface EventSourceConnection
Specified by:
close in interface HttpConnection
Specified by:
close in interface WebSocketConnection

closed

public boolean closed()

sentMessages

public List<String> sentMessages()

sentBinaryMessages

public List<byte[]> sentBinaryMessages()

sentPings

public List<byte[]> sentPings()

sentPongs

public List<byte[]> sentPongs()

data

public StubConnection data(String key,
                           Object value)
Description copied from interface: DataHolder
Store data value by key.

Specified by:
data in interface DataHolder
Specified by:
data in interface EventSourceConnection
Specified by:
data in interface WebSocketConnection
Overrides:
data in class StubDataHolder
See Also:
DataHolder.data()

handlerExecutor

public Executor handlerExecutor()
Specified by:
handlerExecutor in interface HttpConnection

version

public String version()
Specified by:
version in interface WebSocketConnection
Returns:
the WebSocket protocol version

version

public StubConnection version(String version)

execute

public void execute(Runnable command)
Specified by:
execute in interface Executor


Copyright © 2013. All Rights Reserved.