use of com.tvd12.ezyfoxserver.EzySimpleApplication in project ezyfox-server by youngmonkeys.
the class EzyDefaultAppEntryTest 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);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
appSetting.setName("test");
appSetting.setActiveProfiles("hello,world");
appSetting.setPackageName("x.z.y");
EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
EzySimpleApplication application = new EzySimpleApplication();
application.setSetting(appSetting);
application.setUserManager(appUserManager);
application.setEventControllers(eventControllers);
ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
EzySimpleAppContext appContext = new EzySimpleAppContext();
appContext.setApp(application);
appContext.setParent(zoneContext);
appContext.setExecutorService(appScheduledExecutorService);
appContext.init();
EzySimpleAppEntry entry = new EzyAppEntryEx();
entry.config(appContext);
entry.start();
handleClientRequest(appContext);
entry.destroy();
}
use of com.tvd12.ezyfoxserver.EzySimpleApplication in project ezyfox-server by youngmonkeys.
the class EzyDefaultAppEntryTest method handleClientRequest.
private void handleClientRequest(EzyAppContext context) {
EzySimpleApplication app = (EzySimpleApplication) context.getApp();
EzyAppRequestController requestController = app.getRequestController();
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzySimpleUser user = new EzySimpleUser();
EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
EzyUserRequestAppEvent event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("chat").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("exception").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
try {
requestController.handle(context, event);
} catch (Exception e) {
assert e instanceof IllegalStateException;
}
data = EzyEntityFactory.newArrayBuilder().append("app").build();
event = new EzySimpleUserRequestAppEvent(user, session, data);
requestController.handle(context, event);
}
use of com.tvd12.ezyfoxserver.EzySimpleApplication in project ezyfox-server by youngmonkeys.
the class EzySimpleAppEntryTest method test.
@SuppressWarnings({ "rawtypes" })
@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);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
appSetting.setName("test");
EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
EzySimpleApplication application = new EzySimpleApplication();
application.setSetting(appSetting);
application.setUserManager(appUserManager);
application.setEventControllers(eventControllers);
ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
EzySimpleAppContext appContext = new EzySimpleAppContext();
appContext.setApp(application);
appContext.setParent(zoneContext);
appContext.setExecutorService(appScheduledExecutorService);
appContext.init();
EzySimpleAppEntry entry = new EzyAppEntryEx();
entry.config(appContext);
entry.start();
handleClientRequest(appContext);
List<EzyEventController> serverReadyHandlers = appContext.getApp().getEventControllers().getControllers(EzyEventType.SERVER_READY);
Assert.assertEquals(serverReadyHandlers.size(), 2);
Assert.assertEquals(serverReadyHandlers.get(0).getClass(), ServerReadyEventHandler2.class);
Assert.assertEquals(serverReadyHandlers.get(1).getClass(), ServerReadyEventHandler.class);
List<EzyEventController> loginEventHandlers = appContext.getApp().getEventControllers().getControllers(EzyEventType.USER_LOGIN);
Assert.assertEquals(loginEventHandlers.size(), 1);
Assert.assertEquals(loginEventHandlers.get(0).getClass(), AppUserLoginRequestController.class);
entry.destroy();
}
use of com.tvd12.ezyfoxserver.EzySimpleApplication 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.EzySimpleApplication 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);
}
Aggregations