Search in sources :

Example 1 with EzyPlugin

use of com.tvd12.ezyfoxserver.EzyPlugin 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 2 with EzyPlugin

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

the class EzySimplePluginEntryTest method notAllowRequestTest.

@Test
public void notAllowRequestTest() {
    // given
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyPluginSetup pluginSetup = mock(EzyPluginSetup.class);
    EzyPlugin plugin = mock(EzyPlugin.class);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    EzyPluginSetting pluginSetting = mock(EzyPluginSetting.class);
    when(plugin.getSetting()).thenReturn(pluginSetting);
    NotAllowRequestEntry sut = new NotAllowRequestEntry();
    // when
    when(pluginContext.get(ScheduledExecutorService.class)).thenReturn(executorService);
    when(pluginContext.getParent()).thenReturn(zoneContext);
    when(zoneContext.getParent()).thenReturn(serverContext);
    when(pluginContext.get(EzyPluginSetup.class)).thenReturn(pluginSetup);
    sut.config(pluginContext);
    // then
    verify(pluginContext, times(0)).get(EzyPluginSetup.class);
}
Also used : EzyPluginSetup(com.tvd12.ezyfoxserver.command.EzyPluginSetup) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting) Test(org.testng.annotations.Test)

Example 3 with EzyPlugin

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

the class EzyRequestPluginControllerTest method test.

@Test
public void test() {
    EzyRequestPluginController controller = new EzyRequestPluginController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    when(zoneContext.getPluginContext(1)).thenReturn(pluginContext);
    EzyPlugin plugin = mock(EzyPlugin.class);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    EzyPluginRequestController requestController = mock(EzyPluginRequestController.class);
    when(plugin.getRequestController()).thenReturn(requestController);
    EzySimpleRequestPluginRequest request = new EzySimpleRequestPluginRequest();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setZoneId(1);
    user.setId(1);
    user.setName("test");
    request.setSession(session);
    request.setUser(user);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(1).append(EzyEntityFactory.newArrayBuilder()).build();
    request.deserializeParams(array);
    controller.handle(serverContext, request);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleRequestPluginRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequestPluginRequest) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyRequestPluginController(com.tvd12.ezyfoxserver.controller.EzyRequestPluginController) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyArray(com.tvd12.ezyfox.entity.EzyArray) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 4 with EzyPlugin

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

the class EzyPluginsStarter method startPlugin.

protected void startPlugin(String pluginName) {
    try {
        logger.debug("plugin: {} loading...", pluginName);
        EzyPluginContext context = zoneContext.getPluginContext(pluginName);
        EzyPlugin plugin = context.getPlugin();
        EzyPluginEntry entry = startPlugin(pluginName, newPluginEntryLoader(pluginName));
        ((EzyEntryAware) plugin).setEntry(entry);
        logger.debug("plugin: {} loaded", pluginName);
    } catch (Exception e) {
        logger.error("can not start plugin: {}", pluginName, e);
    }
}
Also used : EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyEntryAware(com.tvd12.ezyfoxserver.ext.EzyEntryAware) EzyPluginEntry(com.tvd12.ezyfoxserver.ext.EzyPluginEntry)

Example 5 with EzyPlugin

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

Aggregations

EzyPluginContext (com.tvd12.ezyfoxserver.context.EzyPluginContext)8 EzyPlugin (com.tvd12.ezyfoxserver.EzyPlugin)7 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)7 Test (org.testng.annotations.Test)6 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)5 EzyPluginSetup (com.tvd12.ezyfoxserver.command.EzyPluginSetup)3 EzyPluginSetting (com.tvd12.ezyfoxserver.setting.EzyPluginSetting)3 BaseTest (com.tvd12.test.base.BaseTest)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)2 EzyPluginRequestController (com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController)2 EzySimplePluginSetting (com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting)2 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 EzySingleton (com.tvd12.ezyfox.bean.annotation.EzySingleton)1 EzyArray (com.tvd12.ezyfox.entity.EzyArray)1 EzyObject (com.tvd12.ezyfox.entity.EzyObject)1 EzyZone (com.tvd12.ezyfoxserver.EzyZone)1 EzyBroadcastPluginsEventImpl (com.tvd12.ezyfoxserver.command.impl.EzyBroadcastPluginsEventImpl)1 EzyPluginSendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzyPluginSendResponseImpl)1 EzyRequestPluginController (com.tvd12.ezyfoxserver.controller.EzyRequestPluginController)1