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