support protocol v3 (except binary)

This commit is contained in:
Naoyuki Kanezawa
2014-04-05 15:45:51 +09:00
parent d40601020a
commit f44cb0a956
10 changed files with 400 additions and 194 deletions

View File

@@ -18,28 +18,33 @@ public class UrlTest {
@Test
public void parse() throws MalformedURLException, URISyntaxException {
URL url = Url.parse(new URI("http://woot.com/test"));
assertThat(url.getProtocol(), is("http"));
URL url = Url.parse(new URI("https://woot.com/test"));
assertThat(url.getProtocol(), is("https"));
assertThat(url.getHost(), is("woot.com"));
assertThat(url.getPath(), is("/test"));
}
@Test
public void parse_NoProtocol() throws MalformedURLException, URISyntaxException {
public void parseNoProtocol() throws MalformedURLException, URISyntaxException {
URL url = Url.parse(new URI("//localhost:3000"));
assertThat(url.getProtocol(), is("https"));
assertThat(url.getHost(), is("localhost"));
assertThat(url.getAuthority(), is("localhost:3000"));
assertThat(url.getPort(), is(3000));
}
@Test
public void parse_Namaspace() throws MalformedURLException, URISyntaxException {
public void parseNamespace() throws MalformedURLException, URISyntaxException {
assertThat(Url.parse(new URI("http://woot.com/woot")).getPath(), is("/woot"));
assertThat(Url.parse(new URI("http://google.com")).getPath(), is("/"));
assertThat(Url.parse(new URI("http://google.com/")).getPath(), is("/"));
}
@Test
public void parseDefaultPort() throws MalformedURLException, URISyntaxException {
assertThat(Url.parse(new URI("http://google.com:80/")).toString(), is("http://google.com/"));
assertThat(Url.parse(new URI("https://google.com:443/")).toString(), is("https://google.com/"));
}
@Test
public void extractId() throws MalformedURLException, URISyntaxException {
String id1 = Url.extractId(new URL("http://google.com:80/"));

View File

@@ -1,18 +1,20 @@
package com.github.nkzawa.socketio.parser;
import com.github.nkzawa.emitter.Emitter;
import com.google.gson.JsonParser;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import static com.github.nkzawa.socketio.parser.Parser.decode;
import static com.github.nkzawa.socketio.parser.Parser.encode;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@RunWith(JUnit4.class)
public class ParserTest {
private static Parser.Encoder encoder = new Parser.Encoder();
@Test
public void connect() {
Packet packet = new Packet(Parser.CONNECT);
@@ -49,10 +51,24 @@ public class ParserTest {
test(packet);
}
private void test(Packet packet) {
Packet _packet = decode(encode(packet));
assertThat(_packet.type, is(packet.type));
assertThat(_packet.data, is(packet.data));
assertThat(_packet.nsp, is(packet.nsp));
private void test(final Packet obj) {
encoder.encode(obj, new Parser.Encoder.Callback() {
@Override
public void call(String[] encodedPackets) {
Parser.Decoder decoder = new Parser.Decoder();
decoder.on(Parser.Decoder.EVENT_DECODED, new Emitter.Listener() {
@Override
public void call(Object... args) {
Packet packet = (Packet)args[0];
assertThat(packet.type, is(obj.type));
assertThat(packet.id, is(obj.id));
assertThat(packet.data, is(obj.data));
assertThat(packet.nsp, is(obj.nsp));
assertThat(packet.attachments, is(obj.attachments));
}
});
decoder.add(encodedPackets[0]);
}
});
}
}