Search in sources :

Example 21 with EzySimpleZone

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleZone in project ezyfox-server by youngmonkeys.

the class EzyZonesStarterTest method normalCaseTest.

@Test
public void normalCaseTest() {
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleZonesSetting zonesSetting = settings.getZones();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.setName("test");
    zonesSetting.setItem(zoneSetting);
    EzySimpleAppsSetting appsSetting = new EzySimpleAppsSetting();
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("apps");
    appSetting.setFolder("apps");
    appSetting.setEntryLoader(ExEntryLoader.class.getName());
    appsSetting.setItem(appSetting);
    zoneSetting.setApplications(appsSetting);
    EzySimplePluginsSetting pluginsSetting = new EzySimplePluginsSetting();
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    pluginSetting.setName("plugins");
    pluginSetting.setFolder("plugins");
    pluginSetting.setEntryLoader(ExPluginEntryLoader.class.getName());
    pluginsSetting.setItem(pluginSetting);
    zoneSetting.setPlugins(pluginsSetting);
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    server.setConfig(new EzySimpleConfig());
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getServer()).thenReturn(server);
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(zoneContext.getZone()).thenReturn(zone);
    when(serverContext.getZoneContext("test")).thenReturn(zoneContext);
    EzySimpleApplication app = new EzySimpleApplication();
    app.setSetting(appSetting);
    EzyAppContext appContext = mock(EzyAppContext.class);
    when(appContext.getApp()).thenReturn(app);
    when(zoneContext.getAppContext("apps")).thenReturn(appContext);
    EzySimplePlugin plugin = new EzySimplePlugin();
    plugin.setSetting(pluginSetting);
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    when(zoneContext.getPluginContext("plugins")).thenReturn(pluginContext);
    Map<String, ClassLoader> appClassLoaders = new HashMap<>();
    appClassLoaders.put("apps", new EzyAppClassLoader(new File("test-data"), getClass().getClassLoader()));
    server.setAppClassLoaders(appClassLoaders);
    EzyZonesStarter starter = EzyZonesStarter.builder().serverContext(serverContext).build();
    starter.start();
}
Also used : EzyAppClassLoader(com.tvd12.ezyfoxserver.ccl.EzyAppClassLoader) HashMap(java.util.HashMap) EzyAppClassLoader(com.tvd12.ezyfoxserver.ccl.EzyAppClassLoader) EzySimpleConfig(com.tvd12.ezyfoxserver.config.EzySimpleConfig) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) File(java.io.File) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 22 with EzySimpleZone

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleZone 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 23 with EzySimpleZone

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleZone in project ezyfox-server by youngmonkeys.

the class EzySimplePluginContextTest 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);
    EzySimplePlugin plugin = new EzySimplePlugin();
    EzySimplePluginSetting setting = new EzySimplePluginSetting();
    plugin.setSetting(setting);
    EzySimplePluginContext pluginContext = new EzySimplePluginContext();
    pluginContext.setParent(zoneContext);
    pluginContext.setPlugin(plugin);
    pluginContext.init();
    // noinspection EqualsWithItself
    assert pluginContext.equals(pluginContext);
    EzySimplePluginContext pluginContext2 = new EzySimplePluginContext();
    assert !pluginContext.equals(pluginContext2);
    assert pluginContext.cmd(EzyPluginResponse.class) != null;
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    user.addSession(session);
    EzyData data = EzyEntityFactory.newArrayBuilder().build();
    pluginContext.send(data, session, false);
}
Also used : EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimplePluginContext(com.tvd12.ezyfoxserver.context.EzySimplePluginContext) EzyData(com.tvd12.ezyfox.entity.EzyData) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyPluginResponse(com.tvd12.ezyfoxserver.command.EzyPluginResponse) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 24 with EzySimpleZone

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleZone in project ezyfox-server by youngmonkeys.

the class EzySimpleZoneContextTest method normalCaseTest.

@SuppressWarnings("unchecked")
@Test
public void normalCaseTest() {
    EzyServerContext parent = mock(EzyServerContext.class);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.setName("test");
    EzySimpleZone zone = new EzySimpleZone();
    zone.setUserManager(mock(EzyZoneUserManager.class));
    zone.setSetting(zoneSetting);
    EzySimpleZoneContext context = new EzySimpleZoneContext();
    context.setZone(zone);
    context.setParent(parent);
    context.init();
    assert context.get(EzyBroadcastEvent.class) != null;
    Asserts.assertNull(context.get(Void.class));
    context.addCommand(ExCommand.class, ExCommand::new);
    assert context.cmd(ExCommand.class) != null;
    Asserts.assertNull(context.cmd(Void.class));
    context.broadcast(EzyEventType.SERVER_INITIALIZING, new EzySimpleServerInitializingEvent(), true);
    context.broadcastApps(EzyEventType.SERVER_READY, new EzySimpleServerReadyEvent(), true);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("dungtv");
    EzyUserAccessAppEvent accessAppEvent = new EzySimpleUserAccessAppEvent(user);
    context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, "dungtv", true);
    context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, user, true);
    context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, EzyPredicates.ALWAYS_TRUE, true);
    // noinspection EqualsWithItself
    assert context.equals(context);
    EzyZoneContext zoneContext2 = mock(EzyZoneContext.class);
    EzySimpleZone zone2 = new EzySimpleZone();
    when(zoneContext2.getZone()).thenReturn(zone2);
    assert !zoneContext2.equals(context);
    System.out.println(context.hashCode() + ", " + context.hashCode());
    assert context.hashCode() == context.hashCode();
    EzyResponse response = mock(EzyResponse.class);
    EzySession recipient = spy(EzyAbstractSession.class);
    context.send(response, recipient, false);
    context.send(response, Lists.newArrayList(recipient), false);
    context.stream(new byte[0], recipient);
    context.stream(new byte[0], Lists.newArrayList(recipient));
    context.destroy();
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzyBroadcastEvent(com.tvd12.ezyfoxserver.command.EzyBroadcastEvent) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleServerReadyEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzyUserAccessAppEvent) EzySimpleUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 25 with EzySimpleZone

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleZone in project ezyfox-server by youngmonkeys.

the class EzySimpleZoneContextTest method equalsCaseTest.

@Test
public void equalsCaseTest() {
    EzySimpleZoneContext zoneContext1 = new EzySimpleZoneContext();
    EzySimpleZone zone1 = new EzySimpleZone();
    zoneContext1.setZone(zone1);
    EzySimpleZoneContext zoneContext2 = new EzySimpleZoneContext();
    EzySimpleZone zone2 = new EzySimpleZone();
    zoneContext1.setZone(zone2);
    assert !zoneContext1.equals(zoneContext2);
}
Also used : EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)29 Test (org.testng.annotations.Test)29 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)19 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)16 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)16 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)14 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 BaseTest (com.tvd12.test.base.BaseTest)12 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)11 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)11 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)10 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)10 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)9 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)9 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)8 EzySimpleAppContext (com.tvd12.ezyfoxserver.context.EzySimpleAppContext)8 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)8 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)7 EzySimplePluginContext (com.tvd12.ezyfoxserver.context.EzySimplePluginContext)7