001: package abbot.editor;
002:
003: import java.awt.*;
004: import javax.swing.*;
005: import javax.swing.table.*;
006: import junit.extensions.abbot.*;
007: import abbot.finder.matchers.*;
008:
009: public class ComponentNodeTest extends ComponentTestFixture {
010:
011: private CompactHierarchy hierarchy;
012:
013: protected void setUp() {
014: hierarchy = new CompactHierarchy(getHierarchy());
015: }
016:
017: public void testGetPath() {
018: ComponentNode root = new ComponentNode(hierarchy);
019: JTree tree = new JTree(root);
020: JFrame f = new JFrame(getName());
021: f.getContentPane().add(tree);
022: showWindow(f);
023: root.reload();
024: Object[] path = root.getNode(tree).getPath();
025: Component[] expected = new Component[] { null, f,
026: f.getContentPane(), tree };
027: for (int i = 0; i < path.length; i++) {
028: assertEquals("Wrong path element " + i + " on tree's path",
029: expected[i], ((ComponentNode) path[i])
030: .getComponent());
031: }
032: }
033:
034: public void testGetTableHeaderPath() throws Exception {
035: Object[][] data = { { "one", "two" }, { "three", "four" } };
036: String[] columns = { "one", "two" };
037: JTable table = new JTable(data, columns);
038: JScrollPane sp = new JScrollPane(table);
039: showFrame(sp);
040: ComponentNode root = new ComponentNode(hierarchy);
041: JTableHeader header = (JTableHeader) getFinder().find(
042: new ClassMatcher(JTableHeader.class));
043: Object[] path = root.getNode(header).getPath();
044:
045: ComponentNode node = (ComponentNode) path[path.length - 1];
046: assertEquals("Header should be last path element", header, node
047: .getComponent());
048: }
049:
050: public void testPopupPath() {
051: JLabel label = new JLabel(getName());
052: JFrame f = new JFrame(getName());
053: f.getContentPane().add(label);
054: showWindow(f, new Dimension(200, 200));
055:
056: JPopupMenu light = new JPopupMenu();
057: light.setName("light");
058: JMenu sublight = new JMenu("sublight");
059: sublight.add(new JMenuItem("subitem"));
060: light.add(new JMenuItem("item"));
061: light.add(sublight);
062: JPopupMenu heavy = new JPopupMenu();
063: heavy.setName("heavy");
064: for (int i = 0; i < 10; i++) {
065: heavy.add(new JMenuItem("item " + i));
066: }
067: JMenu subheavy = new JMenu("subheavy");
068: subheavy.add(new JMenuItem("subitem"));
069: heavy.add(subheavy);
070:
071: showPopup(light, label, 10, 10);
072: getRobot().mouseMove(sublight);
073: ComponentNode root = new ComponentNode(hierarchy);
074: Object[] path = root.getNode(sublight).getPath();
075: Component[] expected = new Component[] { null, f,
076: f.getContentPane(), label, light, sublight };
077: for (int i = 0; i < expected.length; i++) {
078: assertEquals("Wrong path element " + i + " on LW",
079: expected[i], ((ComponentNode) path[i])
080: .getComponent());
081: }
082:
083: showPopup(heavy, label);
084: getRobot().mouseMove(subheavy);
085: root.reload();
086: path = root.getNode(subheavy).getPath();
087: expected = new Component[] { null, f, f.getContentPane(),
088: label, heavy, subheavy };
089: for (int i = 0; i < expected.length; i++) {
090: assertEquals("Wrong path element " + i + " on LW",
091: expected[i], ((ComponentNode) path[i])
092: .getComponent());
093: }
094: }
095:
096: public ComponentNodeTest(String name) {
097: super (name);
098: }
099:
100: public static void main(String[] args) {
101: TestHelper.runTests(args, ComponentNodeTest.class);
102: }
103: }
|