Search in sources :

Example 31 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyfox-server by youngmonkeys.

the class EzyUserRequestAppSingletonControllerTest method test.

@Test
public void test() throws Exception {
    EzyRequestHandlerImplementer.setDebug(true);
    EzyExceptionHandlerImplementer.setDebug(true);
    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);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimpleApplication application = new EzySimpleApplication();
    application.setSetting(appSetting);
    application.setUserManager(appUserManager);
    application.setEventControllers(eventControllers);
    ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    appContext.setApp(application);
    appContext.setParent(zoneContext);
    appContext.setExecutorService(appScheduledExecutorService);
    appContext.init();
    EzySimpleAppEntry entry = new EzyAppEntryEx();
    entry.config(appContext);
    entry.start();
    handleClientRequest(appContext);
    EzyBeanContext beanContext = appContext.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.containsCommand("v122/listener/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) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySimpleAppEntry(com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 32 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyfox-server by youngmonkeys.

the class EzyUserRequestPrototypeControllerTest method test.

@Test
public void test() {
    // given
    EzyPrototypeFactory prototypeFactory = mock(EzyPrototypeFactory.class);
    when(prototypeFactory.getSuppliers(EzyRequestListener.class)).thenReturn(Collections.emptyList());
    EzyBeanContext beanContext = mock(EzyBeanContext.class);
    when(beanContext.getPrototypeFactory()).thenReturn(prototypeFactory);
    InternalController sut = new InternalController.Builder().beanContext(beanContext).build();
    // when
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyUserRequestEvent event = mock(EzyUserRequestEvent.class);
    String cmd = RandomUtil.randomShortAlphabetString();
    EzyHandler handler = mock(EzyHandler.class);
    sut.postHandle(appContext, event, cmd, handler);
    // then
    verify(beanContext, times(1)).getPrototypeFactory();
    verify(beanContext, times(1)).getSingleton("unmarshaller", EzyUnmarshaller.class);
}
Also used : EzyPrototypeFactory(com.tvd12.ezyfox.bean.EzyPrototypeFactory) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyUserRequestEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestEvent) EzyHandler(com.tvd12.ezyfox.function.EzyHandler) Test(org.testng.annotations.Test)

Example 33 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntryTest method scanPackages.

@Test
public void scanPackages() {
    // 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);
    InternalPluginEntry sut = new InternalPluginEntry();
    // 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
    EzyBeanContext beanContext = sut.beanContext;
    MongoConfig mongoConfig = (MongoConfig) beanContext.getBean(MongoConfig.class);
    Set<String> expectedPackages = Sets.newHashSet(EzySupportConstants.DEFAULT_PACKAGE_TO_SCAN, "com.tvd12.ezyfoxserver.support.v120.test.entry");
    Asserts.assertEquals(expectedPackages, mongoConfig.packagesToScan);
    Singleton singleton = (Singleton) beanContext.getBean(Singleton.class);
    Asserts.assertNotNull(singleton);
}
Also used : EzyPluginSetup(com.tvd12.ezyfoxserver.command.EzyPluginSetup) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzySingleton(com.tvd12.ezyfox.bean.annotation.EzySingleton) Test(org.testng.annotations.Test)

Example 34 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project java-examples by tvd12.

the class ReactiveExample method main.

public static void main(String[] args) {
    final EzyBeanContext beanContext = EzyBeanContext.builder().scan("com.tvd12.example.reactive").build();
    final RxHomeController rxHomeController = (RxHomeController) beanContext.getBean(RxHomeController.class);
    final HomeData rxHomeData = rxHomeController.getHomeData();
    System.out.println("rxHomeData: " + rxHomeData);
}
Also used : HomeData(com.tvd12.example.reactive.data.HomeData) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext)

Example 35 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project java-examples by tvd12.

the class PerformanceCompareTest method main.

public static void main(String[] args) {
    final EzyBeanContext beanContext = EzyBeanContext.builder().scan("com.tvd12.example.reactive").build();
    final HomeController sequenceHomeController = (HomeController) beanContext.getBean(HomeController.class);
    final RxHomeController rxHomeController = (RxHomeController) beanContext.getBean(RxHomeController.class);
    // warm up
    sequenceHomeController.getHomeData();
    rxHomeController.getHomeData();
    long sequenceCallElapsedTime = Performance.create().loop(100000).test(sequenceHomeController::getHomeData).getTime();
    long rxCallElapsedTime = Performance.create().loop(100000).test(rxHomeController::getHomeData).getTime();
    System.out.printf("sequence call elapsed time: %d\nreactive call elapsed time: %d\n", sequenceCallElapsedTime, rxCallElapsedTime);
    Reactive.destroy();
}
Also used : RxHomeController(com.tvd12.example.reactive.RxHomeController) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) RxHomeController(com.tvd12.example.reactive.RxHomeController) HomeController(com.tvd12.example.reactive.HomeController)

Aggregations

EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)25 Test (org.testng.annotations.Test)15 ApplicationContextBuilder (com.tvd12.ezyhttp.server.core.ApplicationContextBuilder)6 ResourceResolver (com.tvd12.ezyhttp.server.core.resources.ResourceResolver)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)6 EzyBeanContextBuilder (com.tvd12.ezyfox.bean.EzyBeanContextBuilder)5 ResourceDownloadManager (com.tvd12.ezyhttp.core.resources.ResourceDownloadManager)5 ApplicationContext (com.tvd12.ezyhttp.server.core.ApplicationContext)5 ViewContextBuilder (com.tvd12.ezyhttp.server.core.view.ViewContextBuilder)5 ViewContext (com.tvd12.ezyhttp.server.core.view.ViewContext)4 List (java.util.List)4 Calabash (com.tvd12.calabash.Calabash)3 SimpleEntityMapPersistFactory (com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)3 EzyReflection (com.tvd12.ezyfox.reflect.EzyReflection)3 EzyFeatureCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager)3 EzyRequestCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager)3 MongoClient (com.mongodb.MongoClient)2 StatisticsAware (com.tvd12.calabash.core.statistic.StatisticsAware)2 CalabashBuilder (com.tvd12.calabash.local.CalabashBuilder)2 SimpleEntityMapPersistSetting (com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting)2