use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzySimpleZoneContextTest method normalCaseTest.
@SuppressWarnings("unchecked")
@Test
public void normalCaseTest() {
EzyServerContext parent = mock(EzyServerContext.class);
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zoneSetting.setName("test");
EzySimpleZone zone = new EzySimpleZone();
zone.setUserManager(mock(EzyZoneUserManager.class));
zone.setSetting(zoneSetting);
EzySimpleZoneContext context = new EzySimpleZoneContext();
context.setZone(zone);
context.setParent(parent);
context.init();
assert context.get(EzyBroadcastEvent.class) != null;
Asserts.assertNull(context.get(Void.class));
context.addCommand(ExCommand.class, ExCommand::new);
assert context.cmd(ExCommand.class) != null;
Asserts.assertNull(context.cmd(Void.class));
context.broadcast(EzyEventType.SERVER_INITIALIZING, new EzySimpleServerInitializingEvent(), true);
context.broadcastApps(EzyEventType.SERVER_READY, new EzySimpleServerReadyEvent(), true);
EzySimpleUser user = new EzySimpleUser();
user.setName("dungtv");
EzyUserAccessAppEvent accessAppEvent = new EzySimpleUserAccessAppEvent(user);
context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, "dungtv", true);
context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, user, true);
context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, EzyPredicates.ALWAYS_TRUE, true);
// noinspection EqualsWithItself
assert context.equals(context);
EzyZoneContext zoneContext2 = mock(EzyZoneContext.class);
EzySimpleZone zone2 = new EzySimpleZone();
when(zoneContext2.getZone()).thenReturn(zone2);
assert !zoneContext2.equals(context);
System.out.println(context.hashCode() + ", " + context.hashCode());
assert context.hashCode() == context.hashCode();
EzyResponse response = mock(EzyResponse.class);
EzySession recipient = spy(EzyAbstractSession.class);
context.send(response, recipient, false);
context.send(response, Lists.newArrayList(recipient), false);
context.stream(new byte[0], recipient);
context.stream(new byte[0], Lists.newArrayList(recipient));
context.destroy();
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyCloseSessionImplTest method noSendToClient.
@Test
public void noSendToClient() {
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyCloseSessionImpl cmd = new EzyCloseSessionImpl(serverContext);
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzyChannel channel = mock(EzyChannel.class);
session.setChannel(channel);
cmd.close(session, EzyDisconnectReason.UNKNOWN);
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyLoginController method handle.
@Override
public void handle(EzyServerContext ctx, EzyLoginRequest request) {
try {
EzySession session = request.getSession();
EzyLoginParams params = request.getParams();
EzyZoneContext zoneContext = ctx.getZoneContext(params.getZoneName());
EzyUserLoginEvent loginEvent = newLoginEvent(session, params);
try {
control(ctx, zoneContext, loginEvent);
} finally {
loginEvent.release();
}
} catch (EzyLoginErrorException e) {
processException(ctx, request.getSession(), e);
throw e;
} catch (EzyMaxUserException e) {
processException(ctx, request.getSession(), maximumUsers(e));
throw e;
} catch (EzyZoneNotFoundException e) {
processException(ctx, request.getSession(), zoneNotFound(e));
throw e;
} catch (Exception e) {
processException(ctx, request.getSession(), serverError(e));
throw e;
}
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyRequestAppController method responseRequestAppError.
protected void responseRequestAppError(EzyServerContext ctx, EzySession session) {
EzyResponse response = newRequestAppErrorResponse();
ctx.send(response, session, false);
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyRequestAppController method handle.
@Override
public void handle(EzyServerContext ctx, EzyRequestAppRequest request) {
EzyRequestAppParams params = request.getParams();
EzyAppContext appCtx = ctx.getAppContext(params.getAppId());
EzyApplication app = appCtx.getApp();
EzyAppRequestController requestController = app.getRequestController();
// user manager for checking, user must be managed
EzyUserManager userManger = appCtx.getApp().getUserManager();
EzyUser user = request.getUser();
// check user joined app or not to prevent spam request
boolean hasAccessed = userManger.containsUser(user);
if (hasAccessed) {
// redirect handling to app
EzyUserRequestAppEvent event = newRequestAppEvent(request);
requestController.handle(appCtx, event);
} else {
EzySession session = request.getSession();
responseRequestAppError(ctx, session);
}
}
Aggregations