KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.JEditorPane JavaDoc;
25 import javax.swing.text.Caret JavaDoc;
26 import junit.framework.Test;
27 import org.netbeans.editor.Utilities;
28 import org.netbeans.jellytools.EditorOperator;
29 import org.netbeans.editor.BaseDocument;
30 import org.netbeans.test.web.FileObjectFilter;
31 import org.netbeans.test.web.RecurrentSuiteFactory;
32 import org.openide.actions.UndoAction;
33 import org.openide.filesystems.FileObject;
34 import org.openide.util.actions.SystemAction;
35
36 /**
37  *
38  * @author jindra
39  */

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