use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyEmbeddedServerTest method test.
@Test
public void test() throws Exception {
EzyPluginSettingBuilder pluginSettingBuilder = new EzyPluginSettingBuilder().name("test").entryLoader(TestPluginEntryLoader.class);
EzyAppSettingBuilder appSettingBuilder = new EzyAppSettingBuilder().name("test").entryLoader(TestAppEntryLoader.class);
EzyZoneSettingBuilder zoneSettingBuilder = new EzyZoneSettingBuilder().name("test").application(appSettingBuilder.build()).plugin(pluginSettingBuilder.build());
EzySimpleUdpSetting udpSetting = new EzyUdpSettingBuilder().active(true).build();
EzySimpleSettings settings = new EzySettingsBuilder().zone(zoneSettingBuilder.build()).udp(udpSetting).build();
EzyEmbeddedServer server = EzyEmbeddedServer.builder().settings(settings).config(EzySimpleConfig.defaultConfig()).configFile("test-config/config.properties").build();
EzyServerContext serverContext = server.start();
Asserts.assertEquals(serverContext.getServer().getSettings(), settings);
Thread.sleep(2000);
server.stop();
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzySimpleAppEntryTest method scanPackages.
@Test
public void scanPackages() {
// given
EzyAppContext appContext = mock(EzyAppContext.class);
ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyApplication application = mock(EzyApplication.class);
EzyAppUserManager appUserManager = mock(EzyAppUserManager.class);
EzyAppSetup appSetup = mock(EzyAppSetup.class);
EzyAppSetting appSetting = mock(EzyAppSetting.class);
when(application.getSetting()).thenReturn(appSetting);
InternalAppEntry sut = new InternalAppEntry();
// when
when(appContext.get(ScheduledExecutorService.class)).thenReturn(executorService);
when(appContext.getParent()).thenReturn(zoneContext);
when(zoneContext.getParent()).thenReturn(serverContext);
when(appContext.getApp()).thenReturn(application);
when(application.getUserManager()).thenReturn(appUserManager);
when(appContext.get(EzyAppSetup.class)).thenReturn(appSetup);
sut.config(appContext);
// then
EzyBeanContext beanContext = sut.beanContext;
MongoConfig mongoConfig = (MongoConfig) beanContext.getBean(MongoConfig.class);
Set<String> expectedPackages = Sets.newHashSet(EzySupportConstants.DEFAULT_PACKAGE_TO_SCAN, "com.tvd12.ezyfoxserver.support.v120.test.entry");
Asserts.assertEquals(expectedPackages, mongoConfig.packagesToScan);
Singleton singleton = (Singleton) beanContext.getBean(Singleton.class);
Asserts.assertNotNull(singleton);
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzySimplePluginEntryTest method notAllowRequestTest.
@Test
public void notAllowRequestTest() {
// given
EzyPluginContext pluginContext = mock(EzyPluginContext.class);
ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyPluginSetup pluginSetup = mock(EzyPluginSetup.class);
EzyPlugin plugin = mock(EzyPlugin.class);
when(pluginContext.getPlugin()).thenReturn(plugin);
EzyPluginSetting pluginSetting = mock(EzyPluginSetting.class);
when(plugin.getSetting()).thenReturn(pluginSetting);
NotAllowRequestEntry sut = new NotAllowRequestEntry();
// when
when(pluginContext.get(ScheduledExecutorService.class)).thenReturn(executorService);
when(pluginContext.getParent()).thenReturn(zoneContext);
when(zoneContext.getParent()).thenReturn(serverContext);
when(pluginContext.get(EzyPluginSetup.class)).thenReturn(pluginSetup);
sut.config(pluginContext);
// then
verify(pluginContext, times(0)).get(EzyPluginSetup.class);
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyNioServerBootstrapTest method startStreamHandlingLoopHandlersNotActive.
@Test
public void startStreamHandlingLoopHandlersNotActive() {
// given
EzySimpleServer server = new EzySimpleServer();
EzySimpleSettings settings = new EzySimpleSettings();
settings.getStreaming().setEnable(false);
server.setSettings(settings);
EzyServerContext context = mock(EzyServerContext.class);
when(context.getServer()).thenReturn(server);
EzyNioServerBootstrap sut = new EzyNioServerBootstrap();
sut.setContext(context);
// when
MethodUtil.invokeMethod("startStreamHandlingLoopHandlers", sut);
// then
Asserts.assertNull(FieldUtil.getFieldValue(sut, "streamHandlingLoopHandler"));
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyNioServerBootstrapTest method startWebSocketServerBootstrapNotActive.
@Test
public void startWebSocketServerBootstrapNotActive() {
// given
EzySimpleServer server = new EzySimpleServer();
EzySimpleSettings settings = new EzySimpleSettings();
settings.getWebsocket().setActive(false);
server.setSettings(settings);
EzyServerContext context = mock(EzyServerContext.class);
when(context.getServer()).thenReturn(server);
EzyNioServerBootstrap sut = new EzyNioServerBootstrap();
sut.setContext(context);
// when
MethodUtil.invokeMethod("startWebSocketServerBootstrap", sut);
// then
Asserts.assertNull(FieldUtil.getFieldValue(sut, "websocketServerBootstrap"));
}
Aggregations