Search in sources :

Example 26 with EzySimpleAppSetting

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

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

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

Example 29 with EzySimpleAppSetting

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

the class EzyAppSendResponseImplTest method test.

@Test
public void test() {
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyApplication app = mock(EzyApplication.class);
    when(appContext.getApp()).thenReturn(app);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    when(app.getSetting()).thenReturn(appSetting);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(appContext.getParent()).thenReturn(zoneContext);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(zoneContext.getParent()).thenReturn(serverContext);
    EzyAppSendResponseImpl cmd = new EzyAppSendResponseImpl(appContext);
    EzyData data = EzyEntityFactory.newArrayBuilder().build();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    cmd.execute(data, session, false);
    cmd.execute(data, Lists.newArrayList(session), false);
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyAppSendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppSendResponseImpl) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 30 with EzySimpleAppSetting

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

the class EzySimpleServerContextBuilderTest method test.

@SuppressWarnings("rawtypes")
@Test
public void test() {
    EzySimpleServerContextBuilder instance = new EzySimpleServerContextBuilder();
    MethodInvoker.create().object(instance).method("newAppExecutorService").param(EzyAppSetting.class, new EzySimpleAppSetting()).invoke();
    MethodInvoker.create().object(instance).method("newPluginExecutorService").param(EzyPluginSetting.class, new EzySimplePluginSetting()).invoke();
}
Also used : EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleServerContextBuilder(com.tvd12.ezyfoxserver.builder.EzySimpleServerContextBuilder) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)34 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)29 BaseTest (com.tvd12.test.base.BaseTest)25 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)17 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)12 EzySimpleAppContext (com.tvd12.ezyfoxserver.context.EzySimpleAppContext)11 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)11 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)11 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)9 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)9 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)8 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)8 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)6 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)6 EzySimpleAppUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate)6 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)6 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)5 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)5 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)5