use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzyLoginProcessorTest method processUserSessionsMaxSessionPerUser.
@SuppressWarnings("rawtypes")
@Test
public void processUserSessionsMaxSessionPerUser() {
// given
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zoneSetting.getUserManagement().setMaxSessionPerUser(1);
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();
EzyUser user = mock(EzyUser.class);
when(user.getName()).thenReturn("monkey");
when(user.getSessionCount()).thenReturn(2);
userManager.addUser(user);
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
Throwable e = Asserts.assertThrows(() -> sut.apply(zoneContext, event));
// then
Asserts.assertEquals(EzyLoginErrorException.class, e.getClass());
}
use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzyLoginProcessorTest method processUserSessionsMaxSessionPerUserGreaterThan1.
@SuppressWarnings("rawtypes")
@Test
public void processUserSessionsMaxSessionPerUserGreaterThan1() {
// given
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zoneSetting.getUserManagement().setMaxSessionPerUser(2);
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();
EzyUser user = mock(EzyUser.class);
when(user.getName()).thenReturn("monkey");
when(user.getSessionCount()).thenReturn(2);
userManager.addUser(user);
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
Throwable e = Asserts.assertThrows(() -> sut.apply(zoneContext, event));
// then
Asserts.assertEquals(EzyLoginErrorException.class, e.getClass());
}
use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzyLoginProcessorTest method processUserSessionsOk.
@SuppressWarnings("rawtypes")
@Test
public void processUserSessionsOk() {
// given
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zoneSetting.getUserManagement().setMaxSessionPerUser(1);
zoneSetting.getUserManagement().setAllowChangeSession(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();
EzyUser user = mock(EzyUser.class);
when(user.getName()).thenReturn("monkey");
when(user.getSessionCount()).thenReturn(1);
userManager.addUser(user);
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
sut.apply(zoneContext, event);
// then
Asserts.assertTrue(session.isLoggedIn());
}
use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzyPingControllerTest method test.
@SuppressWarnings("rawtypes")
@Test
public void test() {
EzyPingController controller = new EzyPingController();
EzyServerContext serverContext = mock(EzyServerContext.class);
EzySimplePingRequest request = new EzySimplePingRequest();
controller.handle(serverContext, request);
EzySimpleSettings settings = new EzySimpleSettings();
EzyServer server = mock(EzyServer.class);
when(server.getSettings()).thenReturn(settings);
when(serverContext.getServer()).thenReturn(server);
assert MethodInvoker.create().object(controller).method("getSettings").param(EzyServerContext.class, serverContext).invoke() == settings;
EzySessionManager sessionManager = mock(EzySessionManager.class);
when(server.getSessionManager()).thenReturn(sessionManager);
assert MethodInvoker.create().object(controller).method("getSessionManager").param(EzyServerContext.class, serverContext).invoke() == sessionManager;
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);
assert MethodInvoker.create().object(controller).method("getUserManager").param(EzyZoneContext.class, zoneContext).invoke() == zoneUserManager;
}
use of com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandlerTest method handleReceivedStreaming0ExceptionCase.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void handleReceivedStreaming0ExceptionCase() 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);
doThrow(new IllegalArgumentException("server maintain")).when(streamingInterceptor).intercept(any(), any());
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);
EzySimpleUser user = new EzySimpleUser();
user.addSession(session);
user.setZoneId(zoneId);
handler.onSessionLoggedIn(user);
handler.streamingReceived(new byte[] { 1, 2, 3 });
}
Aggregations