@Test
public void testLayoutRowList() throws IOException,
PackageIntegrationException,
DroolsParserException {
ReteGraph graph = new ReteGraph();
BaseVertex root = loadRete( graph );
final RowList rows = ReteooLayoutFactory.calculateReteRows( root );
ReteooLayoutFactory.layoutRowList( graph,
rows );
final List nodes = graph.getChildren();
BaseVertex[] yOrder = (BaseVertex[]) nodes.toArray( new BaseVertex[0] );
Arrays.sort( yOrder,
new Comparator() {
public int compare(Object o1,
Object o2) {
BaseVertex v1 = (BaseVertex) o1;
BaseVertex v2 = (BaseVertex) o2;
int y1 = v1.getLocation().y;
int y2 = v2.getLocation().y;
return new Integer( y1 ).compareTo( new Integer( y2 ) );
}
} );
Class[] expectedTypes = new Class[]{ReteVertex.class, EntryPointNodeVertex.class,
ObjectTypeNodeVertex.class, AlphaNodeVertex.class, AlphaNodeVertex.class,
LeftInputAdapterNodeVertex.class, LeftInputAdapterNodeVertex.class,
RuleTerminalNodeVertex.class, RuleTerminalNodeVertex.class};
for ( int i = 0; i < yOrder.length; i++ ) {
assertEquals( expectedTypes[i],
yOrder[i].getClass() );
if ( i > 0 ) {
// If current vertex has same type as previous then
// y-pos should match and x-pos should not match.
// If type is different then y-pos should *not* match.
BaseVertex current = yOrder[i];
BaseVertex previous = yOrder[i - 1];
if ( current.getClass().equals( previous.getClass() ) ) {
assertEquals( current.getLocation().y,
previous.getLocation().y );
assertNotSame( new Integer( current.getLocation().x ),
new Integer( previous.getLocation().x ) );
} else {
assertNotSame( new Integer( current.getLocation().y ),
new Integer( previous.getLocation().y ) );
}
}
}
}