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);
}
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);
}
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);
}
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);
}
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();
}
Aggregations