use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzyAbstractServerControllerTest method test.
@SuppressWarnings("rawtypes")
@Test
public void test() {
EzySimpleServer server = mock(EzySimpleServer.class);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
ServerController controller = new ServerController();
EzyServerContext serverContext = mock(EzyServerContext.class);
when(serverContext.getZoneContext("example")).thenReturn(zoneContext);
when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
when(serverContext.getAppContext(1)).thenReturn(appContext);
when(zoneContext.getAppContext("abc")).thenReturn(appContext);
when(zoneContext.getAppContext(1)).thenReturn(appContext);
assertEquals(controller.getAppContext(serverContext, 1), appContext);
when(zoneContext.getAppContext("abc")).thenReturn(appContext);
EzyServerControllers controllers = mock(EzyServerControllers.class);
when(server.getControllers()).thenReturn(controllers);
when(serverContext.getServer()).thenReturn(server);
EzyController ctr = mock(EzyController.class);
when(controllers.getController(EzyCommand.APP_ACCESS)).thenReturn(ctr);
assertEquals(controller.getControllers(serverContext), controllers);
assertEquals(controller.getController(serverContext, EzyCommand.APP_ACCESS), ctr);
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzyPluginSetupImplTest method addEventControllerTest.
@SuppressWarnings("rawtypes")
@Test
public void addEventControllerTest() {
// given
EzySimplePlugin plugin = new EzySimplePlugin();
EzyEventControllers eventControllers = mock(EzyEventControllers.class);
plugin.setEventControllers(eventControllers);
EzyPluginSetupImpl sut = new EzyPluginSetupImpl(plugin);
EzyEventController controller = mock(EzyEventController.class);
// when
sut.addEventController(EzyEventType.SERVER_INITIALIZING, controller);
// then
verify(eventControllers, times(1)).addController(EzyEventType.SERVER_INITIALIZING, controller);
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzySimpleApplicationTest method test.
@Test
public void test() {
EzySimpleApplication app = new EzySimpleApplication();
EzySimpleAppSetting setting = new EzySimpleAppSetting();
app.setSetting(setting);
// noinspection EqualsWithItself
assert app.equals(app);
assert !app.equals(new EzySimpleApplication());
EzyAppRequestController controller = mock(EzyAppRequestController.class);
app.setRequestController(controller);
assert app.getRequestController() == controller;
app.destroy();
app.destroy();
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzySimplePluginTest method test.
@Test
public void test() {
EzySimplePlugin plugin = new EzySimplePlugin();
EzySimplePluginSetting setting = new EzySimplePluginSetting();
plugin.setSetting(setting);
// noinspection EqualsWithItself
assert plugin.equals(plugin);
assert !plugin.equals(new EzySimplePlugin());
EzyPluginRequestController controller = mock(EzyPluginRequestController.class);
plugin.setRequestController(controller);
assert plugin.getRequestController() == controller;
plugin.destroy();
plugin.destroy();
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandler method handleRequest.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void handleRequest(EzyConstant cmd, EzyArray data) {
try {
EzyRequest request = newRequest(cmd, data);
try {
EzyInterceptor interceptor = controllers.getInterceptor(cmd);
interceptor.intercept(context, request);
EzyController controller = controllers.getController(cmd);
controller.handle(context, request);
} finally {
request.release();
}
} catch (Exception e) {
if (context != null) {
Throwable throwable = requestHandleException(session, cmd, data, e);
context.handleException(Thread.currentThread(), throwable);
} else {
if (active) {
logger.warn("fatal error, please add an issue to ezyfox-server github " + "with log: {}\nand stacktrace: ", this, e);
} else {
logger.warn("can't handle command: {} and data: {}, this session " + "maybe destroyed (session: {}), error message: {}", cmd, data, session, e.getMessage());
}
}
}
}
Aggregations