1 19 20 21 package org.netbeans.test.web.core.syntax; 22 23 import java.awt.event.KeyEvent ; 24 import java.beans.PropertyChangeEvent ; 25 import java.beans.PropertyChangeListener ; 26 import java.io.File ; 27 import java.util.LinkedList ; 28 import javax.swing.JEditorPane ; 29 import javax.swing.SwingUtilities ; 30 import junit.framework.Test; 31 import org.netbeans.jellytools.actions.SaveAllAction; 32 import org.netbeans.jemmy.JemmyProperties; 33 import org.netbeans.junit.AssertionFailedErrorException; 34 import org.netbeans.editor.BaseDocument; 35 import org.netbeans.jellytools.EditorOperator; 36 import org.netbeans.test.web.FileObjectFilter; 37 import org.netbeans.test.web.RecurrentSuiteFactory; 38 import org.netbeans.test.web.Waiter; 39 import org.openide.cookies.EditorCookie; 40 import org.openide.cookies.EditorCookie.Observable; 41 import org.openide.filesystems.FileObject; 42 import org.openide.loaders.DataObject; 43 44 48 public class IndentationTest extends CompletionTest{ 49 private static final String startStep = "<!--CC"; 50 private static final String endStep="-->"; 51 52 53 public IndentationTest(String name, FileObject testFileObj) { 54 super(name, testFileObj); 55 } 56 57 public static Test suite() { 58 File datadir = new AutoCompletionTest(null, null).getDataDir(); 60 File projectsDir = new File (datadir, "IndentationTestProjects"); 61 FileObjectFilter filter = new FileObjectFilter() { 62 public boolean accept(FileObject fObject) { 63 String ext = fObject.getExt(); 64 String name = fObject.getName(); 65 return (name.startsWith("test") || name.startsWith("Test")) 66 && (xmlExts.contains(ext) || jspExts.contains(ext) || jspExts.equals("java")); 67 } 68 }; 69 return RecurrentSuiteFactory.createSuite(IndentationTest.class, projectsDir, filter); 70 } 71 72 73 public void runTest() throws Exception { 74 try { 75 DataObject dataObj = DataObject.find(testFileObj); 77 final EditorCookie.Observable ed = (Observable) dataObj.getCookie(Observable.class); 78 79 final Waiter waiter = new Waiter(); 81 final PropertyChangeListener pcl = new PropertyChangeListener () { 82 public void propertyChange(PropertyChangeEvent evt) { 83 if (evt.getPropertyName().equals(Observable.PROP_OPENED_PANES)) { 84 waiter.notifyFinished(); 85 } 86 } 87 }; 88 ed.addPropertyChangeListener(pcl); 89 BaseDocument doc = (BaseDocument) ed.openDocument(); 91 ed.open(); 92 assertTrue("The editor pane was not opened in 10 secs.", waiter.waitFinished(10000)); 94 ed.removePropertyChangeListener(pcl); 95 Thread.currentThread().sleep(2000); 97 final LinkedList <JEditorPane > listPane = new LinkedList <JEditorPane >(); 98 Runnable runnable = new Runnable (){ 99 public void run(){ 100 listPane.add(ed.getOpenedPanes()[0]); 101 } 102 }; 103 SwingUtilities.invokeAndWait(runnable); 104 JEditorPane editor = listPane.getFirst(); 105 String text = doc.getText(0, doc.getLength()); 106 int endPosition = 0; 107 int actualPosition = text.indexOf(startStep, 0); int currentDispatchingModel = JemmyProperties.getCurrentDispatchingModel(); 109 JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK); 110 while (actualPosition != -1){ endPosition=text.indexOf(endStep, actualPosition); doc.remove(actualPosition, endPosition+endStep.length()-actualPosition); 117 editor.getCaret().setDot(actualPosition); 118 Thread.currentThread().sleep(500); 119 EditorOperator eOperator = new EditorOperator(testFileObj.getNameExt()); 123 eOperator.pushKey(KeyEvent.VK_ENTER); 124 Thread.currentThread().sleep(1500); 127 doc.insertString(editor.getCaret().getDot(), "|", null); 128 Thread.currentThread().sleep(1000); 129 text = doc.getText(0, doc.getLength()); 130 actualPosition = text.indexOf(startStep, actualPosition); } 132 JemmyProperties.setCurrentDispatchingModel(currentDispatchingModel); 133 ref(doc.getText(0, doc.getLength())); new SaveAllAction().performAPI(); 135 } catch (Exception ex) { 136 throw new AssertionFailedErrorException(ex); 137 } 138 ending(); 139 } 140 141 } 142 | Popular Tags |