use of com.tvd12.ezyfoxserver.event.EzyUserSessionEvent 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.event.EzyUserSessionEvent 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.event.EzyUserSessionEvent in project ezyfox-server by youngmonkeys.
the class EzyUserRequestInterceptorTest method preHandleTest.
@Test
public void preHandleTest() {
// given
EzyUserRequestInterceptor<EzyContext> sut = new EzyUserRequestInterceptor<EzyContext>() {
};
// when
// then
EzyContext context = mock(EzyContext.class);
EzyUserSessionEvent event = mock(EzyUserSessionEvent.class);
String command = RandomUtil.randomShortAlphabetString();
String data = RandomUtil.randomShortAlphabetString();
sut.preHandle(context, event, data, command);
sut.postHandle(context, event, data, command);
Exception e = new Exception("just test");
sut.postHandle(context, event, data, command, e);
}
Aggregations