use of com.tvd12.ezyfoxserver.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.
the class EzyRequestPluginControllerTest method test.
@Test
public void test() {
EzyRequestPluginController controller = new EzyRequestPluginController();
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
EzyPluginContext pluginContext = mock(EzyPluginContext.class);
when(zoneContext.getPluginContext(1)).thenReturn(pluginContext);
EzyPlugin plugin = mock(EzyPlugin.class);
when(pluginContext.getPlugin()).thenReturn(plugin);
EzyPluginRequestController requestController = mock(EzyPluginRequestController.class);
when(plugin.getRequestController()).thenReturn(requestController);
EzySimpleRequestPluginRequest request = new EzySimpleRequestPluginRequest();
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzySimpleUser user = new EzySimpleUser();
user.setZoneId(1);
user.setId(1);
user.setName("test");
request.setSession(session);
request.setUser(user);
EzyArray array = EzyEntityFactory.newArrayBuilder().append(1).append(EzyEntityFactory.newArrayBuilder()).build();
request.deserializeParams(array);
controller.handle(serverContext, request);
}
use of com.tvd12.ezyfoxserver.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.
the class EzySimpleAppUserDelegateTest method testExceptionCase.
@Test
public void testExceptionCase() {
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyApplication app = mock(EzyApplication.class);
when(appContext.getApp()).thenReturn(app);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
when(app.getSetting()).thenReturn(appSetting);
when(appContext.getParent()).thenReturn(zoneContext);
doThrow(new IllegalStateException()).when(appContext).handleEvent(any(), any());
EzySimpleAppUserDelegate delegate = new EzySimpleAppUserDelegate();
delegate.setAppContext(appContext);
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
delegate.onUserRemoved(user, EzyUserRemoveReason.EXIT_APP);
}
use of com.tvd12.ezyfoxserver.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.
the class EzySimpleAppUserDelegateTest method test.
@Test
public void test() {
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyApplication app = mock(EzyApplication.class);
when(appContext.getApp()).thenReturn(app);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
when(app.getSetting()).thenReturn(appSetting);
when(appContext.getParent()).thenReturn(zoneContext);
EzySimpleAppUserDelegate delegate = new EzySimpleAppUserDelegate();
delegate.setAppContext(appContext);
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
delegate.onUserRemoved(user, EzyUserRemoveReason.EXIT_APP);
}
use of com.tvd12.ezyfoxserver.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandlerTest method checkMaxRequestPerSecondCase.
@SuppressWarnings("rawtypes")
@Test
public void checkMaxRequestPerSecondCase() throws Exception {
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);
Thread.sleep(1200);
handler.dataReceived(EzyCommand.LOGIN, requestData);
}
use of com.tvd12.ezyfoxserver.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.
the class EzySimpleUserTest method test.
@Test
public void test() {
EzySimpleUser user = new EzySimpleUser();
user.setId(1);
user.setPassword("abc");
assert user.getPassword().equals("abc");
user.setName("dungtv1");
EzySimpleUser user2 = new EzySimpleUser();
user2.setPassword("abc");
user2.setId(2);
assert user2.getPassword().equals("abc");
user.setName("dungtv2");
assert !user.equals(user2);
assert user.hashCode() != user2.hashCode();
assert user.getLocks() != null;
assert user.getSessionMap() != null;
assert user.getMaxSessions() == 30;
assert user.getStartIdleTime() > 0;
assert !user.isDestroyed();
assert user.getSession() == null;
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzyImmediateDeliver immediateDeliver = mock(EzyImmediateDeliver.class);
EzySocketDisconnectionQueue disconnectionQueue = mock(EzySocketDisconnectionQueue.class);
session.setImmediateDeliver(immediateDeliver);
session.setDisconnectionQueue(disconnectionQueue);
user.addSession(session);
assert user.getSession() == session;
Lock lock = user.getLock("test");
assert lock != null;
EzyPacket packet = mock(EzyPacket.class);
user.send(packet);
user.sendNow(packet);
user.disconnect(EzyDisconnectReason.IDLE);
user.disconnect();
user.removeSession(session);
user.setMaxIdleTime(100 * 60 * 1000);
assert !user.isIdle();
user.setMaxIdleTime(-1);
assert user.isIdle();
user.destroy();
user.destroy();
assert user.getSessions().size() == 0;
}
Aggregations