use of org.jgrapht.io.DOTImporter in project Smack by igniterealtime.
the class ModularXmppClientToServerConnectionStateGraphTest method testStateGraphDotOutput.
@Test
public void testStateGraphDotOutput() throws IOException, ImportException {
URL stateGraphDotFileUrl = Resources.getResource("state-graph.dot");
String expectedStateGraphDot = Resources.toString(stateGraphDotFileUrl, StandardCharsets.UTF_8);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ModularXmppClientToServerConnectionTool.printStateGraph(pw, false);
String currentStateGraphDot = sw.toString();
@SuppressWarnings("serial") DOTImporter<String, DefaultEdge> dotImporter = new DOTImporter<>((id, attributes) -> id, (from, to, label, attributes) -> {
return new DefaultEdge() {
@Override
public int hashCode() {
return HashCode.builder().append(getSource()).append(getTarget()).build();
}
@Override
public boolean equals(Object other) {
return EqualsUtil.equals(this, other, (b, o) -> b.append(getSource(), o.getSource()).append(getTarget(), o.getTarget()));
}
};
});
DirectedPseudograph<String, DefaultEdge> currentStateGraph = new DirectedPseudograph<>(DefaultEdge.class);
DirectedPseudograph<String, DefaultEdge> expectedStateGraph = new DirectedPseudograph<>(DefaultEdge.class);
dotImporter.importGraph(expectedStateGraph, new StringReader(expectedStateGraphDot));
dotImporter.importGraph(currentStateGraph, new StringReader(currentStateGraphDot));
assertEquals(expectedStateGraph, currentStateGraph);
}
Aggregations