use of com.tvd12.ezyfoxserver.EzySimpleZone 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.EzySimpleZone 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());
}
use of com.tvd12.ezyfoxserver.EzySimpleZone 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.EzySimpleZone 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.EzySimpleZone 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());
}
Aggregations