use of com.tvd12.ezyfoxserver.context.EzyPluginContext in project ezyfox-server by youngmonkeys.
the class EzyPluginInfoControllerTest method test.
@Test
public void test() {
EzyPluginInfoController controller = new EzyPluginInfoController();
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
EzySimplePluginInfoRequest request = new EzySimplePluginInfoRequest();
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzySimpleUser user = new EzySimpleUser();
user.setZoneId(1);
request.setSession(session);
request.setUser(user);
EzyArray data = EzyEntityFactory.newArrayBuilder().append("test").build();
request.deserializeParams(data);
controller.handle(serverContext, request);
EzyPluginContext pluginContext = mock(EzyPluginContext.class);
EzySimplePlugin plugin = new EzySimplePlugin();
EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
plugin.setSetting(pluginSetting);
when(pluginContext.getPlugin()).thenReturn(plugin);
when(zoneContext.getPluginContext("test")).thenReturn(pluginContext);
controller.handle(serverContext, request);
}
use of com.tvd12.ezyfoxserver.context.EzyPluginContext in project ezyfox-server by youngmonkeys.
the class EzySimplePluginEntryTest method notAllowRequestTest.
@Test
public void notAllowRequestTest() {
// given
EzyPluginContext pluginContext = mock(EzyPluginContext.class);
ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyPluginSetup pluginSetup = mock(EzyPluginSetup.class);
EzyPlugin plugin = mock(EzyPlugin.class);
when(pluginContext.getPlugin()).thenReturn(plugin);
EzyPluginSetting pluginSetting = mock(EzyPluginSetting.class);
when(plugin.getSetting()).thenReturn(pluginSetting);
NotAllowRequestEntry sut = new NotAllowRequestEntry();
// when
when(pluginContext.get(ScheduledExecutorService.class)).thenReturn(executorService);
when(pluginContext.getParent()).thenReturn(zoneContext);
when(zoneContext.getParent()).thenReturn(serverContext);
when(pluginContext.get(EzyPluginSetup.class)).thenReturn(pluginSetup);
sut.config(pluginContext);
// then
verify(pluginContext, times(0)).get(EzyPluginSetup.class);
}
use of com.tvd12.ezyfoxserver.context.EzyPluginContext 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.context.EzyPluginContext 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.context.EzyPluginContext in project ezyfox-server by youngmonkeys.
the class EzySimplePluginEntry method createBeanContext.
private EzyBeanContext createBeanContext(EzyPluginContext context) {
EzyBindingContext bindingContext = createBindingContext();
EzyMarshaller marshaller = bindingContext.newMarshaller();
EzyUnmarshaller unmarshaller = bindingContext.newUnmarshaller();
EzyResponseFactory pluginResponseFactory = createPluginResponseFactory(context, marshaller);
ScheduledExecutorService executorService = context.get(ScheduledExecutorService.class);
EzyPluginSetting pluginSetting = context.getPlugin().getSetting();
EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder().addSingleton("pluginContext", context).addSingleton("marshaller", marshaller).addSingleton("unmarshaller", unmarshaller).addSingleton("executorService", executorService).addSingleton("zoneContext", context.getParent()).addSingleton("serverContext", context.getParent().getParent()).addSingleton("pluginResponseFactory", pluginResponseFactory).addSingleton("featureCommandManager", new EzyFeatureCommandManager()).addSingleton("requestCommandManager", new EzyRequestCommandManager()).activeProfiles(pluginSetting.getActiveProfiles());
Class[] singletonClasses = getSingletonClasses();
beanContextBuilder.addSingletonClasses(singletonClasses);
Class[] prototypeClasses = getPrototypeClasses();
beanContextBuilder.addPrototypeClasses(prototypeClasses);
Set<String> scanablePackages = internalGetScanableBeanPackages();
if (pluginSetting.getPackageName() != null) {
scanablePackages.add(pluginSetting.getPackageName());
}
EzyReflection reflection = new EzyReflectionProxy(scanablePackages);
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedExtendsClasses(EzyEventHandler.class, EzyPluginEventController.class));
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestController.class));
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyExceptionHandler.class));
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestInterceptor.class));
beanContextBuilder.scan(scanablePackages);
setupBeanContext(context, beanContextBuilder);
return beanContextBuilder.build();
}
Aggregations