use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup in project ezyfox-server by youngmonkeys.
the class EzySocketDataReceiverTest method doWsReceiveButException.
@Test
public void doWsReceiveButException() throws Exception {
// given
EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
EzySocketDataReceiver sut = EzySocketDataReceiver.builder().handlerGroupManager(handlerGroupManager).build();
Session session = mock(Session.class);
String message = RandomUtil.randomShortAlphabetString();
EzyWsHandlerGroup handlerGroup = mock(EzyWsHandlerGroup.class);
doThrow(new RuntimeException()).when(handlerGroup).fireBytesReceived(message);
when(handlerGroupManager.getHandlerGroup(session)).thenReturn(handlerGroup);
// when
MethodInvoker.create().object(sut).method("doWsReceive").param(Session.class, session).param(String.class, message).call();
// then
verify(handlerGroupManager, times(1)).getHandlerGroup(session);
verify(handlerGroup, times(1)).fireBytesReceived(message);
}
use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup in project ezyfox-server by youngmonkeys.
the class EzySocketDataReceiverTest method doWsReceive2ButException.
@Test
public void doWsReceive2ButException() throws Exception {
// given
EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
EzySocketDataReceiver sut = EzySocketDataReceiver.builder().handlerGroupManager(handlerGroupManager).build();
Session session = mock(Session.class);
byte[] payload = new byte[] { 1, 2, 3 };
EzyWsHandlerGroup handlerGroup = mock(EzyWsHandlerGroup.class);
doThrow(new RuntimeException()).when(handlerGroup).fireBytesReceived(payload, 0, payload.length);
when(handlerGroupManager.getHandlerGroup(session)).thenReturn(handlerGroup);
// when
MethodInvoker.create().object(sut).method("doWsReceive").param(Session.class, session).param(byte[].class, payload).param(int.class, 0).param(int.class, payload.length).call();
// then
verify(handlerGroupManager, times(1)).getHandlerGroup(session);
verify(handlerGroup, times(1)).fireBytesReceived(payload, 0, payload.length);
}
use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup in project ezyfox-server by youngmonkeys.
the class EzySimpleWsHandlerGroupTest method handleReceivedSessionStreamEnable.
@Test
public void handleReceivedSessionStreamEnable() throws Exception {
// given
EzyWsHandlerGroup sut = newHandlerGroup();
EzySession session = FieldUtil.getFieldValue(sut, "session");
when(session.isStreamingEnable()).thenReturn(true);
byte[] bytes = new byte[] { 1 << 4, 2, 3 };
int offset = 0;
int len = 3;
// when
MethodInvoker.create().object(sut).method("handleReceivedBytes").param(byte[].class, bytes).param(int.class, offset).param(int.class, len).call();
// then
verify(session, times(1)).isStreamingEnable();
}
use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup in project ezyfox-server by youngmonkeys.
the class EzySimpleWsHandlerGroupTest method handleReceivedBytesLenLowerThan1.
@Test
public void handleReceivedBytesLenLowerThan1() throws Exception {
// given
EzyWsHandlerGroup sut = newHandlerGroup();
byte[] bytes = new byte[0];
int offset = 0;
int len = 0;
// when
// then
MethodInvoker.create().object(sut).method("handleReceivedBytes").param(byte[].class, bytes).param(int.class, offset).param(int.class, len).call();
}
use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup in project ezyfox-server by youngmonkeys.
the class EzySimpleWsHandlerGroupTest method handleReceivedStreamNotEnable.
@Test
public void handleReceivedStreamNotEnable() throws Exception {
// given
EzyWsHandlerGroup sut = newHandlerGroup(false);
byte[] bytes = new byte[] { 1 << 4, 2, 3 };
int offset = 0;
int len = 3;
// when
MethodInvoker.create().object(sut).method("handleReceivedBytes").param(byte[].class, bytes).param(int.class, offset).param(int.class, len).call();
// then
EzySession session = FieldUtil.getFieldValue(sut, "session");
verify(session, times(1)).isStreamingEnable();
}
Aggregations