Search in sources :

Example 66 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzySimpleWsHandlerGroupTest method handleReceivedStreamNotEnable.

@Test
public void handleReceivedStreamNotEnable() throws Exception {
    // given
    EzyWsHandlerGroup sut = newHandlerGroup(false);
    byte[] bytes = new byte[] { 1 << 4, 2, 3 };
    int offset = 0;
    int len = 3;
    // when
    MethodInvoker.create().object(sut).method("handleReceivedBytes").param(byte[].class, bytes).param(int.class, offset).param(int.class, len).call();
    // then
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    verify(session, times(1)).isStreamingEnable();
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 67 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession 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();
}
Also used : EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) EzyUserSessionEvent(com.tvd12.ezyfoxserver.event.EzyUserSessionEvent) EzyObjectResponse(com.tvd12.ezyfoxserver.support.command.EzyObjectResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 68 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyHandlerGroupManagerImplTest method mapSocketChannelNonContainsConnection.

@Test
public void mapSocketChannelNonContainsConnection() {
    // given
    EzyHandlerGroupManager sut = newHandlerGroupManager();
    EzySession session = mock(EzySession.class);
    EzyChannel channel = mock(EzyChannel.class);
    when(session.getChannel()).thenReturn(channel);
    Object connection = new Object();
    when(channel.getConnection()).thenReturn(connection);
    // when
    sut.mapSocketChannel(null, session);
    // then
    verify(session, times(1)).getChannel();
    verify(channel, times(1)).getConnection();
}
Also used : EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 69 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession 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!"));
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) GreetRequest(com.tvd12.ezyfoxserver.support.test.data.GreetRequest) HelloController(com.tvd12.ezyfoxserver.support.test.controller.HelloController) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyRequestHandlersImplementer(com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlersImplementer) GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyUserSessionEvent(com.tvd12.ezyfoxserver.event.EzyUserSessionEvent) EzyUserRequestHandler(com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler) EzySimpleUserSessionEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserSessionEvent) EzyObjectResponse(com.tvd12.ezyfoxserver.support.command.EzyObjectResponse) Test(org.testng.annotations.Test)

Example 70 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class HelloController2 method greet.

@EzyDoHandle("Hello")
public void greet(@EzyRequestData GreetRequest request, EzyUser user, EzySession session, Integer nothing) {
    GreetResponse response = new GreetResponse("Hello " + request.getWho() + "!");
    System.out.println("HelloController::Big/Hello response: " + response);
}
Also used : GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzyDoHandle(com.tvd12.ezyfox.core.annotation.EzyDoHandle)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)112 Test (org.testng.annotations.Test)92 EzyArray (com.tvd12.ezyfox.entity.EzyArray)33 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)26 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)25 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)25 BaseTest (com.tvd12.test.base.BaseTest)25 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)15 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)13 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)13 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)11 EzySendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl)8 EzyHandshakeController (com.tvd12.ezyfoxserver.controller.EzyHandshakeController)8 EzyHandshakeParams (com.tvd12.ezyfoxserver.request.EzyHandshakeParams)8 EzySimpleResponse (com.tvd12.ezyfoxserver.response.EzySimpleResponse)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8