Search in sources :

Example 21 with EzySimpleApplication

use of com.tvd12.ezyfoxserver.EzySimpleApplication 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());
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyData(com.tvd12.ezyfox.entity.EzyData) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzyAppResponse(com.tvd12.ezyfoxserver.command.EzyAppResponse) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 22 with EzySimpleApplication

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

the class EzyAppsStarterTest method newAppEntryLoaderClassLoaderIsNull.

@Test
public void newAppEntryLoaderClassLoaderIsNull() {
    // given
    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);
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    zoneContext.setZone(zone);
    EzyAppsStarter starter = new EzyAppsStarter.Builder().zoneContext(zoneContext).appClassLoaders(loaders).enableAppClassLoader(true).build();
    // when
    starter.start();
    // then
    Asserts.assertNull(app.getEntry());
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyAppsStarter(com.tvd12.ezyfoxserver.EzyAppsStarter) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleAppsSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppsSetting) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 23 with EzySimpleApplication

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

the class EzyAppsStarterTest method newAppEntryLoaderArgsNotNullTest.

@Test
public void newAppEntryLoaderArgsNotNullTest() {
    // given
    Map<String, ClassLoader> loaders = new ConcurrentHashMap<>();
    EzySimpleZoneContext zoneContext = EzyZoneContextsTest.newDefaultZoneContext();
    EzySimpleApplication app = new EzySimpleApplication();
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("abc");
    appSetting.setEntryLoader(InternalAppEntryLoader.class);
    appSetting.setEntryLoaderArgs(new String[] { "Hello" });
    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);
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    zoneContext.setZone(zone);
    EzyAppsStarter starter = new EzyAppsStarter.Builder().zoneContext(zoneContext).appClassLoaders(loaders).enableAppClassLoader(false).classLoader(Thread.currentThread().getContextClassLoader()).build();
    // when
    starter.start();
    // then
    Asserts.assertNotNull(app.getEntry());
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyAppsStarter(com.tvd12.ezyfoxserver.EzyAppsStarter) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleAppsSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppsSetting) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 24 with EzySimpleApplication

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

the class EzyAppsStarterTest method test2.

@Test
public void test2() {
    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();
    starter.start();
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimpleAppsSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppsSetting) EzyAppsStarter(com.tvd12.ezyfoxserver.EzyAppsStarter) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)22 Test (org.testng.annotations.Test)19 BaseTest (com.tvd12.test.base.BaseTest)13 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)12 EzySimpleAppContext (com.tvd12.ezyfoxserver.context.EzySimpleAppContext)11 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)9 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)8 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)7 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)6 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)6 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)6 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)6 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)6 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)5 EzySimpleAppEntry (com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry)5 EzyAppsStarter (com.tvd12.ezyfoxserver.EzyAppsStarter)4 EzyAppRequestController (com.tvd12.ezyfoxserver.app.EzyAppRequestController)4 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)4 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)4 EzySimpleAppsSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppsSetting)4