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;
}
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));
}
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;
}
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);
}
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());
}
Aggregations