use of com.tvd12.ezyfoxserver.context.EzyZoneContext in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method maximumSession3Test.
@Test(expectedExceptions = EzyLoginErrorException.class)
public void maximumSession3Test() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
EzyZoneContext zoneContext = ctx.getZoneContext("example");
EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
userManagementSetting.setMaxSessionPerUser(1);
userManagementSetting.setAllowChangeSession(false);
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
data.set(1, "helloworld");
EzyLoginController controller = new EzyLoginController();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.context.EzyZoneContext in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method maximumSession2Test.
@Test(expectedExceptions = EzyLoginErrorException.class)
public void maximumSession2Test() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
EzyZoneContext zoneContext = ctx.getZoneContext("example");
EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
userManagementSetting.setMaxSessionPerUser(2);
userManagementSetting.setAllowChangeSession(false);
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession(1);
session.setToken("abcdef");
EzyArray data = newLoginData();
data.set(1, "helloworld");
EzyLoginController controller = new EzyLoginController();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
request.setSession(newSession(2));
controller.handle(ctx, request);
request.setSession(newSession(3));
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.context.EzyZoneContext 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.context.EzyZoneContext in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method fireUserAddedEvent0ExceptionCase.
@Test
public void fireUserAddedEvent0ExceptionCase() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzyLoginProcessor processor = new EzyLoginProcessor(ctx);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getZone()).thenReturn(ctx.getZoneContext("example").getZone());
doThrow(new IllegalStateException()).when(zoneContext).broadcastPlugins(any(EzyConstant.class), any(EzyEvent.class), anyBoolean());
MethodInvoker.create().method("doFireUserAddedEvent").object(processor).param(EzyZoneContext.class, zoneContext).param(EzyEvent.class, mock(EzyEvent.class)).invoke();
}
use of com.tvd12.ezyfoxserver.context.EzyZoneContext in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method processChangeSessionTest.
@Test
public void processChangeSessionTest() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
EzyZoneContext zoneContext = ctx.getZoneContext("example");
EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
userManagementSetting.setMaxSessionPerUser(1);
userManagementSetting.setAllowChangeSession(true);
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
data.set(1, "helloworld");
EzyLoginController controller = new EzyLoginController();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
controller.handle(ctx, request);
}
Aggregations