001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.test.lib;
021:
022: import java.io.File;
023: import javax.swing.SwingUtilities;
024: import org.netbeans.api.project.Project;
025: import org.netbeans.jellytools.EditorOperator;
026: import org.netbeans.jellytools.ProjectsTabOperator;
027: import org.netbeans.jellytools.nodes.Node;
028: import org.netbeans.jellytools.JellyTestCase;
029: import org.netbeans.junit.ide.ProjectSupport;
030: import org.openide.util.actions.SystemAction;
031: import org.openide.actions.UndoAction;
032: import org.openide.cookies.EditorCookie;
033: import org.openide.filesystems.FileUtil;
034: import org.openide.loaders.DataObject;
035:
036: /**
037: *
038: * @author Jindrich Sedek
039: */
040: public class BasicOpenFileTest extends JellyTestCase {
041:
042: private String projectName;
043: private EditorOperator operator;
044: private Project project;
045:
046: public BasicOpenFileTest(String str) {
047: super (str);
048: }
049:
050: protected Project openProject(String projectName) {
051: this .projectName = projectName;
052: File dataDir = getDataDir();
053: File projectDir = new File(dataDir, projectName);
054: project = (Project) ProjectSupport.openProject(projectDir);
055: return project;
056: }
057:
058: protected EditorOperator openFile(String fileName) {
059: if (projectName == null) {
060: throw new IllegalStateException(
061: "YOU MUST OPEN PROJECT FIRST");
062: }
063: Node rootNode = new ProjectsTabOperator()
064: .getProjectRootNode(projectName);
065: Node node = new Node(rootNode, "Source Packages|files|"
066: + fileName);
067: node.select();
068: node.performPopupAction("Open");
069: operator = new EditorOperator(fileName);
070: assertNotNull(operator.getText());
071: assertTrue(operator.getText().length() > 0);
072: return operator;
073: }
074:
075: protected EditorOperator openStandaloneTokenFile(String fileName)
076: throws Exception {
077: File tokensDir = new File(getDataDir(), "tokens");
078: File file = new File(tokensDir, fileName);
079: DataObject dataObj = DataObject.find(FileUtil
080: .toFileObject(file));
081: EditorCookie ed = dataObj.getCookie(EditorCookie.class);
082: ed.open();
083: operator = new EditorOperator(fileName);
084: return operator;
085: }
086:
087: protected void edit(String insertion) throws Exception {
088: operator.insert(insertion, 1, 1);
089: assertTrue(operator.getText().contains(insertion));
090: operator.save();
091: assertTrue(operator.getText().contains(insertion));
092: undo();
093: assertFalse(operator.getText().contains(insertion));
094: }
095:
096: protected void closeFile() {
097: EditorOperator.closeDiscardAll();
098: }
099:
100: protected void closeProject() {
101: ProjectSupport.closeProject(projectName);
102: }
103:
104: private void undo() throws Exception {
105: final UndoAction ua = SystemAction.get(UndoAction.class);
106: assertNotNull("Cannot obtain UndoAction", ua);
107: while (ua.isEnabled()) {
108: SwingUtilities.invokeAndWait(new Runnable() {
109: public void run() {
110: ua.performAction();
111: }
112: });
113: }
114: }
115: }
|