use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext in project ezyfox-server by youngmonkeys.
the class EzySimpleServerContextTest method test.
@Test
public void test() {
EzySimpleServerContext ctx = context;
EzySimpleAppContext appContext = new EzySimpleAppContext();
EzySimpleApplication app = new EzySimpleApplication();
EzyZoneContext zoneContext = ctx.getZoneContexts().get(0);
appContext.setParent(zoneContext);
appContext.setApp(app);
appContext.init();
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
appSetting.setName("abcxyz");
ctx.addAppContext(appSetting, appContext);
assert ctx.getAppContext(appSetting.getId()) != null;
context.setProperty("test.1", "abc");
assert context.getProperty("test.1") != null;
assert appContext.getProperty("test.1") == null;
appContext.setProperty("test.2", "abc");
assert context.getProperty("test.2") == null;
assert appContext.getProperty("test.2") != null;
EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
pluginSetting.setName("plugin.1");
EzySimplePluginContext pluginContext = new EzySimplePluginContext();
EzySimplePlugin plugin = new EzySimplePlugin();
pluginContext.setParent(zoneContext);
pluginContext.setPlugin(plugin);
pluginContext.init();
ctx.addPluginContext(pluginSetting, pluginContext);
assert ctx.getPluginContext(pluginSetting.getId()) != null;
context.setProperty("test.1", "abc");
assert context.getProperty("test.1") != null;
assert pluginContext.getProperty("test.1") == null;
pluginContext.setProperty("test.2", "abc");
assert context.getProperty("test.2") == null;
assert pluginContext.getProperty("test.2") != null;
assert context.get(EzyBroadcastEvent.class) != null;
context.addCommand(ExCommand.class, ExCommand::new);
assert context.cmd(ExCommand.class) != null;
try {
context.cmd(Void.class);
} catch (Exception e) {
assert e instanceof IllegalArgumentException;
}
EzyServerReadyEvent serverReadyEvent = new EzySimpleServerReadyEvent();
context.broadcast(EzyEventType.SERVER_READY, serverReadyEvent, true);
EzySimpleServer server = (EzySimpleServer) context.getServer();
server.setResponseApi(mock(EzyResponseApi.class));
server.setStreamingApi(mock(EzyStreamingApi.class));
EzyResponse response = mock(EzyResponse.class);
EzySession recipient = spy(EzyAbstractSession.class);
context.send(response, recipient, false);
context.stream(new byte[0], recipient);
context.stream(new byte[0], Lists.newArrayList(recipient));
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
user.addSession(recipient);
context.send(response, user, false);
assert context.getZoneContext(zoneContext.getZone().getSetting().getId()) != null;
try {
context.getZoneContext(-1);
} catch (Exception e) {
assert e instanceof EzyZoneNotFoundException;
}
try {
context.getZoneContext("not found");
} catch (Exception e) {
assert e instanceof EzyZoneNotFoundException;
}
context.destroy();
}
use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext 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);
}
use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext 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);
}
use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext 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);
}
use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext 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);
}
Aggregations