Search in sources :

Example 1 with EzyWsHandlerGroup

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);
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) Session(org.eclipse.jetty.websocket.api.Session) Test(org.testng.annotations.Test)

Example 2 with EzyWsHandlerGroup

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);
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) Session(org.eclipse.jetty.websocket.api.Session) Test(org.testng.annotations.Test)

Example 3 with EzyWsHandlerGroup

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();
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 4 with EzyWsHandlerGroup

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();
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 5 with EzyWsHandlerGroup

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();
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzyWsHandlerGroup (com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup)8 Test (org.testng.annotations.Test)8 BaseTest (com.tvd12.test.base.BaseTest)6 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)4 EzySocketDataReceiver (com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver)2 EzyHandlerGroupManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager)2 Session (org.eclipse.jetty.websocket.api.Session)2