01: package abbot.tester.extensions;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05: import javax.swing.*;
06: import java.util.List;
07: import java.util.*;
08:
09: import junit.extensions.abbot.*;
10: import junit.extensions.abbot.Timer;
11: import junit.framework.*;
12: import abbot.util.ExtendedComparator;
13:
14: import org.jgraph.JGraph;
15: import org.jgraph.graph.*;
16:
17: /** Unit test to verify the JGraphTester class. */
18:
19: public class JGraphTesterTest extends ComponentTestFixture {
20:
21: private static final int COUNT = 2;
22:
23: private JGraphTester tester;
24: private JGraph graph;
25: private List cells;
26:
27: protected void setUp() {
28: tester = new JGraphTester();
29: graph = new JGraph();
30: cells = new ArrayList();
31: GraphModel m = new DefaultGraphModel();
32: Map attributes = new HashMap();
33: for (int i = 0; i < COUNT; i++) {
34: DefaultGraphCell cell = new DefaultGraphCell("cell" + i);
35: Map map = new HashMap();
36: GraphConstants.setBounds(map, new Rectangle(10, 40 * i, 40,
37: 30));
38: cells.add(cell);
39: attributes.put(cell, map);
40: }
41: m.insert(cells.toArray(), attributes, null, null, null);
42: graph.setModel(m);
43: showFrame(new JScrollPane(graph), new Dimension(200, 200));
44: }
45:
46: public void testSelectCell() throws Exception {
47: assertTrue("Initial selection should be empty", graph
48: .getSelectionCell() == null);
49: tester.actionSelectCell(graph, new JGraphLocation(0));
50: assertEquals("Wrong selection", cells.get(0), graph
51: .getSelectionCell());
52:
53: tester.actionSelectCell(graph, new JGraphLocation(1));
54: assertEquals("Wrong selection (2)", cells.get(1), graph
55: .getSelectionCell());
56:
57: tester.actionSelectCell(graph, new JGraphLocation(0));
58: assertEquals("Wrong selection (3)", cells.get(0), graph
59: .getSelectionCell());
60: }
61:
62: public void testSelectCellScaled() throws Exception {
63: assertTrue("Initial selection should be empty", graph
64: .getSelectionCell() == null);
65: graph.setScale(4.0d);
66:
67: tester.actionSelectCell(graph, new JGraphLocation(0));
68: assertEquals("Wrong selection", cells.get(0), graph
69: .getSelectionCell());
70:
71: tester.actionSelectCell(graph, new JGraphLocation(1));
72: assertEquals("Wrong selection (2)", cells.get(1), graph
73: .getSelectionCell());
74:
75: tester.actionSelectCell(graph, new JGraphLocation(0));
76: assertEquals("Wrong selection (3)", cells.get(0), graph
77: .getSelectionCell());
78: }
79:
80: public static void main(String[] args) {
81: RepeatHelper.runTests(args, JGraphTesterTest.class);
82: }
83: }
|