Search in sources :

Example 1 with EzyRequestCommandManager

use of com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlersImplementerTest method testImplementFailedCase2.

@Test
public void testImplementFailedCase2() {
    EzyRequestHandlerImplementer.setDebug(true);
    EzyRequestHandlersImplementer implementer = new EzyRequestHandlersImplementer();
    EzyFeatureCommandManager featureCommandManager = new EzyFeatureCommandManager();
    EzyRequestCommandManager requestCommandManager = new EzyRequestCommandManager();
    implementer.setFeatureCommandManager(featureCommandManager);
    implementer.setRequestCommandManager(requestCommandManager);
    implementer.implement(Collections.singletonList(new HelloController2()));
}
Also used : EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) HelloController2(com.tvd12.ezyfoxserver.support.test.controller.HelloController2) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyRequestHandlersImplementer(com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlersImplementer) Test(org.testng.annotations.Test)

Example 2 with EzyRequestCommandManager

use of com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlersImplementerTest method test.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test() {
    // given
    EzyAppContext context = mock(EzyAppContext.class);
    EzySession session = mock(EzyAbstractSession.class);
    EzyUser user = new EzySimpleUser();
    EzyUserSessionEvent event = new EzySimpleUserSessionEvent(user, session);
    EzyRequestHandlerImplementer.setDebug(true);
    EzyRequestHandlersImplementer implementer = new EzyRequestHandlersImplementer();
    EzyResponseFactory responseFactory = mock(EzyResponseFactory.class);
    EzyObjectResponse objectResponse = mock(EzyObjectResponse.class);
    when(responseFactory.newObjectResponse()).thenReturn(objectResponse);
    when(objectResponse.command("Big/Hello6")).thenReturn(objectResponse);
    when(objectResponse.data(new GreetResponse("Hello Dzung!"))).thenReturn(objectResponse);
    when(objectResponse.session(any())).thenReturn(objectResponse);
    doNothing().when(objectResponse).execute();
    implementer.setResponseFactory(responseFactory);
    EzyFeatureCommandManager featureCommandManager = new EzyFeatureCommandManager();
    EzyRequestCommandManager requestCommandManager = new EzyRequestCommandManager();
    implementer.setFeatureCommandManager(featureCommandManager);
    implementer.setRequestCommandManager(requestCommandManager);
    Map<String, EzyUserRequestHandler> handlers = implementer.implement(Collections.singletonList(new HelloController()));
    for (EzyUserRequestHandler handler : handlers.values()) {
        handler.handle(context, event, new GreetRequest("Dzung"));
    }
    EzyRequestHandlerImplementer.setDebug(false);
    implementer = new EzyRequestHandlersImplementer();
    implementer.setFeatureCommandManager(featureCommandManager);
    implementer.setRequestCommandManager(requestCommandManager);
    // when
    handlers = implementer.implement(Collections.singletonList(new HelloController()));
    // then
    Asserts.assertTrue(handlers.containsKey("Big/Hello"));
    verify(responseFactory, times(1)).newObjectResponse();
    verify(objectResponse, times(1)).command("Big/Hello6");
    verify(objectResponse, times(1)).data(new GreetResponse("Hello Dzung!"));
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) GreetRequest(com.tvd12.ezyfoxserver.support.test.data.GreetRequest) HelloController(com.tvd12.ezyfoxserver.support.test.controller.HelloController) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyRequestHandlersImplementer(com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlersImplementer) GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyUserSessionEvent(com.tvd12.ezyfoxserver.event.EzyUserSessionEvent) EzyUserRequestHandler(com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler) EzySimpleUserSessionEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserSessionEvent) EzyObjectResponse(com.tvd12.ezyfoxserver.support.command.EzyObjectResponse) Test(org.testng.annotations.Test)

Example 3 with EzyRequestCommandManager

use of com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager in project ezyfox-server by youngmonkeys.

the class EzyUserRequestPluginSingletonControllerTest method test.

@Test
public void test() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzyZoneUserManager zoneUserManager = EzyZoneUserManagerImpl.builder().zoneName("test").build();
    zone.setUserManager(zoneUserManager);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    pluginSetting.setName("test");
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimplePlugin plugin = new EzySimplePlugin();
    plugin.setSetting(pluginSetting);
    plugin.setEventControllers(eventControllers);
    ScheduledExecutorService pluginScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimplePluginContext pluginContext = new EzySimplePluginContext();
    pluginContext.setPlugin(plugin);
    pluginContext.setParent(zoneContext);
    pluginContext.setExecutorService(pluginScheduledExecutorService);
    pluginContext.init();
    EzySimplePluginEntry entry = new EzyPluginEntryEx();
    entry.config(pluginContext);
    entry.start();
    handleClientRequest(pluginContext);
    EzyBeanContext beanContext = pluginContext.get(EzyBeanContext.class);
    EzyRequestCommandManager requestCommandManager = beanContext.getSingleton(EzyRequestCommandManager.class);
    EzyFeatureCommandManager featureCommandManager = beanContext.getSingleton(EzyFeatureCommandManager.class);
    Asserts.assertTrue(requestCommandManager.containsCommand("v1.2.2/hello"));
    Asserts.assertTrue(requestCommandManager.isManagementCommand("v1.2.2/hello"));
    Asserts.assertTrue(requestCommandManager.isPaymentCommand("v1.2.2/hello"));
    Asserts.assertEquals(featureCommandManager.getFeatureByCommand("v1.2.2/hello"), "hello.world");
    entry.destroy();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzySimplePluginContext(com.tvd12.ezyfoxserver.context.EzySimplePluginContext) EzySimplePluginEntry(com.tvd12.ezyfoxserver.support.entry.EzySimplePluginEntry) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 4 with EzyRequestCommandManager

use of com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntry method createBeanContext.

protected EzyBeanContext createBeanContext(EzyAppContext context) {
    EzyBindingContext bindingContext = createBindingContext();
    EzyMarshaller marshaller = bindingContext.newMarshaller();
    EzyUnmarshaller unmarshaller = bindingContext.newUnmarshaller();
    EzyResponseFactory appResponseFactory = createAppResponseFactory(context, marshaller);
    ScheduledExecutorService executorService = context.get(ScheduledExecutorService.class);
    EzyAppSetting appSetting = context.getApp().getSetting();
    EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder().addSingleton("appContext", context).addSingleton("marshaller", marshaller).addSingleton("unmarshaller", unmarshaller).addSingleton("executorService", executorService).addSingleton("zoneContext", context.getParent()).addSingleton("serverContext", context.getParent().getParent()).addSingleton("userManager", context.getApp().getUserManager()).addSingleton("appResponseFactory", appResponseFactory).addSingleton("featureCommandManager", new EzyFeatureCommandManager()).addSingleton("requestCommandManager", new EzyRequestCommandManager()).activeProfiles(appSetting.getActiveProfiles());
    Class[] singletonClasses = getSingletonClasses();
    beanContextBuilder.addSingletonClasses(singletonClasses);
    Class[] prototypeClasses = getPrototypeClasses();
    beanContextBuilder.addPrototypeClasses(prototypeClasses);
    Set<String> scanablePackages = internalGetScanableBeanPackages();
    if (appSetting.getPackageName() != null) {
        scanablePackages.add(appSetting.getPackageName());
    }
    EzyReflection reflection = new EzyReflectionProxy(scanablePackages);
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedExtendsClasses(EzyEventHandler.class, EzyAppEventController.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) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) 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)

Example 5 with EzyRequestCommandManager

use of com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager 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

EzyRequestCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager)9 EzyFeatureCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager)8 Test (org.testng.annotations.Test)7 EzyRequestHandlersImplementer (com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlersImplementer)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 EzyResponseFactory (com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory)3 HelloController (com.tvd12.ezyfoxserver.support.test.controller.HelloController)3 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)2 EzyBeanContextBuilder (com.tvd12.ezyfox.bean.EzyBeanContextBuilder)2 EzyBindingContext (com.tvd12.ezyfox.binding.EzyBindingContext)2 EzyMarshaller (com.tvd12.ezyfox.binding.EzyMarshaller)2 EzyUnmarshaller (com.tvd12.ezyfox.binding.EzyUnmarshaller)2 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)2 EzyReflection (com.tvd12.ezyfox.reflect.EzyReflection)2 EzyReflectionProxy (com.tvd12.ezyfox.reflect.EzyReflectionProxy)2 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)2 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)2 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)2 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)2 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)2