Search in sources :

Example 16 with EzyZone

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

the class EzySimpleDataHandlerTest method notifyAppsSessionRemoved0Case.

@SuppressWarnings({ "rawtypes" })
@Test
public void notifyAppsSessionRemoved0Case() {
    int zoneId = 1;
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyZoneUserManager zoneUserManager = mock(EzyZoneUserManager.class);
    when(zone.getUserManager()).thenReturn(zoneUserManager);
    when(serverContext.getZoneContext(zoneId)).thenReturn(zoneContext);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzyChannel channel = mock(EzyChannel.class);
    when(session.getChannel()).thenReturn(channel);
    EzyServer server = mock(EzyServer.class);
    when(serverContext.getServer()).thenReturn(server);
    EzyServerControllers controllers = mock(EzyServerControllers.class);
    EzyInterceptor streamingInterceptor = mock(EzyInterceptor.class);
    when(controllers.getStreamingInterceptor()).thenReturn(streamingInterceptor);
    EzyStreamingController streamingController = mock(EzyStreamingController.class);
    when(controllers.getStreamingController()).thenReturn(streamingController);
    EzyInterceptor loginInterceptor = mock(EzyInterceptor.class);
    when(controllers.getInterceptor(EzyCommand.LOGIN)).thenReturn(loginInterceptor);
    EzyController loginController = mock(EzyController.class);
    when(controllers.getController(EzyCommand.LOGIN)).thenReturn(loginController);
    when(server.getControllers()).thenReturn(controllers);
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    when(server.getSessionManager()).thenReturn(sessionManager);
    EzyCloseSession closeSession = mock(EzyCloseSession.class);
    when(serverContext.get(EzyCloseSession.class)).thenReturn(closeSession);
    EzySettings settings = mock(EzySettings.class);
    when(settings.isDebug()).thenReturn(true);
    when(server.getSettings()).thenReturn(settings);
    EzySessionManagementSetting sessionManagementSetting = mock(EzySessionManagementSetting.class);
    when(settings.getSessionManagement()).thenReturn(sessionManagementSetting);
    EzyLoggerSetting loggerSetting = mock(EzyLoggerSetting.class);
    when(settings.getLogger()).thenReturn(loggerSetting);
    EzyLoggerSetting.EzyIgnoredCommandsSetting ignoredCommandsSetting = mock(EzyLoggerSetting.EzyIgnoredCommandsSetting.class);
    when(loggerSetting.getIgnoredCommands()).thenReturn(ignoredCommandsSetting);
    when(ignoredCommandsSetting.getCommands()).thenReturn(new HashSet<>());
    EzySessionManagementSetting.EzyMaxRequestPerSecond maxRequestPerSecond = mock(EzySessionManagementSetting.EzyMaxRequestPerSecond.class);
    when(maxRequestPerSecond.getValue()).thenReturn(3);
    when(maxRequestPerSecond.getAction()).thenReturn(EzyMaxRequestPerSecondAction.DISCONNECT_SESSION);
    when(sessionManagementSetting.getSessionMaxRequestPerSecond()).thenReturn(maxRequestPerSecond);
    MyTestDataHandler handler = new MyTestDataHandler(serverContext, session);
    when(session.getDelegate()).thenReturn(handler);
    when(session.isActivated()).thenReturn(true);
    FieldUtil.setFieldValue(handler, "zoneContext", zoneContext);
    doThrow(new IllegalArgumentException("notifyAppsSessionRemoved0Case")).when(zoneContext).broadcastApps(any(EzyConstant.class), any(EzyEvent.class), any(EzyUser.class), anyBoolean());
    MethodInvoker.create().object(handler).method("doNotifyAppsSessionRemoved").param(EzyEvent.class, mock(EzyEvent.class)).invoke();
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyChannel(com.tvd12.ezyfoxserver.socket.EzyChannel) EzyInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyInterceptor) EzyStreamingController(com.tvd12.ezyfoxserver.controller.EzyStreamingController) EzyCloseSession(com.tvd12.ezyfoxserver.command.EzyCloseSession) EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzySessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySessionManagementSetting) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) EzyLoggerSetting(com.tvd12.ezyfoxserver.setting.EzyLoggerSetting) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 17 with EzyZone

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

the class EzyBroadcastPluginsEventImplTest method firePluginEventExceptionCase.

@Test
public void firePluginEventExceptionCase() {
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzySimpleZoneSetting setting = new EzySimpleZoneSetting();
    setting.setName("test");
    when(zone.getSetting()).thenReturn(setting);
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    EzyPlugin plugin = mock(EzyPlugin.class);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    when(plugin.getSetting()).thenReturn(pluginSetting);
    EzySimpleListenEvents listenEvents = pluginSetting.getListenEvents();
    listenEvents.setEvent("SERVER_READY");
    doThrow(new IllegalStateException("server maintain")).when(pluginContext).handleEvent(any(), any());
    when(zoneContext.getPluginContexts()).thenReturn(Lists.newArrayList(pluginContext));
    EzyBroadcastPluginsEventImpl cmd = new EzyBroadcastPluginsEventImpl(zoneContext);
    EzyServerReadyEvent event = new EzySimpleServerReadyEvent();
    cmd.fire(EzyEventType.SERVER_READY, event, true);
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleListenEvents(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting.EzySimpleListenEvents) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyBroadcastPluginsEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyBroadcastPluginsEventImpl) EzySimpleServerReadyEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyServerReadyEvent(com.tvd12.ezyfoxserver.event.EzyServerReadyEvent) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 18 with EzyZone

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

the class EzyBroadcastPluginsEventImplTest method pluginContextsNullCaseTest.

@Test
public void pluginContextsNullCaseTest() {
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzySimpleZoneSetting setting = new EzySimpleZoneSetting();
    setting.setName("test");
    when(zone.getSetting()).thenReturn(setting);
    EzyBroadcastPluginsEventImpl cmd = new EzyBroadcastPluginsEventImpl(zoneContext);
    EzyServerReadyEvent event = new EzySimpleServerReadyEvent();
    cmd.fire(EzyEventType.SERVER_READY, event, true);
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBroadcastPluginsEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyBroadcastPluginsEventImpl) EzySimpleServerReadyEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyServerReadyEvent(com.tvd12.ezyfoxserver.event.EzyServerReadyEvent) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 19 with EzyZone

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

the class EzyZoneBroadcastEventImplTest method firePluginEventNoCatchExceptionCaseTest.

@Test
public void firePluginEventNoCatchExceptionCaseTest() {
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzySimpleZoneSetting setting = new EzySimpleZoneSetting();
    setting.setName("test");
    when(zone.getSetting()).thenReturn(setting);
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    when(zoneContext.getPluginContexts()).thenReturn(Lists.newArrayList(pluginContext));
    EzyZoneBroadcastEventImpl cmd = new EzyZoneBroadcastEventImpl(zoneContext);
    EzyServerReadyEvent event = new EzySimpleServerReadyEvent();
    cmd.fire(EzyEventType.SERVER_READY, event, false);
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyZoneBroadcastEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyZoneBroadcastEventImpl) EzySimpleServerReadyEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyServerReadyEvent(com.tvd12.ezyfoxserver.event.EzyServerReadyEvent) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 20 with EzyZone

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

the class EzyZoneBroadcastEventImplTest method fireAppEventCatchExceptionCaseTest.

@Test
public void fireAppEventCatchExceptionCaseTest() {
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzySimpleZoneSetting setting = new EzySimpleZoneSetting();
    setting.setName("test");
    when(zone.getSetting()).thenReturn(setting);
    EzyAppContext appContext = mock(EzyAppContext.class);
    when(zoneContext.getAppContexts()).thenReturn(Lists.newArrayList(appContext));
    doThrow(new IllegalStateException("server maintain")).when(appContext).handleEvent(any(), any());
    EzyZoneBroadcastEventImpl cmd = new EzyZoneBroadcastEventImpl(zoneContext);
    EzyServerReadyEvent event = new EzySimpleServerReadyEvent();
    cmd.fire(EzyEventType.SERVER_READY, event, true);
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneBroadcastEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyZoneBroadcastEventImpl) EzySimpleServerReadyEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyServerReadyEvent(com.tvd12.ezyfoxserver.event.EzyServerReadyEvent) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzyZone (com.tvd12.ezyfoxserver.EzyZone)21 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)20 Test (org.testng.annotations.Test)18 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)13 EzyServer (com.tvd12.ezyfoxserver.EzyServer)11 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)11 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)11 EzyCloseSession (com.tvd12.ezyfoxserver.command.EzyCloseSession)10 EzyController (com.tvd12.ezyfoxserver.controller.EzyController)10 EzyStreamingController (com.tvd12.ezyfoxserver.controller.EzyStreamingController)10 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)10 EzyInterceptor (com.tvd12.ezyfoxserver.interceptor.EzyInterceptor)10 EzyLoggerSetting (com.tvd12.ezyfoxserver.setting.EzyLoggerSetting)10 EzySessionManagementSetting (com.tvd12.ezyfoxserver.setting.EzySessionManagementSetting)10 EzySettings (com.tvd12.ezyfoxserver.setting.EzySettings)10 EzyChannel (com.tvd12.ezyfoxserver.socket.EzyChannel)10 EzyServerControllers (com.tvd12.ezyfoxserver.wrapper.EzyServerControllers)10 BaseTest (com.tvd12.test.base.BaseTest)9 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8 EzyServerReadyEvent (com.tvd12.ezyfoxserver.event.EzyServerReadyEvent)6