use of com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting in project ezyfox-server by youngmonkeys.
the class EzySimplePluginContextTest method test.
@Test
public void test() {
EzyServerContext serverContext = mock(EzyServerContext.class);
EzySimpleZone zone = new EzySimpleZone();
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getZone()).thenReturn(zone);
when(zoneContext.getParent()).thenReturn(serverContext);
EzySimplePlugin plugin = new EzySimplePlugin();
EzySimplePluginSetting setting = new EzySimplePluginSetting();
plugin.setSetting(setting);
EzySimplePluginContext pluginContext = new EzySimplePluginContext();
pluginContext.setParent(zoneContext);
pluginContext.setPlugin(plugin);
pluginContext.init();
// noinspection EqualsWithItself
assert pluginContext.equals(pluginContext);
EzySimplePluginContext pluginContext2 = new EzySimplePluginContext();
assert !pluginContext.equals(pluginContext2);
assert pluginContext.cmd(EzyPluginResponse.class) != null;
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
EzyAbstractSession session = spy(EzyAbstractSession.class);
user.addSession(session);
EzyData data = EzyEntityFactory.newArrayBuilder().build();
pluginContext.send(data, session, false);
}
use of com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting in project ezyfox-server by youngmonkeys.
the class EzyPluginHandleExceptionImplTest method handleExceptionWithHandlersButException.
@Test
public void handleExceptionWithHandlersButException() {
// 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);
Exception exception = new IllegalArgumentException("one");
EzyExceptionHandler exceptionHandler = mock(EzyExceptionHandler.class);
RuntimeException ex = new RuntimeException("just test");
doThrow(ex).when(exceptionHandler).handleException(Thread.currentThread(), exception);
plugin.getExceptionHandlers().addExceptionHandler(exceptionHandler);
// when
sut.handle(Thread.currentThread(), exception);
// then
verify(exceptionHandler, times(1)).handleException(Thread.currentThread(), exception);
verify(logger, times(1)).warn("handle exception: {} on plugin: {} error", EzyStrings.exceptionToSimpleString(exception), pluginName, ex);
}
use of com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting in project ezyfox-server by youngmonkeys.
the class EzyPluginHandleExceptionImplTest method handleExceptionWithEmptyHandlers.
@Test
public void handleExceptionWithEmptyHandlers() {
// 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);
// when
Exception exception = new IllegalArgumentException("one");
sut.handle(Thread.currentThread(), exception);
// then
verify(logger, times(1)).info("plugin: {} has no handler for exception:", pluginName, exception);
}
use of com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting in project ezyfox-server by youngmonkeys.
the class EzyPluginsStarterTest method newAppEntryLoaderArgsNotNullTest.
@Test
public void newAppEntryLoaderArgsNotNullTest() {
// given
EzySimpleZoneContext zoneContext = EzyZoneContextsTest.newDefaultZoneContext();
EzySimplePlugin plugin = new EzySimplePlugin();
EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
pluginSetting.setName("abc");
pluginSetting.setEntryLoader(InternalPluginEntryLoader.class);
pluginSetting.setEntryLoaderArgs(new String[] { "Hello" });
plugin.setSetting(pluginSetting);
EzySimplePluginContext pluginContext = new EzySimplePluginContext();
pluginContext.setPlugin(plugin);
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
EzySimplePluginsSetting pluginsSetting = new EzySimplePluginsSetting();
pluginsSetting.setItem(pluginSetting);
zoneSetting.setPlugins(pluginsSetting);
zoneContext.addPluginContext(pluginSetting, pluginContext);
EzySimpleZone zone = new EzySimpleZone();
zone.setSetting(zoneSetting);
zoneContext.setZone(zone);
EzyPluginsStarter starter = new EzyPluginsStarter.Builder().zoneContext(zoneContext).build();
// when
starter.start();
// then
Asserts.assertNotNull(plugin.getEntry());
}
use of com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting in project ezyfox-server by youngmonkeys.
the class EzyDefaultPluginEntryTest method test.
@Test
public void test() throws Exception {
EzySimpleSettings settings = new EzySimpleSettings();
EzySimpleServer server = new EzySimpleServer();
server.setSettings(settings);
EzySimpleServerContext serverContext = new EzySimpleServerContext();
serverContext.setServer(server);
serverContext.init();
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
EzySimpleZone zone = new EzySimpleZone();
zone.setSetting(zoneSetting);
EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
zoneContext.setZone(zone);
zoneContext.init();
zoneContext.setParent(serverContext);
EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
pluginSetting.setName("test");
pluginSetting.setActiveProfiles("hello,world");
pluginSetting.setPackageName("x.z.y");
EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
EzySimplePlugin plugin = new EzySimplePlugin();
plugin.setSetting(pluginSetting);
plugin.setEventControllers(eventControllers);
ScheduledExecutorService pluginScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
EzySimplePluginContext pluginContext = new EzySimplePluginContext();
pluginContext.setPlugin(plugin);
pluginContext.setParent(zoneContext);
pluginContext.setExecutorService(pluginScheduledExecutorService);
pluginContext.init();
EzySimplePluginEntry entry = new EzyPluginEntryEx();
entry.config(pluginContext);
entry.start();
handleClientRequest(pluginContext);
entry.destroy();
}
Aggregations