Search in sources :

Example 1 with EzyAppHandleExceptionImpl

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

the class EzySimpleAppContext method doInit.

@Override
protected void doInit() {
    EzySetup setup = new EzyAppSetupImpl(app);
    this.sendResponse = new EzyAppSendResponseImpl(this);
    this.properties.put(EzyAppSendResponse.class, sendResponse);
    this.properties.put(EzyHandleException.class, new EzyAppHandleExceptionImpl(app));
    this.properties.put(EzySetup.class, setup);
    this.properties.put(EzyAppSetup.class, setup);
}
Also used : EzyAppHandleExceptionImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppHandleExceptionImpl) EzyAppSetupImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppSetupImpl) EzyAppSendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppSendResponseImpl)

Example 2 with EzyAppHandleExceptionImpl

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

the class EzyAppHandleExceptionImplTest method handleExceptionWithHandlers.

@Test
public void handleExceptionWithHandlers() {
    // given
    EzySimpleApplication app = new EzySimpleApplication();
    EzySimpleAppSetting setting = new EzySimpleAppSetting();
    String appName = RandomUtil.randomShortAlphabetString();
    setting.setName(appName);
    app.setSetting(setting);
    EzyAppHandleExceptionImpl sut = new EzyAppHandleExceptionImpl(app);
    Logger logger = mock(Logger.class);
    FieldUtil.setFieldValue(sut, "logger", logger);
    EzyExceptionHandler exceptionHandler = mock(EzyExceptionHandler.class);
    app.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("app: {} has no handler for exception:", appName, exception);
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyExceptionHandler(com.tvd12.ezyfox.util.EzyExceptionHandler) EzyAppHandleExceptionImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppHandleExceptionImpl) EzyStrings.exceptionToSimpleString(com.tvd12.ezyfox.io.EzyStrings.exceptionToSimpleString) Logger(org.slf4j.Logger) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 3 with EzyAppHandleExceptionImpl

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

the class EzyAppHandleExceptionImplTest method handleExceptionWithHandlersButException.

@Test
public void handleExceptionWithHandlersButException() {
    // given
    EzySimpleApplication app = new EzySimpleApplication();
    EzySimpleAppSetting setting = new EzySimpleAppSetting();
    String appName = RandomUtil.randomShortAlphabetString();
    setting.setName(appName);
    app.setSetting(setting);
    EzyAppHandleExceptionImpl sut = new EzyAppHandleExceptionImpl(app);
    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);
    app.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 app: {} error", exceptionToSimpleString(exception), appName, ex);
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyExceptionHandler(com.tvd12.ezyfox.util.EzyExceptionHandler) EzyAppHandleExceptionImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppHandleExceptionImpl) EzyStrings.exceptionToSimpleString(com.tvd12.ezyfox.io.EzyStrings.exceptionToSimpleString) Logger(org.slf4j.Logger) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 4 with EzyAppHandleExceptionImpl

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

the class EzyAppHandleExceptionImplTest method handleExceptionWithEmptyHandlers.

@Test
public void handleExceptionWithEmptyHandlers() {
    // given
    EzySimpleApplication app = new EzySimpleApplication();
    EzySimpleAppSetting setting = new EzySimpleAppSetting();
    String appName = RandomUtil.randomShortAlphabetString();
    setting.setName(appName);
    app.setSetting(setting);
    EzyAppHandleExceptionImpl sut = new EzyAppHandleExceptionImpl(app);
    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("app: {} has no handler for exception:", appName, exception);
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyAppHandleExceptionImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppHandleExceptionImpl) EzyStrings.exceptionToSimpleString(com.tvd12.ezyfox.io.EzyStrings.exceptionToSimpleString) Logger(org.slf4j.Logger) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Aggregations

EzyAppHandleExceptionImpl (com.tvd12.ezyfoxserver.command.impl.EzyAppHandleExceptionImpl)4 EzyStrings.exceptionToSimpleString (com.tvd12.ezyfox.io.EzyStrings.exceptionToSimpleString)3 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)3 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)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 EzyAppSendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzyAppSendResponseImpl)1 EzyAppSetupImpl (com.tvd12.ezyfoxserver.command.impl.EzyAppSetupImpl)1