Search in sources :

Example 1 with EzySimpleSocketDisconnection

use of com.tvd12.ezyfoxserver.socket.EzySimpleSocketDisconnection in project ezyfox-server by youngmonkeys.

the class EzyDisconnectUserImplTest method test.

@Test
public void test() {
    // given
    String token = RandomUtil.randomShortAlphabetString();
    EzySession session = newSession();
    session.setToken(token);
    String username = RandomUtil.randomShortAlphabetString();
    EzySimpleUser user = newUser();
    user.setName(username);
    user.addSession(session);
    // when
    EzySimpleSocketDisconnection disconnection = new EzySimpleSocketDisconnection(session, EzyDisconnectReason.ADMIN_BAN);
    // when
    Asserts.assertEquals(user.getName(), username);
    Asserts.assertEquals(user.getSession(), session);
    Asserts.assertEquals(session.getToken(), token);
    Asserts.assertEquals(disconnection.getSession(), session);
    Asserts.assertEquals(disconnection.getDisconnectReason(), EzyDisconnectReason.ADMIN_BAN);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleSocketDisconnection(com.tvd12.ezyfoxserver.socket.EzySimpleSocketDisconnection) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 2 with EzySimpleSocketDisconnection

use of com.tvd12.ezyfoxserver.socket.EzySimpleSocketDisconnection in project ezyfox-server by youngmonkeys.

the class EzySocketDisconnectionHandlerTest method processDisconnectionQueueExceptionCaseTest.

@Test
public void processDisconnectionQueueExceptionCaseTest() {
    EzySocketDisconnectionHandler handler = new EzySocketDisconnectionHandler();
    EzySocketDisconnectionQueue disconnectionQueue = new EzyBlockingSocketDisconnectionQueue();
    EzySocketDataHandlerGroupRemover dataHandlerGroupRemover = mock(EzySocketDataHandlerGroupRemover.class);
    when(dataHandlerGroupRemover.removeHandlerGroup(any(EzySession.class))).thenThrow(new IllegalArgumentException());
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketDisconnection disconnection = new EzySimpleSocketDisconnection(session);
    disconnectionQueue.add(disconnection);
    handler.setDisconnectionQueue(disconnectionQueue);
    handler.setDataHandlerGroupRemover(dataHandlerGroupRemover);
    handler.handleEvent();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 3 with EzySimpleSocketDisconnection

use of com.tvd12.ezyfoxserver.socket.EzySimpleSocketDisconnection in project ezyfox-server by youngmonkeys.

the class EzySocketDisconnectionHandlerTest method test.

@Test
public void test() {
    EzySocketDisconnectionHandler handler = new EzySocketDisconnectionHandler();
    EzySocketDisconnectionQueue disconnectionQueue = new EzyBlockingSocketDisconnectionQueue();
    EzySocketDataHandlerGroupRemover dataHandlerGroupRemover = mock(EzySocketDataHandlerGroupRemover.class);
    EzySocketDataHandlerGroup handlerGroup = mock(EzySocketDataHandlerGroup.class);
    when(dataHandlerGroupRemover.removeHandlerGroup(any(EzySession.class))).thenReturn(handlerGroup);
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketDisconnection disconnection = new EzySimpleSocketDisconnection(session);
    disconnectionQueue.add(disconnection);
    handler.setDisconnectionQueue(disconnectionQueue);
    handler.setDataHandlerGroupRemover(dataHandlerGroupRemover);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 4 with EzySimpleSocketDisconnection

use of com.tvd12.ezyfoxserver.socket.EzySimpleSocketDisconnection in project ezyfox-server by youngmonkeys.

the class EzySocketDisconnectionHandlerTest method hasNoHandlerGroupCaseTest.

@Test
public void hasNoHandlerGroupCaseTest() {
    EzySocketDisconnectionHandler handler = new EzySocketDisconnectionHandler();
    EzySocketDisconnectionQueue disconnectionQueue = new EzyBlockingSocketDisconnectionQueue();
    EzySocketDataHandlerGroupRemover dataHandlerGroupRemover = mock(EzySocketDataHandlerGroupRemover.class);
    when(dataHandlerGroupRemover.removeHandlerGroup(any(EzySession.class))).thenReturn(null);
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketDisconnection disconnection = new EzySimpleSocketDisconnection(session);
    disconnectionQueue.add(disconnection);
    handler.setDisconnectionQueue(disconnectionQueue);
    handler.setDataHandlerGroupRemover(dataHandlerGroupRemover);
    handler.handleEvent();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)4 Test (org.testng.annotations.Test)4 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)1 EzySimpleSocketDisconnection (com.tvd12.ezyfoxserver.socket.EzySimpleSocketDisconnection)1 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)1