Search in sources :

Example 1 with EzySimpleServer

use of com.tvd12.ezyfoxserver.EzySimpleServer 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 EzySimpleServer

use of com.tvd12.ezyfoxserver.EzySimpleServer 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 3 with EzySimpleServer

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

the class EzyAbstractServerBootstrapBuilderTest method test.

@Test
public void test() {
    EzySimpleServer server = newServer();
    MyTestServerBootstrapBuilder builder = (MyTestServerBootstrapBuilder) new MyTestServerBootstrapBuilder().server(server);
    // noinspection ConstantConditions
    Asserts.assertFalse(builder.equals(null));
    EzySslConfigSetting sslConfigSetting = server.getSettings().getWebsocket().getSslConfig();
    MethodInvoker.create().object(builder).method("newSslContext").param(EzySslConfigSetting.class, sslConfigSetting).invoke();
    MethodInvoker.create().object(builder).method("getSettings").invoke();
    MethodInvoker.create().object(builder).method("getSocketSetting").invoke();
    MethodInvoker.create().object(builder).method("getWebsocketSetting").invoke();
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) MyTestServerBootstrapBuilder(com.tvd12.ezyfoxserver.testing.MyTestServerBootstrapBuilder) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 4 with EzySimpleServer

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

the class EzyAbstractServerBootstrapBuilderTest method newSslContextTest.

@Test
public void newSslContextTest() {
    // given
    EzySimpleServer server = newServer();
    EzySimpleWebSocketSetting webSocketSetting = (EzySimpleWebSocketSetting) server.getSettings().getWebsocket();
    webSocketSetting.setSslActive(true);
    MyTestServerBootstrapBuilder builder = (MyTestServerBootstrapBuilder) new MyTestServerBootstrapBuilder().server(server);
    EzySimpleSslConfigSetting setting = new EzySimpleSslConfigSetting();
    // when
    SSLContext sslContext = MethodInvoker.create().object(builder).method("newSslContext").param(EzySslConfigSetting.class, setting).invoke(SSLContext.class);
    Asserts.assertNotNull(sslContext);
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) MyTestServerBootstrapBuilder(com.tvd12.ezyfoxserver.testing.MyTestServerBootstrapBuilder) SSLContext(javax.net.ssl.SSLContext) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 5 with EzySimpleServer

use of com.tvd12.ezyfoxserver.EzySimpleServer 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)

Aggregations

EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)73 Test (org.testng.annotations.Test)67 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)39 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)36 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)25 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)25 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)22 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)21 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)21 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)19 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)19 BaseTest (com.tvd12.test.base.BaseTest)18 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)15 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)14 EzyArray (com.tvd12.ezyfox.entity.EzyArray)13 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)11 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)10 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)10 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)10