add tests
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.github.nkzawa.socketio.client;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ServerConnectionNamespaceTest extends ServerConnectionTest {
|
||||
|
||||
protected String nsp() {
|
||||
return "/foo";
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,8 @@ public class ServerConnectionTest {
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
serverProcess = Runtime.getRuntime().exec(
|
||||
"node src/test/resources/index.js " + PORT, new String[] {"DEBUG=socket.io:*,engine*"});
|
||||
String.format("node src/test/resources/index.js %s %s", PORT, nsp()),
|
||||
new String[] {"DEBUG=socket.io:*"});
|
||||
serverService = Executors.newCachedThreadPool();
|
||||
serverOutout = serverService.submit(new Runnable() {
|
||||
@Override
|
||||
@@ -91,7 +92,7 @@ public class ServerConnectionTest {
|
||||
|
||||
IO.Options opts = new IO.Options();
|
||||
opts.forceNew = true;
|
||||
socket = IO.socket("http://localhost:" + PORT, opts);
|
||||
socket = IO.socket(uri(), opts);
|
||||
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... objects) {
|
||||
@@ -118,7 +119,7 @@ public class ServerConnectionTest {
|
||||
|
||||
IO.Options opts = new IO.Options();
|
||||
opts.forceNew = true;
|
||||
socket = IO.socket("http://localhost:" + PORT, opts);
|
||||
socket = IO.socket(uri(), opts);
|
||||
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... objects) {
|
||||
@@ -151,7 +152,7 @@ public class ServerConnectionTest {
|
||||
|
||||
IO.Options opts = new IO.Options();
|
||||
opts.forceNew = true;
|
||||
socket = IO.socket("http://localhost:" + PORT, opts);
|
||||
socket = IO.socket(uri(), opts);
|
||||
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... objects) {
|
||||
@@ -182,7 +183,7 @@ public class ServerConnectionTest {
|
||||
|
||||
IO.Options opts = new IO.Options();
|
||||
opts.forceNew = true;
|
||||
socket = IO.socket("http://localhost:" + PORT, opts);
|
||||
socket = IO.socket(uri(), opts);
|
||||
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... objects) {
|
||||
@@ -201,4 +202,13 @@ public class ServerConnectionTest {
|
||||
assertThat(events.take(), is(new Object[] {jsonData, "bar"}));
|
||||
socket.disconnect();
|
||||
}
|
||||
|
||||
|
||||
private String uri() {
|
||||
return "http://localhost:" + PORT + nsp();
|
||||
}
|
||||
|
||||
protected String nsp() {
|
||||
return "/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,14 @@ public class ParserTest {
|
||||
test(packet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disconnect() {
|
||||
Packet packet = new Packet(Parser.DISCONNECT);
|
||||
packet.nsp = "/woot";
|
||||
test(packet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void event() {
|
||||
Packet packet1 = new Packet(Parser.EVENT);
|
||||
packet1.data = new JsonParser().parse("[\"a\", 1, {}]");
|
||||
@@ -38,6 +40,7 @@ public class ParserTest {
|
||||
test(packet2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ack() {
|
||||
Packet packet = new Packet(Parser.ACK);
|
||||
packet.data = new JsonParser().parse("[\"a\", 1, {}]");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
var server = require('http').Server()
|
||||
, io = require('socket.io')(server)
|
||||
, port = parseInt(process.argv[2], 10) || 3000;
|
||||
, port = parseInt(process.argv[2], 10) || 3000
|
||||
, nsp = process.argv[3] || '/';
|
||||
|
||||
io.on('connection', function(socket) {
|
||||
io.of(nsp).on('connection', function(socket) {
|
||||
socket.send('hello client');
|
||||
|
||||
socket.on('message', function() {
|
||||
|
||||
Reference in New Issue
Block a user