Search in sources :

Example 26 with Request

use of com.tvd12.ezyhttp.client.request.Request 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;
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPingController(com.tvd12.ezyfoxserver.controller.EzyPingController) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzySimplePingRequest(com.tvd12.ezyfoxserver.request.EzySimplePingRequest) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 27 with Request

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

the class EzyAccessAppControllerTest method accessAppFailedDueToMaxUserAfterAccess.

@Test
public void accessAppFailedDueToMaxUserAfterAccess() {
    // given
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyApplication app = mock(EzyApplication.class);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    when(app.getSetting()).thenReturn(appSetting);
    when(appContext.getApp()).thenReturn(app);
    EzySimpleAppUserDelegate userDelegate = new EzySimpleAppUserDelegate();
    userDelegate.setAppContext(appContext);
    EzyAppUserManager appUserManager = mock(EzyAppUserManager.class);
    when(appUserManager.getMaxUsers()).thenReturn(1);
    when(app.getUserManager()).thenReturn(appUserManager);
    when(zoneContext.getAppContext("test")).thenReturn(appContext);
    EzySimpleAccessAppRequest request = newRequest(1);
    EzyUser user = request.getUser();
    when(appUserManager.getLock(user.getName())).thenReturn(new ReentrantLock());
    doThrow(new EzyMaxUserException(1, 1)).when(appUserManager).addUser(user);
    EzyAccessAppController underTest = new EzyAccessAppController();
    // when
    Throwable e = Asserts.assertThrows(() -> underTest.handle(serverContext, request));
    // then
    Asserts.assertEqualsType(e, EzyAccessAppException.class);
    Asserts.assertEqualsType(e.getCause(), EzyMaxUserException.class);
    verify(appUserManager, times(1)).containsUser(user);
    verify(appUserManager, times(1)).getUserCount();
    verify(appUserManager, times(1)).getMaxUsers();
    verify(appUserManager, times(1)).getAppName();
    verify(appUserManager, times(1)).getLock(user.getName());
    verify(appUserManager, times(1)).removeLock(user.getName());
    verify(appUserManager, times(1)).addUser(user);
    verify(appContext, times(1)).handleEvent(eq(EzyEventType.USER_ACCESS_APP), any(EzySimpleUserAccessAppEvent.class));
    verify(serverContext, times(1)).getZoneContext(1);
    verify(zoneContext, times(1)).getAppContext("test");
    verify(appContext, times(1)).getApp();
    verify(app, times(1)).getSetting();
    verify(app, times(1)).getUserManager();
    // 1 for success, 1 for failure
    verify(serverContext, times(1)).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) ReentrantLock(java.util.concurrent.locks.ReentrantLock) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleAppUserDelegate(com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAccessAppController(com.tvd12.ezyfoxserver.controller.EzyAccessAppController) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAccessAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleAccessAppRequest) EzySimpleUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 28 with Request

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

the class EzyAccessAppControllerTest method newRequest.

protected EzySimpleAccessAppRequest newRequest(int index) {
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user" + index);
    user.setZoneId(1);
    EzyArray params = EzyEntityFactory.newArrayBuilder().append("test").build();
    EzySimpleAccessAppRequest request = new EzySimpleAccessAppRequest();
    request.setUser(user);
    request.setSession(session);
    request.deserializeParams(params);
    return request;
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleAccessAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleAccessAppRequest)

Example 29 with Request

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

the class EzyHandShakeController2Test method test.

@Test
public void test() {
    EzyServerContext ctx = newServerContext();
    EzySession first = getSessionManager(ctx).provideSession(EzyConnectionType.SOCKET);
    System.err.println("first.token:    " + first);
    System.err.println("alive sessions: " + getSessionManager(ctx).getAliveSessions());
    assertTrue(getSessionManager(ctx).containsSession(first.getId()));
    EzySession session = getSessionManager(ctx).provideSession(EzyConnectionType.SOCKET);
    System.err.println("session: " + session);
    EzyArray data = newHandShakeData(first.getToken());
    EzySimpleHandshakeRequest request = new EzySimpleHandshakeRequest();
    request.deserializeParams(data);
    request.setSession(session);
    EzyHandshakeParams requestParams = request.getParams();
    assertEquals(first.getToken(), requestParams.getReconnectToken());
    EzyHandshakeController controller = new EzyHandshakeController();
    controller.handle(ctx, request);
}
Also used : EzyHandshakeParams(com.tvd12.ezyfoxserver.request.EzyHandshakeParams) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleHandshakeRequest(com.tvd12.ezyfoxserver.request.EzySimpleHandshakeRequest) EzyHandshakeController(com.tvd12.ezyfoxserver.controller.EzyHandshakeController) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 30 with Request

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

the class EzyHandShakeControllerTest method handleSocketSSLButEventNoEncryptionTest.

@Test
public void handleSocketSSLButEventNoEncryptionTest() {
    // given
    EzyHandshakeController sut = new EzyHandshakeController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyHandShakeRequest request = mock(EzyHandShakeRequest.class);
    EzyHandshakeParams params = mock(EzyHandshakeParams.class);
    when(request.getParams()).thenReturn(params);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
    when(request.getSession()).thenReturn(session);
    EzyServer server = mock(EzyServer.class);
    EzySettings settings = mock(EzySettings.class);
    EzySocketSetting socketSetting = mock(EzySocketSetting.class);
    when(settings.getSocket()).thenReturn(socketSetting);
    when(socketSetting.isSslActive()).thenReturn(true);
    when(serverContext.getServer()).thenReturn(server);
    when(server.getSettings()).thenReturn(settings);
    when(params.isEnableEncryption()).thenReturn(false);
    // when
    sut.handle(serverContext, request);
    // then
    Asserts.assertNull(session.getSessionKey());
}
Also used : EzyHandShakeRequest(com.tvd12.ezyfoxserver.request.EzyHandShakeRequest) EzyHandshakeParams(com.tvd12.ezyfoxserver.request.EzyHandshakeParams) EzySocketSetting(com.tvd12.ezyfoxserver.setting.EzySocketSetting) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyHandshakeController(com.tvd12.ezyfoxserver.controller.EzyHandshakeController) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) 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