KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > web > core > syntax > AutoCompletionTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.web.core.syntax;
21
22 import java.awt.event.KeyEvent JavaDoc;
23 import java.io.File JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import javax.swing.JEditorPane JavaDoc;
27 import javax.swing.text.Caret JavaDoc;
28 import junit.framework.Test;
29 import org.netbeans.editor.Utilities;
30 import org.netbeans.jellytools.EditorOperator;
31 import org.netbeans.editor.BaseDocument;
32 import org.netbeans.jellytools.modules.editor.CompletionJListOperator;
33 import org.netbeans.test.web.FileObjectFilter;
34 import org.netbeans.test.web.RecurrentSuiteFactory;
35 import org.netbeans.test.web.core.syntax.CompletionTest.TestStep;
36 import org.openide.actions.UndoAction;
37 import org.openide.filesystems.FileObject;
38 import org.openide.util.actions.SystemAction;
39
40 /**
41  *
42  * @author jindra
43  */

44 public class AutoCompletionTest extends CompletionTest {
45     
46     /** Creates a new instance of AutoCompletionTest */
47     public AutoCompletionTest(String JavaDoc name, FileObject testFileObj) {
48         super(name, testFileObj);
49         debug = false;
50     }
51     
52     public static Test suite() {
53         // find folder with test projects and define file objects filter
54
File JavaDoc datadir = new AutoCompletionTest(null, null).getDataDir();
55         File JavaDoc projectsDir = new File JavaDoc(datadir, "AutoCompletionTestProjects");
56         FileObjectFilter filter = new FileObjectFilter() {
57             public boolean accept(FileObject fo) {
58                 String JavaDoc ext = fo.getExt();
59                 String JavaDoc name = fo.getName();
60                 return (name.startsWith("test") || name.startsWith("Test"))
61                         && (xmlExts.contains(ext) || jspExts.contains(ext) || ext.equals("java"));
62             }
63         };
64         return RecurrentSuiteFactory.createSuite(AutoCompletionTest.class, projectsDir, filter);
65     }
66     
67     public void setUp() {
68         super.setUp();
69         Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
70     }
71     
72     protected void run(JEditorPane JavaDoc editor, List JavaDoc steps) throws Exception JavaDoc{
73         Iterator JavaDoc it = steps.iterator();
74         new EditorOperator(testFileObj.getNameExt()).txtEditorPane().pushKey(KeyEvent.VK_SPACE, KeyEvent.CTRL_MASK);
75         Thread.sleep(3000);
76         while (it.hasNext()) {
77             exec(editor, (TestStep) it.next());
78         }
79     }
80     
81     protected void exec(final JEditorPane JavaDoc editor, TestStep step) throws Exception JavaDoc {
82         try {
83             BaseDocument doc = (BaseDocument) editor.getDocument();
84             ref(step.toString());
85             // insert prefix and set cursor
86
doc.insertString(step.getOffset(), "\n" + step.getPrefix(), null);
87             CompletionJListOperator.hideAll();
88             Caret JavaDoc caret = editor.getCaret();
89             caret.setDot(step.getCursorPos());
90             Thread.currentThread().sleep(1000);
91             
92             EditorOperator eo = new EditorOperator(testFileObj.getNameExt());
93             eo.txtEditorPane().pushKey(KeyEvent.VK_SPACE, KeyEvent.CTRL_MASK);
94             
95             Thread.currentThread().sleep(2000);
96             int rowStart = Utilities.getRowStart(doc, step.getOffset() + 1);
97             int rowEnd = Utilities.getRowEnd(doc, step.getOffset() + 1);
98             String JavaDoc result = doc.getText(new int[] {rowStart, rowEnd});
99             if (!result.equals(step.getResult())) {
100                 ref("EE: unexpected CC result:\n< " + result + "\n> "
101                         + step.getResult());
102             }
103             // don't write end cursor possition in Autocompletion tests until issue #78246 is fixed
104
// ref("End cursor position = " + caret.getDot());
105
} finally {
106             Thread.currentThread().sleep(500); //XXX
107
// undo all changes
108
final UndoAction ua = (UndoAction)SystemAction.get(UndoAction.class);
109             assertNotNull("Cannot obtain UndoAction", ua);
110             while (ua.isEnabled()) {
111                 runInAWT(new Runnable JavaDoc() {
112                     public void run() {
113                         ua.performAction();
114                     }
115                 });
116                 Thread.currentThread().sleep(50); //XXX
117
}
118             Thread.currentThread().sleep(500);
119         }
120         
121     }
122     
123 }
124
Popular Tags