001: package abbot.editor.editors;
002:
003: import java.awt.Component;
004: import javax.swing.*;
005: import java.util.*;
006:
007: import junit.extensions.abbot.*;
008: import abbot.finder.matchers.*;
009: import abbot.script.*;
010: import abbot.editor.widgets.*;
011: import abbot.tester.*;
012:
013: /** Verify PropertyCallEditor operation. */
014:
015: public class PropertyCallEditorTest extends ResolverFixture {
016:
017: private PropertyCall call;
018: private PropertyCallEditor editor;
019: private JComboBoxTester comboTester;
020:
021: private JComboBox id;
022: private JComboBox methods;
023: private JTextField cname;
024: private ArrayEditor args;
025:
026: private JComboBox getComponentID(PropertyCallEditor editor)
027: throws Exception {
028: return (JComboBox) getFinder().find(editor,
029: new NameMatcher(XMLConstants.TAG_COMPONENT));
030: }
031:
032: private JTextField getTargetClass(PropertyCallEditor editor)
033: throws Exception {
034: return (JTextField) getFinder().find(editor,
035: new NameMatcher(XMLConstants.TAG_CLASS));
036: }
037:
038: private JComboBox getMethod(PropertyCallEditor editor)
039: throws Exception {
040: return (JComboBox) getFinder().find(editor,
041: new NameMatcher(XMLConstants.TAG_METHOD));
042: }
043:
044: private ArrayEditor getArguments(PropertyCallEditor editor)
045: throws Exception {
046: return (ArrayEditor) getFinder().find(editor,
047: new NameMatcher(XMLConstants.TAG_ARGS));
048: }
049:
050: protected void setUp() throws Exception {
051: call = new PropertyCall(getResolver(), null,
052: "java.lang.Object", "wait", new String[] { "5000" }) {
053: };
054: editor = new PropertyCallEditor(call) {
055: };
056: comboTester = new JComboBoxTester();
057:
058: id = getComponentID(editor);
059: methods = getMethod(editor);
060: cname = getTargetClass(editor);
061: args = getArguments(editor);
062: }
063:
064: public void testSynchWithComponentID() throws Exception {
065: HashMap map = new HashMap();
066: ComponentReference ref = new ComponentReference(getResolver(),
067: Component.class, map);
068:
069: showFrame(editor);
070: int count = methods.getItemCount();
071:
072: comboTester.actionSelectItem(id, ref.getID());
073: assertEquals("Call target class name not changed",
074: Component.class.getName(), call.getTargetClassName());
075: assertEquals("Target class name not updated", Component.class
076: .getName(), cname.getText());
077: assertTrue("Method list should have updated", count != methods
078: .getItemCount());
079: assertEquals("Argument list not cleared", 0, call
080: .getArguments().length);
081: assertEquals("Arguments editor not cleared", 0, args
082: .getValues().length);
083: }
084:
085: public void testSynchWithTesterMethod() {
086: HashMap map = new HashMap();
087: ComponentReference ref = new ComponentReference(getResolver(),
088: JTabbedPane.class, map);
089: showFrame(editor);
090:
091: comboTester.actionSelectItem(id, ref.getID());
092: int count = methods.getItemCount();
093: // select a pseudo-property method
094: comboTester.actionSelectItem(methods, "getTabs");
095: assertEquals(
096: "Call target class not updated to match tester method",
097: JTabbedPaneTester.class.getName(), call
098: .getTargetClassName());
099: assertEquals("Class field not updated to match tester method",
100: JTabbedPaneTester.class.getName(), cname.getText());
101: assertEquals(
102: "Argument list not updated to include component target",
103: 1, call.getArguments().length);
104: assertEquals(
105: "Arguments editor not updated to include component target",
106: 1, args.getValues().length);
107: assertEquals("Component ID should be cleared", null, call
108: .getComponentID());
109: assertEquals("Component ID editor should have no selection",
110: null, id.getSelectedItem());
111: assertEquals("Method list should be unchanged", count, methods
112: .getItemCount());
113:
114: // select a real property method
115: comboTester.actionSelectItem(methods, "getName");
116: assertEquals(
117: "Call target class should be the target component class",
118: JTabbedPane.class.getName(), call.getTargetClassName());
119: assertEquals(
120: "Class field should hold the component class name",
121: JTabbedPane.class.getName(), cname.getText());
122: assertEquals("Argument list not updated", 0, call
123: .getArguments().length);
124: assertEquals("Arguments editor not updated", 0, args
125: .getValues().length);
126: assertEquals("Component ID should be set", ref.getID(), call
127: .getComponentID());
128: assertEquals("Component ID editor should have no selection",
129: ref.getID(), id.getSelectedItem());
130: assertEquals("Method list should be unchanged", count, methods
131: .getItemCount());
132: }
133:
134: /** Construct a test case with the given name. */
135: public PropertyCallEditorTest(String name) {
136: super (name);
137: }
138:
139: /** Run the default test suite. */
140: public static void main(String[] args) {
141: TestHelper.runTests(args, PropertyCallEditorTest.class);
142: }
143: }
|