Search in sources :

Example 16 with Packet

use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.

the class EncoderEventPacketTest method testEncode.

@Test
public void testEncode() throws IOException {
    Packet packet = new Packet(PacketType.EVENT);
    packet.setName("woot");
    ByteBuf result = Unpooled.buffer();
    //        encoder.encodePacket(packet, result);
    Assert.assertEquals("5:::{\"name\":\"woot\"}", result.toString(CharsetUtil.UTF_8));
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 17 with Packet

use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.

the class EncoderEventPacketTest method testEncodeWithMessageIdAndAck.

@Test
public void testEncodeWithMessageIdAndAck() throws IOException {
    Packet packet = new Packet(PacketType.EVENT);
    //        packet.setId(1L);
    //        packet.setAck(Packet.ACK_DATA);
    packet.setName("tobi");
    ByteBuf result = Unpooled.buffer();
    //        encoder.encodePacket(packet, result);
    Assert.assertEquals("5:1+::{\"name\":\"tobi\"}", result.toString(CharsetUtil.UTF_8));
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 18 with Packet

use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.

the class EncoderEventPacketTest method testEncodeWithData.

@Test
public void testEncodeWithData() throws IOException {
    Packet packet = new Packet(PacketType.EVENT);
    packet.setName("edwald");
    //        packet.setArgs(Arrays.asList(Collections.singletonMap("a", "b"), 2, "3"));
    ByteBuf result = Unpooled.buffer();
    //        encoder.encodePacket(packet, result);
    Assert.assertEquals("5:::{\"name\":\"edwald\",\"args\":[{\"a\":\"b\"},2,\"3\"]}", result.toString(CharsetUtil.UTF_8));
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 19 with Packet

use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.

the class PayloadTest method testDecodingNewline.

@Test
public void testDecodingNewline() throws IOException {
    Packet packet = decoder.decodePacket("3:::\n", null);
    Assert.assertEquals(PacketType.MESSAGE, packet.getType());
    Assert.assertEquals("\n", packet.getData());
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet) Test(org.junit.Test)

Example 20 with Packet

use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.

the class PayloadTest method testPayloadDecode.

@Test
public void testPayloadDecode() throws IOException {
    ByteBuf buffer = Unpooled.wrappedBuffer("�5�3:::5�7�3:::53d�3�0::".getBytes());
    List<Packet> payload = new ArrayList<Packet>();
    while (buffer.isReadable()) {
        Packet packet = decoder.decodePackets(buffer, null);
        payload.add(packet);
    }
    Assert.assertEquals(3, payload.size());
    Packet msg1 = payload.get(0);
    Assert.assertEquals(PacketType.MESSAGE, msg1.getType());
    Assert.assertEquals("5", msg1.getData());
    Packet msg2 = payload.get(1);
    Assert.assertEquals(PacketType.MESSAGE, msg2.getType());
    Assert.assertEquals("53d", msg2.getData());
    Packet msg3 = payload.get(2);
    Assert.assertEquals(PacketType.DISCONNECT, msg3.getType());
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

Packet (com.corundumstudio.socketio.protocol.Packet)39 Test (org.junit.Test)27 ByteBuf (io.netty.buffer.ByteBuf)15 Namespace (com.corundumstudio.socketio.namespace.Namespace)2 AuthPacket (com.corundumstudio.socketio.protocol.AuthPacket)2 HandshakeData (com.corundumstudio.socketio.HandshakeData)1 SocketIOClient (com.corundumstudio.socketio.SocketIOClient)1 Transport (com.corundumstudio.socketio.Transport)1 HttpErrorMessage (com.corundumstudio.socketio.messages.HttpErrorMessage)1 JacksonJsonSupport (com.corundumstudio.socketio.protocol.JacksonJsonSupport)1 PacketDecoder (com.corundumstudio.socketio.protocol.PacketDecoder)1 ConnectMessage (com.corundumstudio.socketio.store.pubsub.ConnectMessage)1 NamespaceClient (com.corundumstudio.socketio.transport.NamespaceClient)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 BinaryWebSocketFrame (io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame)1 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)1 WebSocketFrame (io.netty.handler.codec.http.websocketx.WebSocketFrame)1