Search in sources :

Example 1 with EzySimplePluginSetting

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

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

the class EzyPluginHandleExceptionImplTest method handleExceptionWithHandlers.

@Test
public void handleExceptionWithHandlers() {
    // given
    EzySimplePlugin plugin = new EzySimplePlugin();
    EzySimplePluginSetting setting = new EzySimplePluginSetting();
    String pluginName = RandomUtil.randomShortAlphabetString();
    setting.setName(pluginName);
    plugin.setSetting(setting);
    EzyPluginHandleExceptionImpl sut = new EzyPluginHandleExceptionImpl(plugin);
    Logger logger = mock(Logger.class);
    FieldUtil.setFieldValue(sut, "logger", logger);
    EzyExceptionHandler exceptionHandler = mock(EzyExceptionHandler.class);
    plugin.getExceptionHandlers().addExceptionHandler(exceptionHandler);
    // when
    Exception exception = new IllegalArgumentException("one");
    sut.handle(Thread.currentThread(), exception);
    // then
    verify(exceptionHandler, times(1)).handleException(Thread.currentThread(), exception);
    verify(logger, times(0)).info("plugin: {} has no handler for exception:", pluginName, exception);
}
Also used : EzyPluginHandleExceptionImpl(com.tvd12.ezyfoxserver.command.impl.EzyPluginHandleExceptionImpl) EzyExceptionHandler(com.tvd12.ezyfox.util.EzyExceptionHandler) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) Logger(org.slf4j.Logger) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 3 with EzySimplePluginSetting

use of com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting 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 4 with EzySimplePluginSetting

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

the class EzySimplePluginTest method test.

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

Example 5 with EzySimplePluginSetting

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

the class EzyPluginTest method test.

@Test
public void test() {
    EzySimplePluginSetting plugin = new EzySimplePluginSetting();
    plugin.setPriority(10);
}
Also used : EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)21 EzySimplePluginSetting (com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting)14 BaseTest (com.tvd12.test.base.BaseTest)14 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)13 EzySimplePluginContext (com.tvd12.ezyfoxserver.context.EzySimplePluginContext)8 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)7 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)6 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)6 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)6 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)6 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)5 EzySimplePluginEntry (com.tvd12.ezyfoxserver.support.entry.EzySimplePluginEntry)5 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 EzyPluginContext (com.tvd12.ezyfoxserver.context.EzyPluginContext)4 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)4 EzyPluginHandleExceptionImpl (com.tvd12.ezyfoxserver.command.impl.EzyPluginHandleExceptionImpl)3 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)3 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)3 EzySimpleListenEvents (com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting.EzySimpleListenEvents)3