*/
@Test
public void testNetStreamEvents() {
errors.clear();
final Graph g1 = new DefaultGraph("G");
NetStreamReceiver net = null;
try {
net = new NetStreamReceiver("localhost", 2002, debug);
} catch (UnknownHostException e1) {
fail(e1.toString());
} catch (IOException e1) {
fail(e1.toString());
}
ThreadProxyPipe pipe = net.getDefaultStream();
pipe.addSink(g1);
g1.addSink(new Sink() {
public void graphAttributeAdded(String sourceId, long timeId,
String attribute, Object value) {
assertEquals(0, value);
assertEquals("graphAttribute", attribute);
}
public void graphAttributeChanged(String sourceId, long timeId,
String attribute, Object oldValue, Object newValue) {
assertTrue((Integer) newValue == 0 || (Integer) newValue == 1);
assertEquals("graphAttribute", attribute);
}
public void graphAttributeRemoved(String sourceId, long timeId,
String attribute) {
assertEquals("graphAttribute", attribute);
}
public void nodeAttributeAdded(String sourceId, long timeId,
String nodeId, String attribute, Object value) {
assertEquals(0, value);
assertEquals("nodeAttribute", attribute);
}
public void nodeAttributeChanged(String sourceId, long timeId,
String nodeId, String attribute, Object oldValue,
Object newValue) {
assertTrue((Integer) newValue == 0 || (Integer) newValue == 1);
assertEquals("nodeAttribute", attribute);
}
public void nodeAttributeRemoved(String sourceId, long timeId,
String nodeId, String attribute) {
assertEquals("nodeAttribute", attribute);
}
public void edgeAttributeAdded(String sourceId, long timeId,
String edgeId, String attribute, Object value) {
assertEquals(0, value);
assertEquals("edgeAttribute", attribute);
}
public void edgeAttributeChanged(String sourceId, long timeId,
String edgeId, String attribute, Object oldValue,
Object newValue) {
assertTrue((Integer) newValue == 0 || (Integer) newValue == 1);
assertEquals("edgeAttribute", attribute);
}
public void edgeAttributeRemoved(String sourceId, long timeId,
String edgeId, String attribute) {
assertEquals("edgeAttribute", attribute);
}
public void nodeAdded(String sourceId, long timeId, String nodeId) {
assertTrue("node0".equals(nodeId) || "node1".equals(nodeId));
}
public void nodeRemoved(String sourceId, long timeId, String nodeId) {
assertTrue("node0".equals(nodeId) || "node1".equals(nodeId));
}
public void edgeAdded(String sourceId, long timeId, String edgeId,
String fromNodeId, String toNodeId, boolean directed) {
assertEquals("edge", edgeId);
assertEquals("node0", fromNodeId);
assertEquals("node1", toNodeId);
assertEquals(true, directed);
}
public void edgeRemoved(String sourceId, long timeId, String edgeId) {
assertEquals("edge", edgeId);
}
public void graphCleared(String sourceId, long timeId) {
}
public void stepBegins(String sourceId, long timeId, double step) {
assertEquals(1.1, step);
}
});
Thread t = new Thread() {
@Override
public void run() {
Graph g = new MultiGraph("G", false, true);
NetStreamSender nsc = null;
try {
nsc = new NetStreamSender("localhost", 2002);
} catch (UnknownHostException e1) {
error(e1.toString());
return;
} catch (IOException e1) {
error(e1.toString());
return;
}
g.addSink(nsc);
Node node0 = g.addNode("node0");
Edge edge = g.addEdge("edge", "node0", "node1", true);
node0.addAttribute("nodeAttribute", 0);
node0.changeAttribute("nodeAttribute", 1);
node0.removeAttribute("nodeAttribute");
edge.addAttribute("edgeAttribute", 0);
edge.changeAttribute("edgeAttribute", 1);
edge.removeAttribute("edgeAttribute");
g.addAttribute("graphAttribute", 0);
g.changeAttribute("graphAttribute", 1);
g.removeAttribute("graphAttribute");
g.stepBegins(1.1);
g.removeEdge("edge");
g.removeNode("node0");
g.clear();
try {
nsc.close();
} catch (IOException e1) {
}