Search in sources :

Example 1 with EzyWsResponseApi

use of com.tvd12.ezyfoxserver.api.EzyWsResponseApi in project ezyfox-server by youngmonkeys.

the class EzyWsResponseApiTest method responseTest.

@Test
public void responseTest() throws Exception {
    // given
    EzyObjectToStringEncoder encoder = mock(EzyObjectToStringEncoder.class);
    EzyWsResponseApi sut = new EzyWsResponseApi(encoder);
    EzyArray data = EzyEntityFactory.EMPTY_ARRAY;
    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.WEBSOCKET);
        return session;
    });
    pack.addRecipients(sessions);
    // when
    sut.response(pack);
    // then
    verify(encoder, times(1)).encode(data, String.class);
    verify(encoder, times(0)).toMessageContent(data);
    verify(encoder, times(0)).encryptMessageContent(any(byte[].class), any(byte[].class));
}
Also used : EzySimplePackage(com.tvd12.ezyfoxserver.socket.EzySimplePackage) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyObjectToStringEncoder(com.tvd12.ezyfox.codec.EzyObjectToStringEncoder) EzyWsResponseApi(com.tvd12.ezyfoxserver.api.EzyWsResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Aggregations

EzyObjectToStringEncoder (com.tvd12.ezyfox.codec.EzyObjectToStringEncoder)1 EzyArray (com.tvd12.ezyfox.entity.EzyArray)1 EzyWsResponseApi (com.tvd12.ezyfoxserver.api.EzyWsResponseApi)1 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)1 EzySimplePackage (com.tvd12.ezyfoxserver.socket.EzySimplePackage)1 Test (org.testng.annotations.Test)1