Search in sources :

Example 6 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzySimpleServerContextBuilder method newZoneContexts.

protected Collection<EzyZoneContext> newZoneContexts(EzyServerContext parent) {
    Collection<EzyZoneContext> contexts = new ArrayList<>();
    EzySettings settings = EzyServerContexts.getSettings(parent);
    for (Integer zoneId : settings.getZoneIds()) {
        EzyZoneSetting zoneSetting = settings.getZoneById(zoneId);
        EzySimpleZone zone = new EzySimpleZone();
        zone.setSetting(zoneSetting);
        EzyUserDelegate userDelegate = newUserDelegate(parent);
        EzyZoneUserManager userManager = newZoneUserManager(zoneSetting, userDelegate);
        EzyEventControllers eventControllers = newEventControllers(zoneSetting.getEventControllers());
        zone.setUserManager(userManager);
        zone.setEventControllers(eventControllers);
        EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
        zoneContext.setParent(parent);
        zoneContext.setZone(zone);
        zoneContext.addAppContexts(newAppContexts(zoneContext));
        zoneContext.addPluginContexts(newPluginContexts(zoneContext));
        zoneContext.init();
        contexts.add(zoneContext);
        processWithException(((EzyStartable) userManager)::start);
    }
    return contexts;
}
Also used : EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) ArrayList(java.util.ArrayList) EzyUserDelegate(com.tvd12.ezyfoxserver.delegate.EzyUserDelegate) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)

Example 7 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzyUserRequestAppSingletonControllerTest method test.

@Test
public void test() throws Exception {
    EzyRequestHandlerImplementer.setDebug(true);
    EzyExceptionHandlerImplementer.setDebug(true);
    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 EzyAppEntryEx();
    entry.config(appContext);
    entry.start();
    handleClientRequest(appContext);
    EzyBeanContext beanContext = appContext.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.containsCommand("v122/listener/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) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) 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) BaseTest(com.tvd12.test.base.BaseTest)

Example 8 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzyDefaultAppEntryTest 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);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    appSetting.setActiveProfiles("hello,world");
    appSetting.setPackageName("x.z.y");
    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 EzyAppEntryEx();
    entry.config(appContext);
    entry.start();
    handleClientRequest(appContext);
    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 9 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntryTest method test.

@SuppressWarnings({ "rawtypes" })
@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);
    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 EzyAppEntryEx();
    entry.config(appContext);
    entry.start();
    handleClientRequest(appContext);
    List<EzyEventController> serverReadyHandlers = appContext.getApp().getEventControllers().getControllers(EzyEventType.SERVER_READY);
    Assert.assertEquals(serverReadyHandlers.size(), 2);
    Assert.assertEquals(serverReadyHandlers.get(0).getClass(), ServerReadyEventHandler2.class);
    Assert.assertEquals(serverReadyHandlers.get(1).getClass(), ServerReadyEventHandler.class);
    List<EzyEventController> loginEventHandlers = appContext.getApp().getEventControllers().getControllers(EzyEventType.USER_LOGIN);
    Assert.assertEquals(loginEventHandlers.size(), 1);
    Assert.assertEquals(loginEventHandlers.get(0).getClass(), AppUserLoginRequestController.class);
    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) EzyEventController(com.tvd12.ezyfoxserver.controller.EzyEventController) EzySimpleAppEntry(com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry) Test(org.testng.annotations.Test)

Example 10 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzyZoneContextsTest method newDefaultZoneContext.

public static EzySimpleZoneContext newDefaultZoneContext() {
    EzySimpleZoneContext context = new EzySimpleZoneContext();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(new EzySimpleZoneSetting());
    context.setZone(zone);
    return context;
}
Also used : EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)

Aggregations

EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)18 Test (org.testng.annotations.Test)17 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)16 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)11 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)10 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)10 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)10 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)10 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)9 EzySimpleAppContext (com.tvd12.ezyfoxserver.context.EzySimpleAppContext)9 BaseTest (com.tvd12.test.base.BaseTest)9 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)7 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)6 EzySimplePluginContext (com.tvd12.ezyfoxserver.context.EzySimplePluginContext)6 EzySimpleAppEntry (com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry)5 EzySimplePluginEntry (com.tvd12.ezyfoxserver.support.entry.EzySimplePluginEntry)5 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)5 EzyAppsStarter (com.tvd12.ezyfoxserver.EzyAppsStarter)4 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)4 EzySimpleAppsSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppsSetting)4