Search in sources :

Example 51 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyAbstractHandlerGroupTest method handleReceivedDataNotSuccess.

@Test
public void handleReceivedDataNotSuccess() throws Exception {
    // given
    ExHandlerGroup sut = newHandlerGroup();
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    when(session.addReceivedRequests(1)).thenReturn(false);
    when(session.isActivated()).thenReturn(true);
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = FieldUtil.getFieldValue(sut, "sessionTicketsRequestQueues");
    EzyArray data = EzyEntityFactory.newArrayBuilder().append(EzyCommand.APP_ACCESS.getId()).append(EzyEntityFactory.newArray()).build();
    // when
    MethodInvoker.create().object(sut).method("handleReceivedData").param(Object.class, data).param(int.class, 100).call();
    // then
    verify(sessionTicketsRequestQueues, times(1)).addRequest(any());
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 52 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyAbstractHandlerGroupTest method executeSendingPacketCanNotWriteBytes.

@Test
public void executeSendingPacketCanNotWriteBytes() throws Exception {
    // given
    ExHandlerGroup sut = newHandlerGroup();
    EzyPacket packet = mock(EzyPacket.class);
    ByteBuffer writeBuffer = ByteBuffer.wrap(new byte[0]);
    // when
    MethodInvoker.create().object(sut).method("executeSendingPacket").param(EzyPacket.class, packet).param(Object.class, writeBuffer).call();
    // then
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    verify(session, times(3)).getChannel();
}
Also used : ByteBuffer(java.nio.ByteBuffer) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 53 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyAbstractHandlerGroupTest method fireExceptionCaughtException.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void fireExceptionCaughtException() throws Exception {
    // given
    ExHandlerGroup sut = newHandlerGroup();
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    EzyNioDataHandler handler = FieldUtil.getFieldValue(sut, "handler");
    EzySessionManager sessionManager = FieldUtil.getFieldValue(handler, "sessionManager");
    doThrow(new RuntimeException()).when(sessionManager).removeSession(session, MAX_REQUEST_SIZE);
    EzyMaxRequestSizeException exception = new EzyMaxRequestSizeException("just test");
    // when
    sut.fireExceptionCaught(exception);
    // then
    verify(sessionManager, times(1)).removeSession(session, MAX_REQUEST_SIZE);
}
Also used : EzyNioDataHandler(com.tvd12.ezyfoxserver.nio.handler.EzyNioDataHandler) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyMaxRequestSizeException(com.tvd12.ezyfox.exception.EzyMaxRequestSizeException) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 54 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzySimpleNioHandlerGroupTest method handleReceivedMessageHeaderIsNotRawBytes.

@Test
public void handleReceivedMessageHeaderIsNotRawBytes() throws Exception {
    // given
    EzySimpleNioHandlerGroup sut = newHandlerGroup();
    EzyMessage message = mock(EzyMessage.class);
    EzyMessageHeader header = mock(EzyMessageHeader.class);
    when(message.getHeader()).thenReturn(header);
    // when
    MethodInvoker.create().object(sut).method("handleReceivedMessage").param(EzyMessage.class, message).call();
    // then
    verify(header, times(1)).isRawBytes();
    EzySimpleMessageDataDecoder decoder = FieldUtil.getFieldValue(sut, "decoder");
    EzyByteToObjectDecoder d = FieldUtil.getFieldValue(decoder, "decoder");
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    verify(d, times(1)).decode(message, session.getSessionKey());
}
Also used : EzySimpleNioHandlerGroup(com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioHandlerGroup) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 55 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzySimpleSessionManagerTest method isUnloggedInSessionFalseTest.

@Test
public void isUnloggedInSessionFalseTest() {
    // given
    MyTestSessionManager manager = new MyTestSessionManager.Builder().build();
    EzySession session = mock(EzySession.class);
    when(session.isLoggedIn()).thenReturn(false);
    when(session.isActivated()).thenReturn(true);
    when(session.getMaxWaitingTime()).thenReturn(1000L);
    when(session.getCreationTime()).thenReturn(System.currentTimeMillis() - 100L);
    // when
    Boolean result = MethodInvoker.create().object(manager).method("isUnloggedInSession").param(EzySession.class, session).invoke(Boolean.class);
    // then
    Asserts.assertFalse(result);
}
Also used : MyTestSessionManager(com.tvd12.ezyfoxserver.testing.MyTestSessionManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)112 Test (org.testng.annotations.Test)92 EzyArray (com.tvd12.ezyfox.entity.EzyArray)33 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)26 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)25 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)25 BaseTest (com.tvd12.test.base.BaseTest)25 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)15 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)13 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)13 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)11 EzySendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl)8 EzyHandshakeController (com.tvd12.ezyfoxserver.controller.EzyHandshakeController)8 EzyHandshakeParams (com.tvd12.ezyfoxserver.request.EzyHandshakeParams)8 EzySimpleResponse (com.tvd12.ezyfoxserver.response.EzySimpleResponse)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8