use of com.tvd12.ezyfoxserver.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.
the class EzyDefaultAppEntryTest method handleClientRequest.
private void handleClientRequest(EzyAppContext context) {
EzySimpleApplication app = (EzySimpleApplication) context.getApp();
EzyAppRequestController requestController = app.getRequestController();
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzySimpleUser user = new EzySimpleUser();
EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
EzyUserRequestAppEvent event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("chat").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("exception").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
try {
requestController.handle(context, event);
} catch (Exception e) {
assert e instanceof IllegalStateException;
}
data = EzyEntityFactory.newArrayBuilder().append("app").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
}
use of com.tvd12.ezyfoxserver.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.
the class EzyServerContextsTest method test.
@Test
public void test() {
EzySimpleApplication app = new EzySimpleApplication();
app.setUserManager(EzyAppUserManagerImpl.builder().maxUsers(1).appName("test").build());
EzyAppContext appContext = mock(EzyAppContext.class);
when(appContext.getApp()).thenReturn(app);
EzySimpleUser user = new EzySimpleUser();
assert !EzyServerContexts.containsUser(appContext, user);
assert !EzyServerContexts.containsUser(appContext, "test");
assert EzyServerContexts.getUserManager(appContext) != null;
}
use of com.tvd12.ezyfoxserver.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.
the class EzySimpleAppContextTest method test.
@Test
public void test() {
EzyServerContext serverContext = mock(EzyServerContext.class);
EzySimpleZone zone = new EzySimpleZone();
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getZone()).thenReturn(zone);
when(zoneContext.getParent()).thenReturn(serverContext);
EzySimpleApplication app = new EzySimpleApplication();
EzySimpleAppSetting setting = new EzySimpleAppSetting();
app.setSetting(setting);
EzySimpleAppContext appContext = new EzySimpleAppContext();
appContext.setParent(zoneContext);
appContext.setApp(app);
appContext.init();
Asserts.assertNull(appContext.get(Void.class));
// noinspection EqualsWithItself
assert appContext.equals(appContext);
EzySimpleAppContext appContext2 = new EzySimpleAppContext();
assert !appContext.equals(appContext2);
assert appContext.cmd(EzyAppResponse.class) != null;
Asserts.assertNull(appContext.cmd(Void.class));
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
EzyAbstractSession session = spy(EzyAbstractSession.class);
user.addSession(session);
EzyData data = EzyEntityFactory.newArrayBuilder().build();
appContext.send(data, session, false);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
appContext.setExecutorService(executorService);
assert appContext.getExecutorService() != null;
appContext.handleException(Thread.currentThread(), new Exception());
}
use of com.tvd12.ezyfoxserver.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.
the class EzySimplePluginContextTest method test.
@Test
public void test() {
EzyServerContext serverContext = mock(EzyServerContext.class);
EzySimpleZone zone = new EzySimpleZone();
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getZone()).thenReturn(zone);
when(zoneContext.getParent()).thenReturn(serverContext);
EzySimplePlugin plugin = new EzySimplePlugin();
EzySimplePluginSetting setting = new EzySimplePluginSetting();
plugin.setSetting(setting);
EzySimplePluginContext pluginContext = new EzySimplePluginContext();
pluginContext.setParent(zoneContext);
pluginContext.setPlugin(plugin);
pluginContext.init();
// noinspection EqualsWithItself
assert pluginContext.equals(pluginContext);
EzySimplePluginContext pluginContext2 = new EzySimplePluginContext();
assert !pluginContext.equals(pluginContext2);
assert pluginContext.cmd(EzyPluginResponse.class) != null;
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
EzyAbstractSession session = spy(EzyAbstractSession.class);
user.addSession(session);
EzyData data = EzyEntityFactory.newArrayBuilder().build();
pluginContext.send(data, session, false);
}
use of com.tvd12.ezyfoxserver.entity.EzySimpleUser 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();
}
Aggregations