7 changed files with 155 additions and 2 deletions
-
1src/main/java/com/corundumstudio/socketio/SocketIORouter.java
-
5src/main/java/com/corundumstudio/socketio/SocketIOServer.java
-
6src/main/java/com/corundumstudio/socketio/parser/Encoder.java
-
45src/test/java/com/corundumstudio/socketio/parser/EncoderConnectionPacketTest.java
-
50src/test/java/com/corundumstudio/socketio/parser/EncoderEventPacketTest.java
-
31src/test/java/com/corundumstudio/socketio/parser/EncoderMessagePacketTest.java
-
19src/test/java/com/corundumstudio/socketio/parser/PayloadTest.java
@ -0,0 +1,45 @@ |
|||||
|
package com.corundumstudio.socketio.parser; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
|
||||
|
import org.codehaus.jackson.map.ObjectMapper; |
||||
|
import org.junit.Assert; |
||||
|
import org.junit.Test; |
||||
|
|
||||
|
public class EncoderConnectionPacketTest { |
||||
|
|
||||
|
private Encoder encoder = new Encoder(new ObjectMapper()); |
||||
|
|
||||
|
@Test |
||||
|
public void testEncodeHeartbeat() throws IOException { |
||||
|
Packet packet = new Packet(PacketType.HEARTBEAT); |
||||
|
String result = encoder.encodePacket(packet); |
||||
|
Assert.assertEquals("2::", result); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void testEncodeDisconnection() throws IOException { |
||||
|
Packet packet = new Packet(PacketType.DISCONNECT); |
||||
|
packet.setEndpoint("/woot"); |
||||
|
String result = encoder.encodePacket(packet); |
||||
|
Assert.assertEquals("0::/woot", result); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void testEncode() throws IOException { |
||||
|
Packet packet = new Packet(PacketType.CONNECT); |
||||
|
packet.setEndpoint("/tobi"); |
||||
|
String result = encoder.encodePacket(packet); |
||||
|
Assert.assertEquals("1::/tobi", result); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void testEncodePacketWithQueryString() throws IOException { |
||||
|
Packet packet = new Packet(PacketType.CONNECT); |
||||
|
packet.setEndpoint("/test"); |
||||
|
packet.setQs("?test=1"); |
||||
|
String result = encoder.encodePacket(packet); |
||||
|
Assert.assertEquals("1::/test:?test=1", result); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,50 @@ |
|||||
|
package com.corundumstudio.socketio.parser; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.util.Arrays; |
||||
|
import java.util.Collections; |
||||
|
|
||||
|
import org.codehaus.jackson.map.ObjectMapper; |
||||
|
import org.codehaus.jackson.map.annotate.JsonSerialize; |
||||
|
import org.junit.Assert; |
||||
|
import org.junit.Test; |
||||
|
|
||||
|
public class EncoderEventPacketTest { |
||||
|
|
||||
|
private Encoder encoder; |
||||
|
|
||||
|
public EncoderEventPacketTest() { |
||||
|
ObjectMapper om = new ObjectMapper(); |
||||
|
om.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); |
||||
|
encoder = new Encoder(om); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Test |
||||
|
public void testEncode() throws IOException { |
||||
|
Packet packet = new Packet(PacketType.EVENT); |
||||
|
packet.setName("woot"); |
||||
|
String result = encoder.encodePacket(packet); |
||||
|
Assert.assertEquals("5:::{\"name\":\"woot\"}", result); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void testEncodeWithMessageIdAndAck() throws IOException { |
||||
|
Packet packet = new Packet(PacketType.EVENT); |
||||
|
packet.setId("1"); |
||||
|
packet.setAck("data"); |
||||
|
packet.setName("tobi"); |
||||
|
String result = encoder.encodePacket(packet); |
||||
|
Assert.assertEquals("5:1+::{\"name\":\"tobi\"}", result); |
||||
|
} |
||||
|
|
||||
|
@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")); |
||||
|
String result = encoder.encodePacket(packet); |
||||
|
Assert.assertEquals("5:::{\"name\":\"edwald\",\"args\":[{\"a\":\"b\"},2,\"3\"]}", result); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,31 @@ |
|||||
|
package com.corundumstudio.socketio.parser; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
|
||||
|
import org.codehaus.jackson.map.ObjectMapper; |
||||
|
import org.junit.Assert; |
||||
|
import org.junit.Test; |
||||
|
|
||||
|
public class EncoderMessagePacketTest { |
||||
|
|
||||
|
private Encoder encoder = new Encoder(new ObjectMapper()); |
||||
|
|
||||
|
@Test |
||||
|
public void testEncode() throws IOException { |
||||
|
Packet packet = new Packet(PacketType.MESSAGE); |
||||
|
packet.setData("woot"); |
||||
|
String result = encoder.encodePacket(packet); |
||||
|
Assert.assertEquals("3:::woot", result); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void testEncodeWithIdAndEndpoint() throws IOException { |
||||
|
Packet packet = new Packet(PacketType.MESSAGE); |
||||
|
packet.setId("5"); |
||||
|
packet.setAck(true); |
||||
|
packet.setEndpoint("/tobi"); |
||||
|
String result = encoder.encodePacket(packet); |
||||
|
Assert.assertEquals("3:5:/tobi", result); |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue