use of com.tvd12.ezyfoxserver.entity.EzySession 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();
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method invalidUsernameTest.
@Test(expectedExceptions = EzyLoginErrorException.class)
public void invalidUsernameTest() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
EzyZoneContext zoneContext = ctx.getZoneContext("example");
EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
userManagementSetting.setAllowGuestLogin(false);
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
data.set(1, "");
EzyLoginController controller = new EzyLoginController();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method allowGuestLoginTest.
@Test
public void allowGuestLoginTest() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
data.set(1, "");
EzyLoginController controller = new EzyLoginController();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method testExceptionCase.
@SuppressWarnings("rawtypes")
@Test(expectedExceptions = IllegalStateException.class)
public void testExceptionCase() {
EzyServerContext ctx = mock(EzyServerContext.class);
doThrow(new IllegalStateException("server maintain")).when(ctx).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
EzyStatistics userStats = new EzySimpleStatistics();
EzySimpleServer server = new EzySimpleServer();
server.setStatistics(userStats);
when(ctx.getServer()).thenReturn(server);
server.setResponseApi(mock(EzyResponseApi.class));
EzySessionManager sessionManager = mock(EzySessionManager.class);
server.setSessionManager(sessionManager);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(ctx.getZoneContext("example")).thenReturn(zoneContext);
EzySimpleZone zone = new EzySimpleZone();
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zone.setSetting(zoneSetting);
when(zoneContext.getZone()).thenReturn(zone);
EzyZoneUserManager zoneUserManager = EzyZoneUserManagerImpl.builder().maxUsers(1).build();
zone.setUserManager(zoneUserManager);
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
EzyLoginController controller = new EzyLoginController() {
@Override
protected void responseLoginError(EzyServerContext ctx, EzySession session, EzyILoginError error) {
}
};
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyHandShakeControllerTest method handleSocketSSLButWebsocketTest.
@Test
public void handleSocketSSLButWebsocketTest() {
// given
EzyHandshakeController sut = new EzyHandshakeController();
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyHandShakeRequest request = mock(EzyHandShakeRequest.class);
EzyHandshakeParams params = mock(EzyHandshakeParams.class);
when(request.getParams()).thenReturn(params);
EzySession session = spy(EzyAbstractSession.class);
when(session.getConnectionType()).thenReturn(EzyConnectionType.WEBSOCKET);
when(request.getSession()).thenReturn(session);
// when
sut.handle(serverContext, request);
// then
Asserts.assertNull(session.getSessionKey());
}
Aggregations