Search in sources :

Example 21 with EzyZoneContext

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);
}
Also used : EzySimpleUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Example 22 with EzyZoneContext

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);
}
Also used : EzySimpleUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Example 23 with EzyZoneContext

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);
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test)

Example 24 with EzyZoneContext

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();
}
Also used : EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzyLoginProcessor(com.tvd12.ezyfoxserver.controller.EzyLoginProcessor) Test(org.testng.annotations.Test)

Example 25 with EzyZoneContext

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);
}
Also used : EzySimpleUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Aggregations

EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)77 Test (org.testng.annotations.Test)65 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)42 BaseTest (com.tvd12.test.base.BaseTest)26 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)24 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)23 EzyZone (com.tvd12.ezyfoxserver.EzyZone)21 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)21 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)20 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)20 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)18 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)18 EzyArray (com.tvd12.ezyfox.entity.EzyArray)17 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)17 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)15 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)13 EzyPluginContext (com.tvd12.ezyfoxserver.context.EzyPluginContext)13 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)12 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)12 EzyServer (com.tvd12.ezyfoxserver.EzyServer)11