Search in sources :

Example 11 with EzySimpleZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting in project ezyfox-server by youngmonkeys.

the class EzyUserRequestPluginSingletonControllerTest method test.

@Test
public void test() 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);
    EzyZoneUserManager zoneUserManager = EzyZoneUserManagerImpl.builder().zoneName("test").build();
    zone.setUserManager(zoneUserManager);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    pluginSetting.setName("test");
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimplePlugin plugin = new EzySimplePlugin();
    plugin.setSetting(pluginSetting);
    plugin.setEventControllers(eventControllers);
    ScheduledExecutorService pluginScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimplePluginContext pluginContext = new EzySimplePluginContext();
    pluginContext.setPlugin(plugin);
    pluginContext.setParent(zoneContext);
    pluginContext.setExecutorService(pluginScheduledExecutorService);
    pluginContext.init();
    EzySimplePluginEntry entry = new EzyPluginEntryEx();
    entry.config(pluginContext);
    entry.start();
    handleClientRequest(pluginContext);
    EzyBeanContext beanContext = pluginContext.get(EzyBeanContext.class);
    EzyRequestCommandManager requestCommandManager = beanContext.getSingleton(EzyRequestCommandManager.class);
    EzyFeatureCommandManager featureCommandManager = beanContext.getSingleton(EzyFeatureCommandManager.class);
    Asserts.assertTrue(requestCommandManager.containsCommand("v1.2.2/hello"));
    Asserts.assertTrue(requestCommandManager.isManagementCommand("v1.2.2/hello"));
    Asserts.assertTrue(requestCommandManager.isPaymentCommand("v1.2.2/hello"));
    Asserts.assertEquals(featureCommandManager.getFeatureByCommand("v1.2.2/hello"), "hello.world");
    entry.destroy();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzySimplePluginContext(com.tvd12.ezyfoxserver.context.EzySimplePluginContext) EzySimplePluginEntry(com.tvd12.ezyfoxserver.support.entry.EzySimplePluginEntry) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 12 with EzySimpleZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting 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();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySimpleAppEntry(com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry) Test(org.testng.annotations.Test)

Example 13 with EzySimpleZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting 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();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySimpleAppEntry(com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry) Test(org.testng.annotations.Test)

Example 14 with EzySimpleZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting in project ezyfox-server by youngmonkeys.

the class EzyZoneSettingBuilderTest method test.

@Test
public void test() {
    EzySimpleAppSetting appSetting = new EzyAppSettingBuilder().configFile("config.properties").entryLoader(TestAppEntryLoader.class).entryLoaderArgs(new String[] { "hello" }).maxUsers(100).name("test").threadPoolSize(3).build();
    EzySimpleAppsSetting appsSetting = new EzySimpleAppsSetting();
    EzySimpleListenEvents listenEvents = new EzySimpleListenEvents();
    EzySimplePluginSetting pluginSetting = new EzyPluginSettingBuilder().configFile("config.properties").entryLoader(TestPluginEntryLoader.class).name("test").threadPoolSize(3).priority(1).listenEvents(listenEvents).addListenEvent(EzyEventType.USER_LOGIN).addListenEvent(EzyEventType.USER_LOGIN.toString()).build();
    EzySimplePluginsSetting pluginsSetting = new EzySimplePluginsSetting();
    EzySimpleStreamingSetting streamingSetting = new EzySimpleStreamingSetting();
    EzySimpleEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzySimpleUserManagementSetting userManagementSetting = new EzyUserManagementSettingBuilder().allowChangeSession(true).allowGuestLogin(true).guestNamePrefix("Guest#").maxSessionPerUser(3).userMaxIdleTimeInSecond(100).userNamePattern("user#name").build();
    EzySimpleZoneSetting setting = new EzyZoneSettingBuilder().configFile("config.properties").maxUsers(1000).name("test").applications(appsSetting).application(appSetting).plugins(pluginsSetting).plugin(pluginSetting).streaming(streamingSetting).eventControllers(eventControllersSetting).userManagement(userManagementSetting).addEventController(EzyEventType.SERVER_READY, HelloZoneServerReadyController.class).build();
    assertEquals(setting.getConfigFile(), "config.properties");
    assertEquals(setting.getMaxUsers(), 1000);
    assertEquals(setting.getName(), "test");
    assertEquals(setting.getApplications(), appsSetting);
    assertEquals(setting.getPlugins(), pluginsSetting);
    assertEquals(setting.getStreaming(), streamingSetting);
    assertEquals(setting.getEventControllers(), eventControllersSetting);
    assertEquals(setting.getUserManagement(), userManagementSetting);
    appSetting = appsSetting.getAppByName("test");
    assertEquals(appSetting.getConfigFile(true), "config.properties");
    assertEquals(appSetting.getEntryLoader(), TestAppEntryLoader.class.getName());
    assertEquals(appSetting.getFolder(), "test");
    assertEquals(appSetting.getMaxUsers(), 100);
    assertEquals(appSetting.getName(), "test");
    assertEquals(appSetting.getThreadPoolSize(), 3);
    assertEquals(appSetting.getConfigFileInput(), "config.properties");
    pluginSetting = pluginsSetting.getPluginByName("test");
    assertEquals(pluginSetting.getConfigFile(true), "config.properties");
    assertEquals(pluginSetting.getEntryLoader(), TestPluginEntryLoader.class.getName());
    assertEquals(pluginSetting.getFolder(), "test");
    assertEquals(pluginSetting.getName(), "test");
    assertEquals(pluginSetting.getThreadPoolSize(), 3);
    assertEquals(pluginSetting.getPriority(), 1);
    assertEquals(pluginSetting.getListenEvents().getEvents().size(), 1);
    userManagementSetting = setting.getUserManagement();
    assertTrue(userManagementSetting.isAllowChangeSession());
    assertTrue(userManagementSetting.isAllowGuestLogin());
    assertEquals(userManagementSetting.getGuestNamePrefix(), "Guest#");
    assertEquals(userManagementSetting.getMaxSessionPerUser(), 3);
    assertEquals(userManagementSetting.getUserMaxIdleTimeInSecond(), 100);
    assertEquals(userManagementSetting.getUserNamePattern(), "user#name");
}
Also used : EzySimpleListenEvents(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting.EzySimpleListenEvents) Test(org.testng.annotations.Test)

Example 15 with EzySimpleZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting in project ezyfox-server by youngmonkeys.

the class EzyLoginControllerTest method testExceptionCase.

@SuppressWarnings("rawtypes")
@Test(expectedExceptions = IllegalStateException.class)
public void testExceptionCase() {
    EzyServerContext ctx = mock(EzyServerContext.class);
    doThrow(new IllegalStateException("server maintain")).when(ctx).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
    EzyStatistics userStats = new EzySimpleStatistics();
    EzySimpleServer server = new EzySimpleServer();
    server.setStatistics(userStats);
    when(ctx.getServer()).thenReturn(server);
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    server.setSessionManager(sessionManager);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(ctx.getZoneContext("example")).thenReturn(zoneContext);
    EzySimpleZone zone = new EzySimpleZone();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zone.setSetting(zoneSetting);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyZoneUserManager zoneUserManager = EzyZoneUserManagerImpl.builder().maxUsers(1).build();
    zone.setUserManager(zoneUserManager);
    EzySession session = newSession();
    session.setToken("abcdef");
    EzyArray data = newLoginData();
    EzyLoginController controller = new EzyLoginController() {

        @Override
        protected void responseLoginError(EzyServerContext ctx, EzySession session, EzyILoginError error) {
        }
    };
    EzySimpleLoginRequest request = new EzySimpleLoginRequest();
    request.deserializeParams(data);
    request.setSession(session);
    controller.handle(ctx, request);
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyILoginError(com.tvd12.ezyfoxserver.constant.EzyILoginError) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)37 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)26 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)25 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)19 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)19 BaseTest (com.tvd12.test.base.BaseTest)18 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)17 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)11 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)10 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)10 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)10 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)10 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)10 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)9 EzySimpleAppContext (com.tvd12.ezyfoxserver.context.EzySimpleAppContext)9 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)9 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)9 EzyZone (com.tvd12.ezyfoxserver.EzyZone)7 EzyLoginProcessor (com.tvd12.ezyfoxserver.controller.EzyLoginProcessor)7 EzySimpleServerReadyEvent (com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent)7