use of com.tvd12.ezyfoxserver.context.EzySimpleAppContext in project ezyfox-server by youngmonkeys.
the class EzySimpleAppContextTest method sendMultiTest.
@Test
public void sendMultiTest() {
// given
EzyData data = mock(EzyData.class);
EzySession recipient = mock(EzySession.class);
List<EzySession> recipients = Collections.singletonList(recipient);
boolean encrypted = RandomUtil.randomBoolean();
EzyAppSendResponse sendResponse = mock(EzyAppSendResponse.class);
doNothing().when(sendResponse).execute(data, recipients, encrypted, EzyTransportType.TCP);
EzySimpleAppContext sut = new EzySimpleAppContext();
FieldUtil.setFieldValue(sut, "sendResponse", sendResponse);
// when
sut.send(data, recipients, encrypted, EzyTransportType.TCP);
// then
verify(sendResponse, times(1)).execute(data, recipients, encrypted, EzyTransportType.TCP);
}
use of com.tvd12.ezyfoxserver.context.EzySimpleAppContext 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.EzySimpleAppContext in project ezyfox-server by youngmonkeys.
the class EzyAppsStarterTest method getClassLoaderErrorCaseTest.
@Test
public void getClassLoaderErrorCaseTest() {
Map<String, ClassLoader> loaders = new ConcurrentHashMap<>();
EzySimpleZoneContext zoneContext = EzyZoneContextsTest.newDefaultZoneContext();
EzySimpleApplication app = new EzySimpleApplication();
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
appSetting.setName("abc");
app.setSetting(appSetting);
EzySimpleAppContext appContext = new EzySimpleAppContext();
appContext.setApp(app);
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
EzySimpleAppsSetting appsSetting = new EzySimpleAppsSetting();
appsSetting.setItem(appSetting);
zoneSetting.setApplications(appsSetting);
zoneContext.addAppContext(appSetting, appContext);
EzyAppsStarter starter = new EzyAppsStarter.Builder().zoneContext(zoneContext).appClassLoaders(loaders).build();
try {
MethodInvoker.create().object(starter).method("getAppClassLoader").param("abc").param("hello").invoke();
} catch (IllegalStateException e) {
e.printStackTrace();
assert e.getCause().getCause() instanceof IllegalArgumentException;
}
}
use of com.tvd12.ezyfoxserver.context.EzySimpleAppContext in project ezyfox-server by youngmonkeys.
the class EzyDefaultAppEntryTest method test2.
@Test
public void test2() throws Exception {
EzySimpleSettings settings = new EzySimpleSettings();
EzySimpleServer server = new EzySimpleServer();
server.setSettings(settings);
EzySimpleServerContext serverContext = new EzySimpleServerContext();
serverContext.setServer(server);
serverContext.init();
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
EzySimpleZone zone = new EzySimpleZone();
zone.setSetting(zoneSetting);
EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
zoneContext.setZone(zone);
zoneContext.init();
zoneContext.setParent(serverContext);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
appSetting.setName("test");
EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
EzySimpleApplication application = new EzySimpleApplication();
application.setSetting(appSetting);
application.setUserManager(appUserManager);
application.setEventControllers(eventControllers);
ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
EzySimpleAppContext appContext = new EzySimpleAppContext();
appContext.setApp(application);
appContext.setParent(zoneContext);
appContext.setExecutorService(appScheduledExecutorService);
appContext.init();
EzySimpleAppEntry entry = new EzyAppEntryEx2();
entry.config(appContext);
entry.start();
entry.destroy();
}
use of com.tvd12.ezyfoxserver.context.EzySimpleAppContext in project ezyfox-server by youngmonkeys.
the class EzySimpleAppEntryTest method test2.
@Test
public void test2() throws Exception {
EzySimpleSettings settings = new EzySimpleSettings();
EzySimpleServer server = new EzySimpleServer();
server.setSettings(settings);
EzySimpleServerContext serverContext = new EzySimpleServerContext();
serverContext.setServer(server);
serverContext.init();
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
EzySimpleZone zone = new EzySimpleZone();
zone.setSetting(zoneSetting);
EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
zoneContext.setZone(zone);
zoneContext.init();
zoneContext.setParent(serverContext);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
appSetting.setName("test");
EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
EzySimpleApplication application = new EzySimpleApplication();
application.setSetting(appSetting);
application.setUserManager(appUserManager);
application.setEventControllers(eventControllers);
ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
EzySimpleAppContext appContext = new EzySimpleAppContext();
appContext.setApp(application);
appContext.setParent(zoneContext);
appContext.setExecutorService(appScheduledExecutorService);
appContext.init();
EzySimpleAppEntry entry = new EzyAppEntryEx2();
entry.config(appContext);
entry.start();
entry.destroy();
}
Aggregations