Search in sources :

Example 16 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.

the class EzyLoginControllerTest method maximumSession1Test.

@Test(expectedExceptions = EzyLoginErrorException.class)
public void maximumSession1Test() {
    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(0);
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySession session = newSession();
    session.setToken("abcdef");
    EzyArray data = newLoginData();
    data.set(1, "");
    EzyLoginController controller = new EzyLoginController();
    EzySimpleLoginRequest request = new EzySimpleLoginRequest();
    request.deserializeParams(data);
    request.setSession(session);
    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 17 with Request

use of com.tvd12.ezyhttp.client.request.Request 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);
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzySimpleUserLoginEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserLoginEvent) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyLoginParams(com.tvd12.ezyfoxserver.request.EzyLoginParams) 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) EzyLoginProcessor(com.tvd12.ezyfoxserver.controller.EzyLoginProcessor) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) Test(org.testng.annotations.Test)

Example 18 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.

the class EzyLoginControllerTest method test1.

@Test(expectedExceptions = { EzyLoginErrorException.class })
public void test1() {
    EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
    EzySimpleServer server = (EzySimpleServer) ctx.getServer();
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySession session = newSession();
    session.setToken("abcdef");
    EzyArray data = newLoginData1();
    EzyLoginController controller = new EzyLoginController() {

        @Override
        protected void process(EzyServerContext ctx, EzyZoneContext zoneContext, EzyUserLoginEvent event) {
            throw new EzyLoginErrorException();
        }
    };
    EzySimpleLoginRequest request = new EzySimpleLoginRequest();
    request.deserializeParams(data);
    request.setSession(session);
    controller.handle(ctx, request);
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Example 19 with Request

use of com.tvd12.ezyhttp.client.request.Request 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 20 with Request

use of com.tvd12.ezyhttp.client.request.Request 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)

Aggregations

Test (org.testng.annotations.Test)128 HttpServletResponse (javax.servlet.http.HttpServletResponse)48 HttpServletRequest (javax.servlet.http.HttpServletRequest)45 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)37 BeforeTest (org.testng.annotations.BeforeTest)36 BaseTest (com.tvd12.test.base.BaseTest)31 EzyArray (com.tvd12.ezyfox.entity.EzyArray)30 ComponentManager (com.tvd12.ezyhttp.server.core.manager.ComponentManager)29 BlockingServlet (com.tvd12.ezyhttp.server.core.servlet.BlockingServlet)29 ToString (lombok.ToString)29 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)27 ServletOutputStream (javax.servlet.ServletOutputStream)25 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)24 RequestHandlerManager (com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager)24 Cookie (javax.servlet.http.Cookie)24 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)22 RequestCookie (com.tvd12.ezyhttp.server.core.annotation.RequestCookie)22 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)21 HttpClient (com.tvd12.ezyhttp.client.HttpClient)21 PostRequest (com.tvd12.ezyhttp.client.request.PostRequest)21