Search in sources :

Example 1 with DOTImporter

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);
}
Also used : DOTImporter(org.jgrapht.io.DOTImporter) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) DefaultEdge(org.jgrapht.graph.DefaultEdge) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph) URL(java.net.URL) PrintWriter(java.io.PrintWriter) Test(org.junit.jupiter.api.Test)

Aggregations

PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 DefaultEdge (org.jgrapht.graph.DefaultEdge)1 DirectedPseudograph (org.jgrapht.graph.DirectedPseudograph)1 DOTImporter (org.jgrapht.io.DOTImporter)1 Test (org.junit.jupiter.api.Test)1