Search in sources :

Example 1 with Controller

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);
}
Also used : EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) EzyAbstractServerController(com.tvd12.ezyfoxserver.controller.EzyAbstractServerController) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 2 with Controller

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);
}
Also used : EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyPluginSetupImpl(com.tvd12.ezyfoxserver.command.impl.EzyPluginSetupImpl) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyEventController(com.tvd12.ezyfoxserver.controller.EzyEventController) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 3 with 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();
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyAppRequestController(com.tvd12.ezyfoxserver.app.EzyAppRequestController) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 4 with Controller

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();
}
Also used : EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 5 with Controller

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());
            }
        }
    }
}
Also used : EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzyRequest(com.tvd12.ezyfoxserver.request.EzyRequest) EzyInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyInterceptor) EzyRequestHandleException.requestHandleException(com.tvd12.ezyfoxserver.exception.EzyRequestHandleException.requestHandleException)

Aggregations

Test (org.testng.annotations.Test)38 EzyArray (com.tvd12.ezyfox.entity.EzyArray)18 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)14 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)14 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)14 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)12 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)12 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)12 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)11 BaseTest (com.tvd12.test.base.BaseTest)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 GraphQLController (com.tvd12.ezyhttp.server.graphql.controller.GraphQLController)6 GraphQLDataFetcherManager (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager)5 EzySimpleUserManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting)4 EzyZoneSetting (com.tvd12.ezyfoxserver.setting.EzyZoneSetting)4 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)4 GraphQLDataFetcher (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher)4 GraphQLSchemaParser (com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser)4 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)3