Search in sources :

Example 6 with EzyPluginContext

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);
}
Also used : EzySimplePluginInfoRequest(com.tvd12.ezyfoxserver.request.EzySimplePluginInfoRequest) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyPluginInfoController(com.tvd12.ezyfoxserver.controller.EzyPluginInfoController) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 7 with EzyPluginContext

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);
}
Also used : EzyPluginSetup(com.tvd12.ezyfoxserver.command.EzyPluginSetup) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting) Test(org.testng.annotations.Test)

Example 8 with EzyPluginContext

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;
    }
}
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 9 with EzyPluginContext

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);
}
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 10 with EzyPluginContext

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();
}
Also used : EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting) EzyUnmarshaller(com.tvd12.ezyfox.binding.EzyUnmarshaller) EzyMarshaller(com.tvd12.ezyfox.binding.EzyMarshaller) EzyBeanContextBuilder(com.tvd12.ezyfox.bean.EzyBeanContextBuilder) EzyReflectionProxy(com.tvd12.ezyfox.reflect.EzyReflectionProxy) EzyReflection(com.tvd12.ezyfox.reflect.EzyReflection)

Aggregations

EzyPluginContext (com.tvd12.ezyfoxserver.context.EzyPluginContext)16 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)13 Test (org.testng.annotations.Test)11 EzyPluginSetting (com.tvd12.ezyfoxserver.setting.EzyPluginSetting)8 BaseTest (com.tvd12.test.base.BaseTest)8 EzyPlugin (com.tvd12.ezyfoxserver.EzyPlugin)7 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)7 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)6 EzyPluginRequestController (com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController)6 EzyArray (com.tvd12.ezyfox.entity.EzyArray)5 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)5 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)4 EzyZone (com.tvd12.ezyfoxserver.EzyZone)4 EzyPluginSetup (com.tvd12.ezyfoxserver.command.EzyPluginSetup)4 EzyUserRequestPluginEvent (com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 EzyServerReadyEvent (com.tvd12.ezyfoxserver.event.EzyServerReadyEvent)3 EzySimpleServerReadyEvent (com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent)3 EzySimpleUserRequestPluginEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserRequestPluginEvent)3 EzySimplePluginSetting (com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting)3