use of com.tvd12.ezyfox.codec.EzyObjectToStringEncoder 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));
}
use of com.tvd12.ezyfox.codec.EzyObjectToStringEncoder in project ezyfox-server by youngmonkeys.
the class EzyProxyResponseApiTest method test.
@Test
public void test() throws Exception {
EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
EzyProxyResponseApi api = new EzyProxyResponseApi(codecFactory);
EzyPackage pack = mock(EzyPackage.class);
api.response(pack);
EzyObjectToByteEncoder byteEncoder = mock(EzyObjectToByteEncoder.class);
EzyObjectToStringEncoder stringEncoder = mock(EzyObjectToStringEncoder.class);
when(codecFactory.newEncoder(EzyConnectionType.SOCKET)).thenReturn(byteEncoder);
when(codecFactory.newEncoder(EzyConnectionType.WEBSOCKET)).thenReturn(stringEncoder);
api = new EzyProxyResponseApi(codecFactory);
api.response(pack);
api.response(pack, true);
EzyImmediateDeliver immediateDeliver = mock(EzyImmediateDeliver.class);
EzyAbstractSession session = spy(EzyAbstractSession.class);
session.setImmediateDeliver(immediateDeliver);
when(pack.getRecipients(any(EzyConstant.class))).thenReturn(Lists.newArrayList(session));
api.response(pack);
api.response(pack, true);
}
Aggregations