Search in sources :

Example 1 with EzyPluginRequestController

use of com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController 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 2 with EzyPluginRequestController

use of com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController in project ezyfox-server by youngmonkeys.

the class EzyUserRequestPluginSingletonControllerTest method handleClientRequest.

private void handleClientRequest(EzyPluginContext context) {
    EzySimplePlugin plugin = (EzySimplePlugin) context.getPlugin();
    EzyPluginRequestController requestController = plugin.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("hello").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    EzyUserRequestPluginEvent event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("responseFactoryTest").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("hello2").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("plugin/c_hello").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNotSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("plugin/requestException4").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    try {
        data = EzyEntityFactory.newArrayBuilder().append("exception").build();
        event = new EzySimpleUserRequestPluginEvent(user, session, data);
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
}
Also used : EzySimpleUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestPluginEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)

Example 3 with EzyPluginRequestController

use of com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntry method setPluginRequestController.

private void setPluginRequestController(EzyPluginContext pluginContext, EzyBeanContext beanContext) {
    if (!allowRequest() || getClass().isAnnotationPresent(EzyDisallowRequest.class)) {
        return;
    }
    EzyPluginSetup setup = pluginContext.get(EzyPluginSetup.class);
    EzyPluginRequestController controller = newUserRequestController(beanContext);
    setup.setRequestController(controller);
    Set<String> commands = ((EzyCommandsAware) controller).getCommands();
    pluginContext.setProperty(COMMANDS, commands);
}
Also used : EzyPluginSetup(com.tvd12.ezyfoxserver.command.EzyPluginSetup) EzyCommandsAware(com.tvd12.ezyfoxserver.support.controller.EzyCommandsAware) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyDisallowRequest(com.tvd12.ezyfoxserver.support.annotation.EzyDisallowRequest)

Example 4 with EzyPluginRequestController

use of com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController in project ezyfox-server by youngmonkeys.

the class EzyDefaultPluginEntryTest method handleClientRequest.

private void handleClientRequest(EzyPluginContext context) {
    EzySimplePlugin plugin = (EzySimplePlugin) context.getPlugin();
    EzyPluginRequestController requestController = plugin.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    EzyUserRequestPluginEvent event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("chat").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("exception").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    try {
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
    data = EzyEntityFactory.newArrayBuilder().append("plugin").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
}
Also used : EzySimpleUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestPluginEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)

Example 5 with EzyPluginRequestController

use of com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController in project ezyfox-server by youngmonkeys.

the class EzyRequestPluginControllerTest method test.

@Test
public void test() {
    EzyRequestPluginController controller = new EzyRequestPluginController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    when(zoneContext.getPluginContext(1)).thenReturn(pluginContext);
    EzyPlugin plugin = mock(EzyPlugin.class);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    EzyPluginRequestController requestController = mock(EzyPluginRequestController.class);
    when(plugin.getRequestController()).thenReturn(requestController);
    EzySimpleRequestPluginRequest request = new EzySimpleRequestPluginRequest();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setZoneId(1);
    user.setId(1);
    user.setName("test");
    request.setSession(session);
    request.setUser(user);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(1).append(EzyEntityFactory.newArrayBuilder()).build();
    request.deserializeParams(array);
    controller.handle(serverContext, request);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleRequestPluginRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequestPluginRequest) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyRequestPluginController(com.tvd12.ezyfoxserver.controller.EzyRequestPluginController) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyArray(com.tvd12.ezyfox.entity.EzyArray) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzyPluginRequestController (com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController)7 EzyArray (com.tvd12.ezyfox.entity.EzyArray)4 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)4 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)4 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)4 EzyUserRequestPluginEvent (com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)4 EzySimpleUserRequestPluginEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserRequestPluginEvent)3 EzyPlugin (com.tvd12.ezyfoxserver.EzyPlugin)2 EzyPluginContext (com.tvd12.ezyfoxserver.context.EzyPluginContext)2 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)2 BaseTest (com.tvd12.test.base.BaseTest)2 Test (org.testng.annotations.Test)2 EzyPluginSetup (com.tvd12.ezyfoxserver.command.EzyPluginSetup)1 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)1 EzyRequestPluginController (com.tvd12.ezyfoxserver.controller.EzyRequestPluginController)1 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)1 EzyRequestPluginParams (com.tvd12.ezyfoxserver.request.EzyRequestPluginParams)1 EzySimpleRequestPluginRequest (com.tvd12.ezyfoxserver.request.EzySimpleRequestPluginRequest)1 EzySimplePluginSetting (com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting)1 EzyDisallowRequest (com.tvd12.ezyfoxserver.support.annotation.EzyDisallowRequest)1