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