Search in sources :

Example 1 with EzyServerContext

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

the class EzyAbstractServerControllerTest method test.

@SuppressWarnings("rawtypes")
@Test
public void test() {
    EzySimpleServer server = mock(EzySimpleServer.class);
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    ServerController controller = new ServerController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getZoneContext("example")).thenReturn(zoneContext);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    when(serverContext.getAppContext(1)).thenReturn(appContext);
    when(zoneContext.getAppContext("abc")).thenReturn(appContext);
    when(zoneContext.getAppContext(1)).thenReturn(appContext);
    assertEquals(controller.getAppContext(serverContext, 1), appContext);
    when(zoneContext.getAppContext("abc")).thenReturn(appContext);
    EzyServerControllers controllers = mock(EzyServerControllers.class);
    when(server.getControllers()).thenReturn(controllers);
    when(serverContext.getServer()).thenReturn(server);
    EzyController ctr = mock(EzyController.class);
    when(controllers.getController(EzyCommand.APP_ACCESS)).thenReturn(ctr);
    assertEquals(controller.getControllers(serverContext), controllers);
    assertEquals(controller.getController(serverContext, EzyCommand.APP_ACCESS), ctr);
}
Also used : EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) EzyAbstractServerController(com.tvd12.ezyfoxserver.controller.EzyAbstractServerController) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 2 with EzyServerContext

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

the class EzyPluginSendResponseImplTest method test.

@Test
public void test() {
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    EzyPlugin plugin = mock(EzyPlugin.class);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    pluginSetting.setName("test");
    when(plugin.getSetting()).thenReturn(pluginSetting);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(pluginContext.getParent()).thenReturn(zoneContext);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(zoneContext.getParent()).thenReturn(serverContext);
    EzyPluginSendResponseImpl cmd = new EzyPluginSendResponseImpl(pluginContext);
    EzyObject data = EzyEntityFactory.newObjectBuilder().build();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    cmd.execute(data, session, false);
    cmd.execute(data, Lists.newArrayList(session), false);
}
Also used : EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPluginSendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzyPluginSendResponseImpl) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyObject(com.tvd12.ezyfox.entity.EzyObject) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 3 with EzyServerContext

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

the class EzyServerBootstrapTest method test.

@SuppressWarnings("rawtypes")
@Test
public void test() throws Exception {
    EzyServerBootstrap bt = new MyTestServerBootstrapBuilder().server(newServer()).build();
    bt.destroy();
    assert MethodInvoker.create().object(bt).method("getServer").invoke() != null;
    assert MethodInvoker.create().object(bt).method("getServerSettings").invoke() != null;
    assert MethodInvoker.create().object(bt).method("getHttpSetting").invoke() != null;
    assert MethodInvoker.create().object(bt).method("getSocketSetting").invoke() != null;
    assert MethodInvoker.create().object(bt).method("getWebSocketSetting").invoke() != null;
    EzyServerBootstrap bootstrap = new EzyServerBootstrap() {

        @Override
        protected void startOtherBootstraps(Runnable callback) {
            callback.run();
        }
    };
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzySimpleServer server = new EzySimpleServer();
    EzySimpleConfig config = new EzySimpleConfig();
    server.setConfig(config);
    when(serverContext.getServer()).thenReturn(server);
    EzySimpleSettings settings = new EzySimpleSettings();
    server.setSettings(settings);
    EzySessionManager sessionManager = new ExEzySimpleSessionManager.Builder().objectFactory(() -> spy(EzyAbstractSession.class)).build();
    server.setSessionManager(sessionManager);
    EzyBootstrap localBootstrap = EzyBootstrap.builder().context(serverContext).build();
    bootstrap.setContext(serverContext);
    bootstrap.setLocalBootstrap(localBootstrap);
    bootstrap.start();
}
Also used : EzySimpleConfig(com.tvd12.ezyfoxserver.config.EzySimpleConfig) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyBootstrap(com.tvd12.ezyfoxserver.EzyBootstrap) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyServerBootstrap(com.tvd12.ezyfoxserver.EzyServerBootstrap) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) Test(org.testng.annotations.Test)

Example 4 with EzyServerContext

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

the class EzyLoginController method responseLoginError.

protected void responseLoginError(EzyServerContext ctx, EzySession session, EzyILoginError error) {
    EzyResponse response = newLoginErrorResponse(error);
    ctx.send(response, session, false);
}
Also used : EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse)

Example 5 with EzyServerContext

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

the class EzyPingController method handle.

@Override
public void handle(EzyServerContext ctx, EzyPingRequest request) {
    EzyResponse response = EzyPongResponse.getInstance();
    EzySession session = request.getSession();
    ctx.send(response, session, false);
}
Also used : EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Aggregations

EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)72 Test (org.testng.annotations.Test)67 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)46 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)25 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)25 BaseTest (com.tvd12.test.base.BaseTest)23 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)22 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)21 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)20 EzyServer (com.tvd12.ezyfoxserver.EzyServer)17 EzySettings (com.tvd12.ezyfoxserver.setting.EzySettings)16 EzyArray (com.tvd12.ezyfox.entity.EzyArray)14 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)14 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)13 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)13 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)12 EzyChannel (com.tvd12.ezyfoxserver.socket.EzyChannel)12 EzyZone (com.tvd12.ezyfoxserver.EzyZone)11 EzyController (com.tvd12.ezyfoxserver.controller.EzyController)11 EzyLoggerSetting (com.tvd12.ezyfoxserver.setting.EzyLoggerSetting)11