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-2007 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: package org.netbeans.test.cnd;
042:
043: import org.netbeans.jellytools.Bundle;
044: import org.netbeans.jellytools.JellyTestCase;
045: import org.netbeans.jellytools.MainWindowOperator;
046: import org.netbeans.jellytools.NbDialogOperator;
047: import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
048: import org.netbeans.jellytools.NewProjectWizardOperator;
049: import org.netbeans.jellytools.ProjectsTabOperator;
050: import org.netbeans.jellytools.TopComponentOperator;
051: import org.netbeans.jellytools.actions.Action;
052: import org.netbeans.jellytools.actions.ActionNoBlock;
053: import org.netbeans.jellytools.nodes.Node;
054: import org.netbeans.jemmy.TimeoutExpiredException;
055: import org.netbeans.jemmy.operators.JTreeOperator;
056: import org.netbeans.junit.NbTestSuite;
057:
058: /** CND commit validation suite.
059: *
060: * @author ap153252
061: */
062: public class CNDValidation extends JellyTestCase {
063:
064: /** Creates a new instance of CNDValidation */
065: public CNDValidation(String name) {
066: super (name);
067: }
068:
069: /** Defines order of test cases.
070: * @return NbTestSuite instance
071: */
072: public static NbTestSuite suite() {
073: NbTestSuite suite = new NbTestSuite();
074: suite.addTest(new CNDValidation("testCreateSampleProject"));
075: suite.addTest(new CNDValidation("testClassView"));
076: suite.addTest(new CNDValidation("testBuildProject"));
077: return suite;
078: }
079:
080: /** Setup before every test case. */
081: public void setUp() {
082: System.out.println("######## " + getName() + " #######");
083: }
084:
085: /** Clean up after every test case. */
086: public void tearDown() {
087: }
088:
089: private static final String SAMPLE_PROJECT_NAME = "Welcome";
090:
091: /** Test new project
092: * - open new project wizard
093: * - select Samples|C/C++ Development|C/C++ category
094: * - select Welcome project
095: * - wait until wizard and Opening projects dialogs are closed
096: * - close possible error dialogs when compiler is not found
097: * - check project node appears in project view
098: */
099: public void testCreateSampleProject() {
100: NewProjectWizardOperator npwo = NewProjectWizardOperator
101: .invoke();
102: // "Samples"
103: String samplesLabel = Bundle.getStringTrimmed(
104: "org.netbeans.modules.project.ui.Bundle",
105: "Templates/Project/Samples");
106: String develLabel = Bundle
107: .getStringTrimmed(
108: "org.netbeans.modules.cnd.makeproject.ui.wizards.Bundle",
109: "Templates/Project/Samples/Native");
110: String ccLabel = Bundle
111: .getStringTrimmed(
112: "org.netbeans.modules.cnd.makeproject.ui.wizards.Bundle",
113: "Templates/Project/Samples/Native/CCPP");
114: npwo.selectCategory(samplesLabel + "|" + develLabel + "|"
115: + ccLabel);
116: npwo.selectProject(SAMPLE_PROJECT_NAME);
117: npwo.next();
118: NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
119: npnlso.txtProjectName().setText(SAMPLE_PROJECT_NAME);
120: npnlso.txtProjectLocation().setText(
121: System.getProperty("netbeans.user")); // NOI18N
122: npnlso.btFinish().pushNoBlock();
123: npnlso.getTimeouts().setTimeout(
124: "ComponentOperator.WaitStateTimeout", 120000);
125: npnlso.waitClosed();
126: // Opening Projects
127: String openingProjectsTitle = Bundle.getString(
128: "org.netbeans.modules.project.ui.Bundle",
129: "LBL_Opening_Projects_Progress");
130: try {
131: // wait at most 120 second until progress dialog dismiss
132: NbDialogOperator openingOper = new NbDialogOperator(
133: openingProjectsTitle);
134: openingOper.getTimeouts().setTimeout(
135: "ComponentOperator.WaitStateTimeout", 120000);
136: openingOper.waitClosed();
137: } catch (TimeoutExpiredException e) {
138: // ignore when progress dialog was closed before we started to wait for it
139: }
140: do {
141: try {
142: // wait for error dialog if compiler is not set
143: NbDialogOperator errorOper = new NbDialogOperator(
144: "Error");
145: errorOper.close();
146: } catch (TimeoutExpiredException e) {
147: // no more error dialog => we can continue
148: break;
149: }
150: } while (true);
151: // wait project appear in projects view
152: new ProjectsTabOperator()
153: .getProjectRootNode(SAMPLE_PROJECT_NAME);
154: }
155:
156: /** Test Class View
157: * - open Window|Class View
158: * - check Welcome|main node is available
159: */
160: public void testClassView() {
161: new Action(null, "Window|Classes").perform(); // NOI18N
162: TopComponentOperator classView = new TopComponentOperator(
163: "Classes"); // NOI18N
164: new Node(new JTreeOperator(classView), SAMPLE_PROJECT_NAME
165: + "|main");
166: }
167:
168: /** Test build project
169: * - call Clean and Build on project node
170: * - if compiler is not set, close 'Resolve Missing...' dialog
171: * - otherwise wait for clean and build finished
172: */
173: public void testBuildProject() {
174: Node projectNode = new ProjectsTabOperator()
175: .getProjectRootNode(SAMPLE_PROJECT_NAME);
176: // "Clean and Build"
177: String buildItem = Bundle.getString(
178: "org.netbeans.modules.cnd.makeproject.ui.Bundle",
179: "LBL_RebuildAction_Name");
180: // start to track Main Window status bar
181: MainWindowOperator.StatusTextTracer stt = MainWindowOperator
182: .getDefault().getStatusTextTracer();
183: stt.start();
184: new ActionNoBlock(null, buildItem).perform(projectNode);
185: try {
186: // wait for possible dialog when compiler are not set
187: NbDialogOperator resolveOper = new NbDialogOperator(
188: "Resolve Missing Native Build Tools");
189: // close and finish the test
190: resolveOper.close();
191: return;
192: } catch (TimeoutExpiredException e) {
193: // ignore when it doesn't appear
194: }
195: // wait message "Clean successful"
196: stt.waitText("Clean successful", true); // NOI18N
197: // wait message "Build successful."
198: stt.waitText(Bundle.getString(
199: "org.netbeans.modules.cnd.builds.Bundle",
200: "MSG_BuildFinishedOK"), true);
201: stt.stop();
202: }
203: }
|