use of com.tvd12.ezyfoxserver.setting.EzyPluginSetting 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.setting.EzyPluginSetting 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();
}
use of com.tvd12.ezyfoxserver.setting.EzyPluginSetting in project ezyfox-server-example by tvd12.
the class PluginEntry method setupBeanContext.
@Override
protected void setupBeanContext(EzyPluginContext context, EzyBeanContextBuilder builder) {
EzyPluginSetting setting = context.getPlugin().getSetting();
String pluginConfigFile = getConfigFile(setting);
builder.addProperties(pluginConfigFile);
logger.info("hello-world plugin config file: {}", pluginConfigFile);
}
use of com.tvd12.ezyfoxserver.setting.EzyPluginSetting 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.ezyfoxserver.setting.EzyPluginSetting in project ezyfox-server by youngmonkeys.
the class EzySimplePluginEntryTest method disallowRequestTest.
@Test
public void disallowRequestTest() {
// 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);
DisAllowRequestEntry sut = new DisAllowRequestEntry();
// 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);
}
Aggregations