use of com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method handleUdpHandshakeSessionIsNull.
@SuppressWarnings("rawtypes")
@Test
public void handleUdpHandshakeSessionIsNull() {
// given
EzySimpleNioUdpDataHandler sut = new EzySimpleNioUdpDataHandler(1);
DatagramChannel channel = mock(DatagramChannel.class);
InetSocketAddress address = new InetSocketAddress(3005);
EzyMessage message = mock(EzyMessage.class);
String sessionToken = RandomUtil.randomAlphabetString(8);
long sessionId = 12345L;
int tokenSize = sessionToken.length();
int messageSize = 0;
// sessionIdSize
messageSize += 8;
// tokenLengthSize
messageSize += 2;
// messageSize
messageSize += tokenSize;
ByteBuffer buffer = ByteBuffer.allocate(messageSize);
buffer.putLong(sessionId);
buffer.putShort((short) tokenSize);
buffer.put(sessionToken.getBytes());
buffer.flip();
byte[] bytes = EzyByteBuffers.getBytes(buffer);
when(message.getContent()).thenReturn(bytes);
EzySessionManager sessionManager = mock(EzySessionManager.class);
sut.setSessionManager(sessionManager);
// when
MethodInvoker.create().object(sut).method("handleUdpHandshake").param(DatagramChannel.class, channel).param(InetSocketAddress.class, address).param(EzyMessage.class, message).call();
// then
verify(message, times(1)).getContent();
verify(sessionManager, times(1)).getSession(sessionId);
sut.destroy();
}
use of com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method testInvalidMessageCase.
@Test
public void testInvalidMessageCase() throws Exception {
EzySimpleNioUdpDataHandler handler = new EzySimpleNioUdpDataHandler(1);
byte[] bytes = new byte[] { 1, 2, 3 };
EzyUdpReceivedPacket packet = new EzySimpleUdpReceivedPacket(DatagramChannel.open(), new InetSocketAddress(12345), bytes);
handler.fireUdpPacketReceived(packet);
Thread.sleep(200);
handler.destroy();
}
use of com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method handleReceivedUdpPacketInvalidMessageTest.
@Test
public void handleReceivedUdpPacketInvalidMessageTest() {
// given
EzySimpleNioUdpDataHandler sut = new EzySimpleNioUdpDataHandler(1);
byte[] messageBytes = new byte[0];
EzyUdpReceivedPacket packet = mock(EzyUdpReceivedPacket.class);
when(packet.getBytes()).thenReturn(messageBytes);
// when
MethodInvoker.create().object(sut).method("handleReceivedUdpPacket").param(EzyUdpReceivedPacket.class, packet).call();
// then
sut.destroy();
}
Aggregations