Search in sources :

Example 11 with EzySession

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

the class EzySendResponseImplTest method responseOneSuccessButNotDebug.

@Test
public void responseOneSuccessButNotDebug() throws Exception {
    // given
    EzySimpleSettings settings = new EzySimpleSettings();
    settings.setDebug(false);
    EzyResponseApi responseApi = spy(EzyAbstractResponseApi.class);
    EzySimpleServer server = new EzySimpleServer();
    server.setResponseApi(responseApi);
    server.setSettings(settings);
    EzySendResponseImpl cmd = new EzySendResponseImpl(server);
    EzyResponse response = new EzySimpleResponse(EzyCommand.APP_REQUEST);
    EzySession recipient = spy(EzyAbstractSession.class);
    // when
    cmd.execute(response, recipient, false, false, EzyTransportType.TCP);
    // then
    verify(responseApi, times(1)).response(any(EzyPackage.class), anyBoolean());
}
Also used : EzySimpleResponse(com.tvd12.ezyfoxserver.response.EzySimpleResponse) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyPackage(com.tvd12.ezyfoxserver.response.EzyPackage) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzySendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl) Test(org.testng.annotations.Test)

Example 12 with EzySession

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

the class EzySendResponseImplTest method responseOneExceptionCase.

@Test
public void responseOneExceptionCase() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    settings.setDebug(true);
    EzyResponseApi responseApi = mock(EzyResponseApi.class);
    doThrow(new IllegalArgumentException()).when(responseApi).response(any(EzyPackage.class), anyBoolean());
    EzySimpleServer server = new EzySimpleServer();
    server.setResponseApi(responseApi);
    server.setSettings(settings);
    EzySendResponseImpl cmd = new EzySendResponseImpl(server);
    EzyResponse response = new EzySimpleResponse(EzyCommand.APP_REQUEST);
    EzySession recipient = spy(EzyAbstractSession.class);
    cmd.execute(response, recipient, false, false, EzyTransportType.TCP);
}
Also used : EzySimpleResponse(com.tvd12.ezyfoxserver.response.EzySimpleResponse) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyPackage(com.tvd12.ezyfoxserver.response.EzyPackage) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzySendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl) Test(org.testng.annotations.Test)

Example 13 with EzySession

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

the class EzyStreamBytesImplTest method exceptionCaseTest.

@Test
public void exceptionCaseTest() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    settings.setDebug(true);
    EzyStreamingApi streamingApi = spy(EzyStreamingApi.class);
    doThrow(new IllegalArgumentException()).when(streamingApi).response(any(EzyBytesPackage.class));
    EzySimpleServer server = new EzySimpleServer();
    server.setStreamingApi(streamingApi);
    server.setSettings(settings);
    EzyStreamBytesImpl cmd = new EzyStreamBytesImpl(server);
    EzySession recipient = spy(EzyAbstractSession.class);
    cmd.execute(new byte[] { 1, 2, 3 }, recipient);
    cmd.execute(new byte[] { 1, 2, 3 }, Lists.newArrayList(recipient));
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyBytesPackage(com.tvd12.ezyfoxserver.response.EzyBytesPackage) EzyStreamBytesImpl(com.tvd12.ezyfoxserver.command.impl.EzyStreamBytesImpl) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 14 with EzySession

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

the class EzyStreamBytesImplTest method normalCaseTest.

@Test
public void normalCaseTest() {
    EzySimpleSettings settings = new EzySimpleSettings();
    settings.setDebug(true);
    EzyStreamingApi streamingApi = spy(EzyAbstractStreamingApi.class);
    EzySimpleServer server = new EzySimpleServer();
    server.setStreamingApi(streamingApi);
    server.setSettings(settings);
    EzyStreamBytesImpl cmd = new EzyStreamBytesImpl(server);
    EzySession recipient = spy(EzyAbstractSession.class);
    cmd.execute(new byte[] { 1, 2, 3 }, recipient);
    cmd.execute(new byte[] { 1, 2, 3 }, Lists.newArrayList(recipient));
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyStreamBytesImpl(com.tvd12.ezyfoxserver.command.impl.EzyStreamBytesImpl) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 15 with EzySession

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

the class EzySocketResponseApiTest method secureResponseImmediateTest.

@Test
public void secureResponseImmediateTest() throws Exception {
    // given
    EzyArray data = EzyEntityFactory.EMPTY_ARRAY;
    byte[] bytes = RandomUtil.randomShortByteArray();
    EzyObjectToByteEncoder encoder = mock(EzyObjectToByteEncoder.class);
    when(encoder.toMessageContent(data)).thenReturn(bytes);
    EzySocketResponseApi sut = new EzySocketResponseApi(encoder);
    EzySimplePackage pack = new EzySimplePackage();
    pack.setData(data);
    pack.setEncrypted(true);
    pack.setTransportType(EzyTransportType.TCP);
    int sessionCount = RandomUtil.randomSmallInt() + 1;
    List<EzySession> sessions = RandomUtil.randomList(sessionCount, () -> {
        EzySession session = mock(EzySession.class);
        when(session.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
        return session;
    });
    pack.addRecipients(sessions);
    // when
    sut.response(pack, true);
    // then
    verify(encoder, times(1)).toMessageContent(data);
    verify(encoder, times(sessionCount)).encryptMessageContent(any(byte[].class), any(byte[].class));
}
Also used : EzySimplePackage(com.tvd12.ezyfoxserver.socket.EzySimplePackage) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyObjectToByteEncoder(com.tvd12.ezyfox.codec.EzyObjectToByteEncoder) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzySocketResponseApi(com.tvd12.ezyfoxserver.api.EzySocketResponseApi) Test(org.testng.annotations.Test)

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