Search in sources :

Example 1 with EzyPluginHandleExceptionImpl

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

use of com.tvd12.ezyfoxserver.command.impl.EzyPluginHandleExceptionImpl 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);
}
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 EzyPluginHandleExceptionImpl

use of com.tvd12.ezyfoxserver.command.impl.EzyPluginHandleExceptionImpl 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);
}
Also used : EzyPluginHandleExceptionImpl(com.tvd12.ezyfoxserver.command.impl.EzyPluginHandleExceptionImpl) 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 4 with EzyPluginHandleExceptionImpl

use of com.tvd12.ezyfoxserver.command.impl.EzyPluginHandleExceptionImpl in project ezyfox-server by youngmonkeys.

the class EzySimplePluginContext method doInit.

@Override
protected void doInit() {
    EzySetup setup = new EzyPluginSetupImpl(plugin);
    this.sendResponse = new EzyPluginSendResponseImpl(this);
    this.properties.put(EzyPluginSendResponse.class, sendResponse);
    this.properties.put(EzyHandleException.class, new EzyPluginHandleExceptionImpl(plugin));
    this.properties.put(EzySetup.class, setup);
    this.properties.put(EzyPluginSetup.class, setup);
}
Also used : EzyPluginHandleExceptionImpl(com.tvd12.ezyfoxserver.command.impl.EzyPluginHandleExceptionImpl) EzyPluginSendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzyPluginSendResponseImpl) EzyPluginSetupImpl(com.tvd12.ezyfoxserver.command.impl.EzyPluginSetupImpl)

Aggregations

EzyPluginHandleExceptionImpl (com.tvd12.ezyfoxserver.command.impl.EzyPluginHandleExceptionImpl)4 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)3 EzySimplePluginSetting (com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting)3 BaseTest (com.tvd12.test.base.BaseTest)3 Logger (org.slf4j.Logger)3 Test (org.testng.annotations.Test)3 EzyExceptionHandler (com.tvd12.ezyfox.util.EzyExceptionHandler)2 EzyPluginSendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzyPluginSendResponseImpl)1 EzyPluginSetupImpl (com.tvd12.ezyfoxserver.command.impl.EzyPluginSetupImpl)1