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());
}
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);
}
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));
}
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));
}
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));
}
Aggregations