Graphs

The PowerTools

Powerful open source tools for automated testing

Graphs

The PowerTools include a module that generates graphs. It makes use of the open source graph vizualization software GraphViz, which uses the Eclipse Public License and can be downloaded here. The PowerTools engine uses the module to generate coverage graphs for models (for Model Based Testing), but it can also be used separately.

 

The graph jar file on the downloads page contains only the graph module, so that it can be used without the rest of the PowerTools. The module is included in the larger PowerTools jar file, so when using the PowerTools for automated testing, the graph module is already available.

 

The following examples demonstrate how easy it is to create graphs from Java using the PowerTools graphs module.

Refer to existing nodes by name:

DirectedGraph graph = new DirectedGraph (false);

 

graph.addNode ("node 1");

graph.addNode ("node 2");

graph.addEdge ("node 1", "node 2");

graph.addNode ("node 3");

graph.addEdge ("node 1", "node 3");

 

Label edges by refering to existing nodes as objects:

DirectedGraph graph = new DirectedGraph (false);

 

Node node1 = graph.addNode ("node 1");

Node node2 = graph.addNode ("node 2");

Edge edge1 = graph.addEdge (node1, node2);

edge1.setLabel ("edge 1");

Node node3 = graph.addNode ("node 3");

Edge edge2 = graph.addEdge (node1, node3);

edge2.setLabel ("edge 2");

 

Give the graph a background colour and a label:

DirectedGraph graph = new DirectedGraph (true);

 

graph.setLabel ("graph label");

graph.setFillColour (Colour.LIGHT_GRAY);

graph.setTextColour (Colour.RED);

graph.setFontName ("Arial");

graph.setFontSize

 

graph.addNode ("node 1");

graph.addNode ("node 2");

graph.addEdge ("node 1", "node 2");

graph.addNode ("node 3");

graph.addEdge ("node 1", "node 3");

 

Set default node attributes and override them:

DirectedGraph graph = new DirectedGraph (true);

 

// set the default node attributes

graph.setDefaultNodeShape (Shape.CIRCLE);

graph.setDefaultNodeStyle (Style.FILLED);

graph.setDefaultNodeLineColour (Colour.RED);

graph.setDefaultNodeLineWidth (2);

graph.setDefaultNodeFillColour (Colour.PURPLE);

graph.setDefaultNodeTextColour (Colour.YELLOW);

graph.setDefaultNodeFontName ("Arial");

graph.setDefaultNodeFontSize (14);

 

// create nodes and edges

graph.addNode ("node 1");

graph.addNode ("node 2").setLineColour (Colour.GREEN);

graph.addEdge ("node 1", "node 2");

Node node3 = graph.addNode ("node 3");

 

// override some node attributes

node3.setShape (Shape.OCTAGON);

node3.setLineWidth (4);

graph.addEdge ("node 1", "node 3");

 

Create a cluster and subcluster:

DirectedGraph graph = new DirectedGraph (true);

Cluster cluster1 = graph.addCluster ("cluster 1");

Cluster cluster2 = graph.addCluster ("cluster 2", cluster1);

 

// create nodes and edges

graph.addNode ("node 1", cluster1);

graph.addNode ("node 2", cluster2);

graph.addEdge ("node 1", "node 2");

graph.addNode ("node 3");

graph.addEdge ("node 1", "node 3");

 

Set defaults for graph and cluster, then override them:

// create graph and set some default attributes

DirectedGraph graph = new DirectedGraph (true);

graph.setDefaultNodeShape (Shape.OVAL);

graph.setDefaultNodeFontName ("Arial");

 

// create cluster and set some default attributes

Cluster cluster = graph.addCluster ("cluster");

cluster.setLabel ("cluster label");

cluster.setStyle (Style.FILLED);

cluster.setFillColour (Colour.YELLOW);

cluster.setLineColour (Colour.RED);

cluster.setDefaultNodeShape (Shape.SQUARE);

// create nodes and edges

Node node1 = graph.addNode ("node 1", cluster);

graph.addNode ("node 2", cluster);

graph.addEdge ("node 1", "node 2");

graph.addNode ("node 3");

graph.addEdge ("node 1", "node 3");

 

// override some node attributes

node1.setShape (Shape.DIAMOND);

node1.setStyle (Style.FILLED);

node1.setFillColour (Colour.BLUE);

node1.setTextColour (Colour.WHITE);

 

© 2013-2014 Martin Gijsen