use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandlerTest method handleRequestExceptionCase2.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void handleRequestExceptionCase2() 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();
doThrow(new IllegalStateException("server maintain")).when(loginInterceptor).intercept(any(), any());
FieldUtil.setFieldValue(handler, "context", null);
FieldUtil.setFieldValue(handler, "active", false);
MethodInvoker.create().object(handler).method("handleRequest").param(EzyConstant.class, EzyCommand.LOGIN).param(EzyArray.class, loginData).invoke();
}
use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandlerTest method handleRequestExceptionCase1.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void handleRequestExceptionCase1() 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();
doThrow(new IllegalStateException("server maintain")).when(loginInterceptor).intercept(any(), any());
FieldUtil.setFieldValue(handler, "context", null);
handler.dataReceived(EzyCommand.LOGIN, requestData);
}
use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method testSetUserProperties.
@Test
public void testSetUserProperties() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
EzyLoginProcessor processor = new EzyLoginProcessor(ctx);
EzyZoneContext zoneContext = ctx.getZoneContext("example");
EzyLoginParams params = request.getParams();
EzySimpleUserLoginEvent event = new EzySimpleUserLoginEvent(session, params.getZoneName(), params.getUsername(), params.getPassword(), params.getData());
event.setUserProperty("dataId", 123L);
processor.apply(zoneContext, event);
event.release();
EzyZoneUserManager userManager = zoneContext.getZone().getUserManager();
EzyUser user = userManager.getUser("dungtv");
assert user.getProperty("dataId").equals(123L);
}
use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method testEzyMaxUserExceptionCase.
@SuppressWarnings("rawtypes")
@Test(expectedExceptions = EzyMaxUserException.class)
public void testEzyMaxUserExceptionCase() {
EzyServerContext ctx = mock(EzyServerContext.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();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
data.set(1, "test1");
request.deserializeParams(data);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzyLoginProcessorTest method applyWithStreamingEnable.
@SuppressWarnings("rawtypes")
@Test
public void applyWithStreamingEnable() {
// given
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zoneSetting.getStreaming().setEnable(true);
EzySimpleZone zone = new EzySimpleZone();
zone.setSetting(zoneSetting);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getZone()).thenReturn(zone);
EzySimpleServer server = new EzySimpleServer();
EzySessionManager sessionManager = mock(EzySessionManager.class);
server.setSessionManager(sessionManager);
EzyZoneUserManager userManager = EzyZoneUserManagerImpl.builder().build();
zone.setUserManager(userManager);
EzyStatistics statistics = mock(EzyStatistics.class);
EzyUserStatistics userStatistics = mock(EzyUserStatistics.class);
when(statistics.getUserStats()).thenReturn(userStatistics);
server.setStatistics(statistics);
EzyServerContext serverContext = mock(EzyServerContext.class);
when(serverContext.getServer()).thenReturn(server);
EzyLoginProcessor sut = new EzyLoginProcessor(serverContext);
EzySessionDelegate sessionDelegate = mock(EzySessionDelegate.class);
EzyAbstractSession session = spy(EzyAbstractSession.class);
session.setDelegate(sessionDelegate);
EzyUserLoginEvent event = mock(EzyUserLoginEvent.class);
when(event.getUsername()).thenReturn("monkey");
when(event.getSession()).thenReturn(session);
when(event.isStreamingEnable()).thenReturn(true);
// when
sut.apply(zoneContext, event);
// then
Asserts.assertTrue(session.isStreamingEnable());
}
Aggregations