Search in sources :

Example 1 with EzySimpleApplication

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

the class EzySimpleServerContextTest method test.

@Test
public void test() {
    EzySimpleServerContext ctx = context;
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    EzySimpleApplication app = new EzySimpleApplication();
    EzyZoneContext zoneContext = ctx.getZoneContexts().get(0);
    appContext.setParent(zoneContext);
    appContext.setApp(app);
    appContext.init();
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("abcxyz");
    ctx.addAppContext(appSetting, appContext);
    assert ctx.getAppContext(appSetting.getId()) != null;
    context.setProperty("test.1", "abc");
    assert context.getProperty("test.1") != null;
    assert appContext.getProperty("test.1") == null;
    appContext.setProperty("test.2", "abc");
    assert context.getProperty("test.2") == null;
    assert appContext.getProperty("test.2") != null;
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    pluginSetting.setName("plugin.1");
    EzySimplePluginContext pluginContext = new EzySimplePluginContext();
    EzySimplePlugin plugin = new EzySimplePlugin();
    pluginContext.setParent(zoneContext);
    pluginContext.setPlugin(plugin);
    pluginContext.init();
    ctx.addPluginContext(pluginSetting, pluginContext);
    assert ctx.getPluginContext(pluginSetting.getId()) != null;
    context.setProperty("test.1", "abc");
    assert context.getProperty("test.1") != null;
    assert pluginContext.getProperty("test.1") == null;
    pluginContext.setProperty("test.2", "abc");
    assert context.getProperty("test.2") == null;
    assert pluginContext.getProperty("test.2") != null;
    assert context.get(EzyBroadcastEvent.class) != null;
    context.addCommand(ExCommand.class, ExCommand::new);
    assert context.cmd(ExCommand.class) != null;
    try {
        context.cmd(Void.class);
    } catch (Exception e) {
        assert e instanceof IllegalArgumentException;
    }
    EzyServerReadyEvent serverReadyEvent = new EzySimpleServerReadyEvent();
    context.broadcast(EzyEventType.SERVER_READY, serverReadyEvent, true);
    EzySimpleServer server = (EzySimpleServer) context.getServer();
    server.setResponseApi(mock(EzyResponseApi.class));
    server.setStreamingApi(mock(EzyStreamingApi.class));
    EzyResponse response = mock(EzyResponse.class);
    EzySession recipient = spy(EzyAbstractSession.class);
    context.send(response, recipient, false);
    context.stream(new byte[0], recipient);
    context.stream(new byte[0], Lists.newArrayList(recipient));
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    user.addSession(recipient);
    context.send(response, user, false);
    assert context.getZoneContext(zoneContext.getZone().getSetting().getId()) != null;
    try {
        context.getZoneContext(-1);
    } catch (Exception e) {
        assert e instanceof EzyZoneNotFoundException;
    }
    try {
        context.getZoneContext("not found");
    } catch (Exception e) {
        assert e instanceof EzyZoneNotFoundException;
    }
    context.destroy();
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzyServerReadyEvent(com.tvd12.ezyfoxserver.event.EzyServerReadyEvent) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException) EzyBroadcastEvent(com.tvd12.ezyfoxserver.command.EzyBroadcastEvent) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException) EzySimplePluginContext(com.tvd12.ezyfoxserver.context.EzySimplePluginContext) EzySimpleServerReadyEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 2 with EzySimpleApplication

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

the class EzySimpleApplicationTest method test.

@Test
public void test() {
    EzySimpleApplication app = new EzySimpleApplication();
    EzySimpleAppSetting setting = new EzySimpleAppSetting();
    app.setSetting(setting);
    // noinspection EqualsWithItself
    assert app.equals(app);
    assert !app.equals(new EzySimpleApplication());
    EzyAppRequestController controller = mock(EzyAppRequestController.class);
    app.setRequestController(controller);
    assert app.getRequestController() == controller;
    app.destroy();
    app.destroy();
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyAppRequestController(com.tvd12.ezyfoxserver.app.EzyAppRequestController) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 3 with EzySimpleApplication

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

the class EzyAppsStarterTest method getClassLoaderErrorCaseTest.

@Test
public void getClassLoaderErrorCaseTest() {
    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();
    try {
        MethodInvoker.create().object(starter).method("getAppClassLoader").param("abc").param("hello").invoke();
    } catch (IllegalStateException e) {
        e.printStackTrace();
        assert e.getCause().getCause() instanceof IllegalArgumentException;
    }
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyAppsStarter(com.tvd12.ezyfoxserver.EzyAppsStarter) 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 4 with EzySimpleApplication

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

the class EzyRequestAppControllerTest method newServerContext.

@Override
protected EzyServerContext newServerContext() {
    session = newSession();
    session.setToken("abc");
    user = new MyTestUser();
    user.setName("dungtv");
    user.addSession(session);
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzySimpleApplication app = new EzySimpleApplication();
    app.setSetting(new EzySimpleAppSetting());
    app.setUserManager(EzyAppUserManagerImpl.builder().build());
    app.getUserManager().addUser(user);
    when(appContext.getApp()).thenReturn(app);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getAppContext(1)).thenReturn(appContext);
    return serverContext;
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) MyTestUser(com.tvd12.ezyfoxserver.testing.MyTestUser) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext)

Example 5 with EzySimpleApplication

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

the class EzyUserRequestAppSingletonControllerTest method handleClientRequest.

private void handleClientRequest(EzyAppContext context) {
    EzySimpleApplication app = (EzySimpleApplication) context.getApp();
    EzyAppRequestController requestController = app.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("hello").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    EzyUserRequestAppEvent event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("responseFactoryTest").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("hello2").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("hello6").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("c_hello").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNotSend").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("requestException").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    try {
        data = EzyEntityFactory.newArrayBuilder().append("requestException2").build();
        event = new EzySimpleUserRequestAppEvent(user, session, data);
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e.getCause().getClass() == Exception.class;
    }
    data = EzyEntityFactory.newArrayBuilder().append("requestException3").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    try {
        data = EzyEntityFactory.newArrayBuilder().append("exception").build();
        event = new EzySimpleUserRequestAppEvent(user, session, data);
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
}
Also used : EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestAppEvent) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyAppRequestController(com.tvd12.ezyfoxserver.app.EzyAppRequestController) EzyUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent)

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