use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzyAccessAppControllerTest method newRequest.
protected EzySimpleAccessAppRequest newRequest(int index) {
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzySimpleUser user = new EzySimpleUser();
user.setName("user" + index);
user.setZoneId(1);
EzyArray params = EzyEntityFactory.newArrayBuilder().append("test").build();
EzySimpleAccessAppRequest request = new EzySimpleAccessAppRequest();
request.setUser(user);
request.setSession(session);
request.deserializeParams(params);
return request;
}
use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzyHandShakeController2Test method test.
@Test
public void test() {
EzyServerContext ctx = newServerContext();
EzySession first = getSessionManager(ctx).provideSession(EzyConnectionType.SOCKET);
System.err.println("first.token: " + first);
System.err.println("alive sessions: " + getSessionManager(ctx).getAliveSessions());
assertTrue(getSessionManager(ctx).containsSession(first.getId()));
EzySession session = getSessionManager(ctx).provideSession(EzyConnectionType.SOCKET);
System.err.println("session: " + session);
EzyArray data = newHandShakeData(first.getToken());
EzySimpleHandshakeRequest request = new EzySimpleHandshakeRequest();
request.deserializeParams(data);
request.setSession(session);
EzyHandshakeParams requestParams = request.getParams();
assertEquals(first.getToken(), requestParams.getReconnectToken());
EzyHandshakeController controller = new EzyHandshakeController();
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzyHandShakeControllerTest method test.
@Test
public void test() {
EzyServerContext ctx = newServerContext();
EzySession session = newSession();
EzyArray data = newHandShakeData();
EzyHandshakeController controller = new EzyHandshakeController();
EzySimpleHandshakeRequest request = new EzySimpleHandshakeRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandlerTest method normalCase.
@SuppressWarnings("rawtypes")
@Test
public void normalCase() {
int zoneId = 1;
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyZone zone = mock(EzyZone.class);
when(zoneContext.getZone()).thenReturn(zone);
EzyZoneUserManager zoneUserManager = mock(EzyZoneUserManager.class);
when(zone.getUserManager()).thenReturn(zoneUserManager);
when(serverContext.getZoneContext(zoneId)).thenReturn(zoneContext);
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzyChannel channel = mock(EzyChannel.class);
when(session.getChannel()).thenReturn(channel);
EzyServer server = mock(EzyServer.class);
when(serverContext.getServer()).thenReturn(server);
EzyServerControllers controllers = mock(EzyServerControllers.class);
EzyInterceptor streamingInterceptor = mock(EzyInterceptor.class);
when(controllers.getStreamingInterceptor()).thenReturn(streamingInterceptor);
EzyStreamingController streamingController = mock(EzyStreamingController.class);
when(controllers.getStreamingController()).thenReturn(streamingController);
EzyInterceptor loginInterceptor = mock(EzyInterceptor.class);
when(controllers.getInterceptor(EzyCommand.LOGIN)).thenReturn(loginInterceptor);
EzyController loginController = mock(EzyController.class);
when(controllers.getController(EzyCommand.LOGIN)).thenReturn(loginController);
when(server.getControllers()).thenReturn(controllers);
EzySessionManager sessionManager = mock(EzySessionManager.class);
when(server.getSessionManager()).thenReturn(sessionManager);
EzyCloseSession closeSession = mock(EzyCloseSession.class);
when(serverContext.get(EzyCloseSession.class)).thenReturn(closeSession);
EzySettings settings = mock(EzySettings.class);
when(settings.isDebug()).thenReturn(true);
when(server.getSettings()).thenReturn(settings);
EzySessionManagementSetting sessionManagementSetting = mock(EzySessionManagementSetting.class);
when(settings.getSessionManagement()).thenReturn(sessionManagementSetting);
EzyLoggerSetting loggerSetting = mock(EzyLoggerSetting.class);
when(settings.getLogger()).thenReturn(loggerSetting);
EzyLoggerSetting.EzyIgnoredCommandsSetting ignoredCommandsSetting = mock(EzyLoggerSetting.EzyIgnoredCommandsSetting.class);
when(loggerSetting.getIgnoredCommands()).thenReturn(ignoredCommandsSetting);
when(ignoredCommandsSetting.getCommands()).thenReturn(new HashSet<>());
EzySessionManagementSetting.EzyMaxRequestPerSecond maxRequestPerSecond = mock(EzySessionManagementSetting.EzyMaxRequestPerSecond.class);
when(maxRequestPerSecond.getValue()).thenReturn(3);
when(maxRequestPerSecond.getAction()).thenReturn(EzyMaxRequestPerSecondAction.DISCONNECT_SESSION);
when(sessionManagementSetting.getSessionMaxRequestPerSecond()).thenReturn(maxRequestPerSecond);
MyTestDataHandler handler = new MyTestDataHandler(serverContext, session);
when(session.getDelegate()).thenReturn(handler);
when(session.isActivated()).thenReturn(true);
EzyArray loginData = EzyEntityFactory.newArrayBuilder().append("zone").append("username").append("password").append(EzyEntityFactory.newObject()).build();
EzyArray requestData = EzyEntityFactory.newArrayBuilder().append(EzyCommand.LOGIN.getId()).append(loginData).build();
handler.dataReceived(EzyCommand.LOGIN, requestData);
EzySimpleUser user = new EzySimpleUser();
user.addSession(session);
user.setZoneId(zoneId);
handler.onSessionLoggedIn(user);
handler.streamingReceived(new byte[] { 1, 2, 3 });
EzyArray accessAppData = EzyEntityFactory.newArrayBuilder().append("app").append(EzyEntityFactory.newObject()).build();
EzyArray requestData2 = EzyEntityFactory.newArrayBuilder().append(EzyCommand.APP_ACCESS.getId()).append(accessAppData).build();
handler.dataReceived(EzyCommand.APP_ACCESS, requestData2);
handler.dataReceived(EzyCommand.LOGIN, requestData);
handler.dataReceived(EzyCommand.LOGIN, requestData);
handler.exceptionCaught(new EzyMaxRequestSizeException(1024, 512));
handler.channelInactive(EzyDisconnectReason.ADMIN_BAN);
handler.channelInactive(EzyDisconnectReason.ADMIN_BAN);
handler.destroy();
System.out.println(handler);
}
use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandlerTest method dataReceivedValidateSessionIsNull.
@Test
public void dataReceivedValidateSessionIsNull() {
// given
MyTestDataHandler sut = createHandler();
FieldUtil.setFieldValue(sut, "session", null);
EzyArray msg = EzyEntityFactory.newArray();
// when
sut.dataReceived(EzyCommand.APP_ACCESS, msg);
// then
Asserts.assertNull(FieldUtil.getFieldValue(sut, "session"));
}
Aggregations