001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package gui;
043:
044: import java.io.File;
045: import junit.textui.TestRunner;
046: import org.netbeans.jellytools.*;
047: import org.netbeans.jellytools.actions.NewTemplateAction;
048: import org.netbeans.jellytools.actions.PropertiesAction;
049: import org.netbeans.jellytools.nodes.FolderNode;
050: import org.netbeans.jellytools.nodes.Node;
051: import org.netbeans.jemmy.EventTool;
052: import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
053:
054: import org.netbeans.junit.NbTestSuite;
055: import org.openide.actions.SaveAllAction;
056:
057: /////////////////////
058: public class BeansTemplates extends JellyTestCase {
059:
060: private static final String NAME_JAVA_BEAN = "MyBean";
061: private static final String NAME_BEAN_INFO = "MyBeanInfo";
062: private static final String NAME_BEAN_INFO_NO_ICON = "MyBeanInfoNoIcon";
063: private static final String NAME_CUSTOMIZER = "MyCustomizer";
064: private static final String NAME_PROPERTY_EDITOR = "MyPropertyEditor";
065:
066: private static final String sampleDir = Utilities.findFileSystem(
067: "src").getDisplayName();
068:
069: /** Need to be defined because of JUnit */
070: public BeansTemplates(String name) {
071: super (name);
072: }
073:
074: public static NbTestSuite suite() {
075: NbTestSuite suite = new NbTestSuite();
076: suite.addTest(new BeansTemplates("testJavaBean"));
077: suite.addTest(new BeansTemplates("testBeanInfo"));
078: suite.addTest(new BeansTemplates("testBeanInfoNoIcon"));
079: suite.addTest(new BeansTemplates("testCustomizer"));
080: suite.addTest(new BeansTemplates("testPropertyEditor"));
081: return suite;
082: }
083:
084: /** Use for execution inside IDE */
085: public static void main(java.lang.String[] args) {
086: // run whole suite
087: TestRunner.run(suite());
088: // run only selected test case
089: //junit.textui.TestRunner.run(new BeansTemplates("testJavaBean"));
090: }
091:
092: public void setUp() {
093: System.out.println("######## " + getName() + " #######");
094: new PropertiesAction().perform();
095: }
096:
097: public void tearDown() {
098: ((SaveAllAction) SaveAllAction.findObject(SaveAllAction.class,
099: true)).performAction();
100:
101: Utilities.delete(NAME_JAVA_BEAN + ".java");
102: Utilities.delete(NAME_BEAN_INFO + ".java");
103: Utilities.delete(NAME_BEAN_INFO_NO_ICON + ".java");
104: Utilities.delete(NAME_CUSTOMIZER + ".java");
105: Utilities.delete(NAME_PROPERTY_EDITOR + ".java");
106: }
107:
108: public void testJavaBean() {
109: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
110: Node repositoryRootNode = new RepositoryTabOperator()
111: .getRootNode();
112: FolderNode examplesFolderNode = new FolderNode(
113: repositoryRootNode.tree(), sampleDir); // NOI18N
114: examplesFolderNode.select();
115: DefaultStringComparator comparator = new DefaultStringComparator(
116: true, true);
117: new NewTemplateAction().perform();
118: NewWizardOperator newWizardOper = new NewWizardOperator();
119: ChooseTemplateStepOperator ctso = new ChooseTemplateStepOperator();
120: ctso.setComparator(comparator);
121: String bean = Bundle.getString(
122: "org.netbeans.modules.beans.Bundle", "Templates/Beans")
123: + "|"
124: + Bundle.getString("org.netbeans.modules.beans.Bundle",
125: "Templates/Beans/Bean.java");
126: new EventTool().waitNoEvent(1000);
127: ctso.selectTemplate(bean);
128: ctso.next();
129: TargetLocationStepOperator tlso = new TargetLocationStepOperator();
130: tlso.setName(NAME_JAVA_BEAN);
131: tlso.tree().setComparator(comparator);
132: tlso.selectLocation(sampleDir);
133: tlso.finish();
134: new EventTool().waitNoEvent(10000);
135:
136: writeResult(NAME_JAVA_BEAN);
137: compareReferenceFiles();
138: }
139:
140: private void writeResult(String name) {
141: new EventTool().waitNoEvent(1000);
142: new EditorOperator(name);
143: ref(Utilities.unify(Utilities.getAsString(name + ".java")));
144: new EventTool().waitNoEvent(500);
145: }
146:
147: public void testBeanInfo() {
148: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
149: Node repositoryRootNode = new RepositoryTabOperator()
150: .getRootNode();
151: FolderNode examplesFolderNode = new FolderNode(
152: repositoryRootNode.tree(), sampleDir); // NOI18N
153: examplesFolderNode.select();
154: DefaultStringComparator comparator = new DefaultStringComparator(
155: true, true);
156: new NewTemplateAction().perform();
157: NewWizardOperator newWizardOper = new NewWizardOperator();
158: ChooseTemplateStepOperator ctso = new ChooseTemplateStepOperator();
159: String bean = Bundle.getString(
160: "org.netbeans.modules.beans.Bundle", "Templates/Beans")
161: + "|"
162: + Bundle.getString("org.netbeans.modules.beans.Bundle",
163: "Templates/Beans/BeanInfo.java");
164: new EventTool().waitNoEvent(1000);
165: ctso.selectTemplate(bean);
166: ctso.next();
167: TargetLocationStepOperator tlso = new TargetLocationStepOperator();
168: tlso.setName(NAME_BEAN_INFO);
169: tlso.tree().setComparator(comparator);
170: tlso.selectLocation(sampleDir);
171: tlso.finish();
172:
173: writeResult(NAME_BEAN_INFO);
174: compareReferenceFiles();
175: }
176:
177: public void testBeanInfoNoIcon() {
178: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
179: Node repositoryRootNode = new RepositoryTabOperator()
180: .getRootNode();
181: FolderNode examplesFolderNode = new FolderNode(
182: repositoryRootNode.tree(), sampleDir); // NOI18N
183: examplesFolderNode.select();
184: DefaultStringComparator comparator = new DefaultStringComparator(
185: true, true);
186: new NewTemplateAction().perform();
187: NewWizardOperator newWizardOper = new NewWizardOperator();
188: ChooseTemplateStepOperator ctso = new ChooseTemplateStepOperator();
189: String bean = Bundle.getString(
190: "org.netbeans.modules.beans.Bundle", "Templates/Beans")
191: + "|"
192: + Bundle.getString("org.netbeans.modules.beans.Bundle",
193: "Templates/Beans/BeanInfoNoIcon.java");
194: new EventTool().waitNoEvent(1000);
195: ctso.selectTemplate(bean);
196: ctso.next();
197: TargetLocationStepOperator tlso = new TargetLocationStepOperator();
198: tlso.setName(NAME_BEAN_INFO_NO_ICON);
199: tlso.tree().setComparator(comparator);
200: tlso.selectLocation(sampleDir);
201: tlso.finish();
202:
203: writeResult(NAME_BEAN_INFO_NO_ICON);
204: compareReferenceFiles();
205: }
206:
207: public void testCustomizer() {
208: MainWindowOperator mainWindowOper = MainWindowOperator
209: .getDefault();
210: // mainWindowOper.switchToGUIEditingWorkspace();
211: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
212: Node repositoryRootNode = new RepositoryTabOperator()
213: .getRootNode();
214: FolderNode examplesFolderNode = new FolderNode(
215: repositoryRootNode.tree(), sampleDir); // NOI18N
216: examplesFolderNode.select();
217: DefaultStringComparator comparator = new DefaultStringComparator(
218: true, true);
219: new NewTemplateAction().perform();
220: NewWizardOperator newWizardOper = new NewWizardOperator();
221: ChooseTemplateStepOperator ctso = new ChooseTemplateStepOperator();
222: String bean = Bundle.getString(
223: "org.netbeans.modules.beans.Bundle", "Templates/Beans")
224: + "|"
225: + Bundle.getString("org.netbeans.modules.beans.Bundle",
226: "Templates/Beans/Customizer.java");
227: new EventTool().waitNoEvent(1000);
228: ctso.selectTemplate(bean);
229: ctso.next();
230: TargetLocationStepOperator tlso = new TargetLocationStepOperator();
231: tlso.setName(NAME_CUSTOMIZER);
232: tlso.tree().setComparator(comparator);
233: tlso.selectLocation(sampleDir);
234: tlso.finish();
235:
236: writeResult(NAME_CUSTOMIZER);
237: compareReferenceFiles();
238: }
239:
240: public void testPropertyEditor() {
241: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
242: Node repositoryRootNode = new RepositoryTabOperator()
243: .getRootNode();
244: FolderNode examplesFolderNode = new FolderNode(
245: repositoryRootNode.tree(), sampleDir); // NOI18N
246: examplesFolderNode.select();
247: DefaultStringComparator comparator = new DefaultStringComparator(
248: true, true);
249: new NewTemplateAction().perform();
250: NewWizardOperator newWizardOper = new NewWizardOperator();
251: ChooseTemplateStepOperator ctso = new ChooseTemplateStepOperator();
252: String bean = Bundle.getString(
253: "org.netbeans.modules.beans.Bundle", "Templates/Beans")
254: + "|"
255: + Bundle.getString("org.netbeans.modules.beans.Bundle",
256: "Templates/Beans/PropertyEditor.java");
257: new EventTool().waitNoEvent(1000);
258: ctso.selectTemplate(bean);
259: ctso.next();
260: TargetLocationStepOperator tlso = new TargetLocationStepOperator();
261: tlso.setName(NAME_PROPERTY_EDITOR);
262: tlso.tree().setComparator(comparator);
263: tlso.selectLocation(sampleDir);
264: tlso.finish();
265:
266: writeResult(NAME_PROPERTY_EDITOR);
267: compareReferenceFiles();
268: }
269:
270: }
|