use of com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory in project ezyfox-server by youngmonkeys.
the class EzyAsmAbstractRequestHandlerTest method responseToSessionTest.
@Test
public void responseToSessionTest() {
// given
String command = RandomUtil.randomShortAlphabetString();
String data = RandomUtil.randomShortAlphabetString();
EzyUserSessionEvent event = mock(EzyUserSessionEvent.class);
EzySession session = mock(EzySession.class);
when(event.getSession()).thenReturn(session);
EzyObjectResponse objectResponse = mock(EzyObjectResponse.class);
when(objectResponse.command(command)).thenReturn(objectResponse);
when(objectResponse.data(data)).thenReturn(objectResponse);
when(objectResponse.session(session)).thenReturn(objectResponse);
EzyResponseFactory responseFactory = mock(EzyResponseFactory.class);
when(responseFactory.newObjectResponse()).thenReturn(objectResponse);
InternalRequestHandler sut = new InternalRequestHandler();
sut.setCommand(command);
sut.setResponseFactory(responseFactory);
// then
sut.responseToSession(event, data);
// then
verify(event, times(1)).getSession();
verify(objectResponse, times(1)).command(command);
verify(objectResponse, times(1)).data(data);
verify(objectResponse, times(1)).session(session);
verify(objectResponse, times(1)).execute();
verify(responseFactory, times(1)).newObjectResponse();
}
use of com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory 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!"));
}
use of com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory 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();
}
use of com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory 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.support.factory.EzyResponseFactory in project ezyfox-server by youngmonkeys.
the class EzySimpleAppEntry method createAppResponseFactory.
private EzyResponseFactory createAppResponseFactory(EzyAppContext appContext, EzyMarshaller marshaller) {
EzyAppResponseFactory factory = new EzyAppResponseFactory();
factory.setAppContext(appContext);
factory.setMarshaller(marshaller);
return factory;
}
Aggregations