001: package abbot.editor.editors;
002:
003: import java.awt.Color;
004: import javax.swing.*;
005:
006: import junit.extensions.abbot.*;
007: import abbot.DynamicLoadingConstants;
008: import abbot.script.*;
009: import abbot.tester.*;
010: import abbot.finder.matchers.*;
011: import abbot.editor.widgets.*;
012:
013: /** Verify LaunchEditor operation. */
014:
015: public class LaunchEditorTest extends ResolverFixture implements
016: XMLConstants, DynamicLoadingConstants {
017:
018: private Launch launch;
019: private LaunchEditor editor;
020: private ComponentTester tester;
021:
022: protected void setUp() {
023: launch = new Launch(getResolver(), LaunchEditor.HELP_DESC,
024: "java.lang.Object", "hashCode", null);
025: editor = new LaunchEditor(launch);
026: tester = new ComponentTester();
027: }
028:
029: public void testRemoveHelpDescription() throws Exception {
030: showFrame(editor);
031: JCheckBox cb = (JCheckBox) getFinder().find(
032: new ClassMatcher(JCheckBox.class));
033: assertEquals("Should start with help description",
034: LaunchEditor.HELP_DESC, launch.getDescription());
035: tester.actionClick(cb);
036: assertFalse(
037: "Help description should be changed on edit of other prop",
038: LaunchEditor.HELP_DESC.equals(launch.getDescription()));
039: }
040:
041: public void testClasspathAffectsClassAndMethod() throws Exception {
042: String PATH = DYNAMIC_CLASSPATH;
043: String CLASSNAME = DYNAMIC_CLASSNAME;
044: String METHOD = "main";
045: launch.setTargetClassName(CLASSNAME);
046: launch.setMethodName(METHOD);
047: launch.setArguments("[]");
048: launch.setClasspath(PATH);
049: editor = new LaunchEditor(launch);
050: showFrame(editor);
051:
052: ArrayEditor array = (ArrayEditor) getFinder().find(editor,
053: new NameMatcher(TAG_CLASSPATH));
054: JTextField tf = (JTextField) getFinder().find(array,
055: new NameMatcher("editor"));
056: JTextField className = (JTextField) getFinder().find(editor,
057: new NameMatcher(TAG_CLASS));
058: JComboBox methodCombo = (JComboBox) getFinder().find(editor,
059: new NameMatcher(TAG_METHOD));
060: JTextField method = (JTextField) getFinder().find(methodCombo,
061: new ClassMatcher(JTextField.class));
062: Color normal = className.getForeground();
063:
064: assertEquals("Wrong class name", CLASSNAME, className.getText());
065: assertEquals("Wrong method name", METHOD, method.getText());
066: assertEquals("Wrong number of path elements", 1, array
067: .getValues().length);
068: assertEquals("Wrong path", PATH, array.getValues()[0]);
069:
070: JTextComponentTester textTester = new JTextComponentTester();
071: textTester.actionEnterText(tf, "no.such.path");
072:
073: assertTrue("Class name field should show invalid: "
074: + className.getForeground(), !normal.equals(className
075: .getForeground()));
076: assertTrue("Method name field should show invalid"
077: + method.getForeground(), !normal.equals(method
078: .getForeground()));
079:
080: textTester.actionEnterText(tf, PATH);
081: assertEquals(
082: "Class name should have reverted to normal foreground",
083: normal, className.getForeground());
084: assertEquals(
085: "Method name should have reverted to normal foreground",
086: normal, method.getForeground());
087: }
088:
089: public void testChangeClasspath() throws Exception {
090: String PATH = "/some/path";
091: launch.setClasspath(PATH);
092: editor = new LaunchEditor(launch);
093: showFrame(editor);
094: ArrayEditor array = (ArrayEditor) getFinder().find(editor,
095: new NameMatcher(TAG_CLASSPATH));
096:
097: Object[] path = array.getValues();
098: assertEquals("Path element not added", 1, path.length);
099:
100: JTextField tf = (JTextField) getFinder().find(array,
101: new NameMatcher("editor"));
102: assertEquals("Incorrect editor text", PATH, tf.getText());
103:
104: path = array.getValues();
105: assertEquals("Path not changed", PATH, path[0]);
106: }
107:
108: public void testAddClasspath() throws Exception {
109: showFrame(editor);
110: ArrayEditor array = (ArrayEditor) getFinder().find(editor,
111: new NameMatcher(TAG_CLASSPATH));
112: JButton button = (JButton) getFinder().find(array,
113: new NameMatcher("add"));
114: tester.actionClick(button);
115: Object[] path = array.getValues();
116: assertEquals("Should have added a path", 1, path.length);
117: tester.actionClick(button);
118: path = array.getValues();
119: assertEquals("Should have added a path", 2, path.length);
120: }
121:
122: /** Construct a test case with the given name. */
123: public LaunchEditorTest(String name) {
124: super (name);
125: }
126:
127: /** Run the default test suite. */
128: public static void main(String[] args) {
129: TestHelper.runTests(args, LaunchEditorTest.class);
130: }
131: }
|