mobility.project/test/qa-functional/src/org/netbeans/test/mobility/NewProjectFileTest.java
author asotona@netbeans.org
Tue Oct 09 10:00:23 2007 +0000 (8 months ago)
changeset 58087 e58442f16491
parent 53024f1ae61c91aae
permissions -rw-r--r--
first round of headers replacement
issue #118154
        1 /*
        2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
        3  *
        4  * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
        5  *
        6  * The contents of this file are subject to the terms of either the GNU
        7  * General Public License Version 2 only ("GPL") or the Common
        8  * Development and Distribution License("CDDL") (collectively, the
        9  * "License"). You may not use this file except in compliance with the
       10  * License. You can obtain a copy of the License at
       11  * http://www.netbeans.org/cddl-gplv2.html
       12  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
       13  * specific language governing permissions and limitations under the
       14  * License.  When distributing the software, include this License Header
       15  * Notice in each file and include the License file at
       16  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
       17  * particular file as subject to the "Classpath" exception as provided
       18  * by Sun in the GPL Version 2 section of the License file that
       19  * accompanied this code. If applicable, add the following below the
       20  * License Header, with the fields enclosed by brackets [] replaced by
       21  * your own identifying information:
       22  * "Portions Copyrighted [year] [name of copyright owner]"
       23  *
       24  * Contributor(s):
       25  *
       26  * The Original Software is NetBeans. The Initial Developer of the Original
       27  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
       28  * Microsystems, Inc. All Rights Reserved.
       29  *
       30  * If you wish your version of this file to be governed by only the CDDL
       31  * or only the GPL Version 2, indicate your decision by adding
       32  * "[Contributor] elects to include this software in this distribution
       33  * under the [CDDL or GPL Version 2] license." If you do not indicate a
       34  * single choice of license, a recipient has the option to distribute
       35  * your version of this file under either the CDDL, the GPL Version 2 or
       36  * to extend the choice of license to its licensees as provided above.
       37  * However, if you add GPL Version 2 code and therefore, elected the GPL
       38  * Version 2 license, then the option applies only if the new code is
       39  * made subject to such option by the copyright holder.
       40  */
       41 
       42 package org.netbeans.test.mobility;
       43 
       44 
       45 import java.io.File;
       46 import java.io.IOException;
       47 import java.util.HashSet;
       48 import javax.swing.JDialog;
       49 import org.netbeans.jellytools.Bundle;
       50 import org.netbeans.jellytools.EditorOperator;
       51 import org.netbeans.jellytools.MainWindowOperator;
       52 import org.netbeans.jellytools.NewProjectWizardOperator;
       53 import org.netbeans.jellytools.nodes.Node;
       54 import org.netbeans.jellytools.properties.PropertySheetOperator;
       55 import org.netbeans.jemmy.operators.DialogOperator;
       56 import org.netbeans.jemmy.operators.JButtonOperator;
       57 import org.netbeans.jemmy.operators.JMenuBarOperator;
       58 import org.netbeans.jemmy.operators.JTextFieldOperator;
       59 import org.netbeans.jemmy.operators.JTreeOperator;
       60 import org.netbeans.junit.NbTestSuite;
       61 import org.netbeans.jellytools.JellyTestCase;
       62 import org.netbeans.jellytools.NbDialogOperator;
       63 import org.netbeans.jellytools.NewFileNameLocationStepOperator;
       64 import org.netbeans.jellytools.NewFileWizardOperator;
       65 import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
       66 import org.netbeans.jellytools.ProjectsTabOperator;
       67 import org.netbeans.jellytools.TopComponentOperator;
       68 import org.netbeans.jellytools.actions.CompileAction;
       69 import org.netbeans.jellytools.nodes.SourcePackagesNode;
       70 import org.netbeans.jemmy.operators.JDialogOperator;
       71 //import org.netbeans.jemmy.operators.JToggleButtonOperator;
       72 /**
       73  */
       74 public class NewProjectFileTest extends JellyTestCase {
       75     
       76     public static final String ITEM_VISUALMIDLET = Bundle.getStringTrimmed("org.netbeans.modules.vmd.midp.resources.Bundle", "Templates/MIDP/VisualMIDlet.java");
       77     public static final String ITEM_MIDLET = Bundle.getStringTrimmed("org.netbeans.modules.mobility.project.ui.wizard.Bundle", "Templates/MIDP/Midlet.java");
       78     public static final String ITEM_MIDPCANVAS = Bundle.getStringTrimmed("org.netbeans.modules.mobility.project.ui.wizard.Bundle", "Templates/MIDP/MIDPCanvas.java");
       79     public static final String ITEM_LOCALIZATIONSUPPORTCLASS = "Localization Support Class";
       80     //public static final String ITEM_HELLOVISUALMIDLET = "Hello Visual Midlet"; //template removed
       81     
       82     public static final String CATEGORY_MIDP = Bundle.getStringTrimmed("org.netbeans.modules.mobility.project.ui.wizard.Bundle", "Templates/MIDP");
       83     public static final String CATEGORY_CDC = "CDC"; //TODO I18N
       84     
       85     public static final String PROJECT_MOBILE_APP = Bundle.getStringTrimmed("org.netbeans.modules.mobility.project.ui.wizard.Bundle", "Templates/Project/J2ME/MobileApplication");
       86     public static final String PROJECT_CDC_APP = "CDC Application";//Bundle.getStringTrimmed("org.netbeans.modules.mobility.project.ui.wizard.Bundle", "Templates/Project/J2ME/MobileApplication");
       87         
       88     public static final HashSet disabledNodes = new HashSet();
       89     private static String projectDirectory;
       90     
       91     public static final String SAMPLE_MOBILE_PROJECT = "SampleMobileApplication";
       92     public static final String PROJECT_TO_BE_CREATED = "NewCreatedMobileProject";
       93     public static final String PROJECT_TO_BE_CLOSED = "ProjectToBeClosedMobile";
       94     public static final String PROJECT_TO_BE_OPENED = "OpenMobileProject";
       95     public static final String PROJECT_FOR_NEW_FILES = "CreateNewFilesMobile";
       96     public static final String PROJECT_OPENED = "MobileApplicationVisualMIDlet";
       97     
       98     public NewProjectFileTest(String name) {
       99         super(name);
      100     }
      101     
      102     /*
      103     public static NbTestSuite suite() {
      104         NbTestSuite suite = new NbTestSuite();
      105         //suite.addTest(new NewProjectFileTest("testNewProject"));//TODO can be used only when a J2ME platform is available
      106         suite.addTest(new NewProjectFileTest("testCreateNewFiles"));
      107         suite.addTest(new NewProjectFileTest("testOpenProject"));
      108         suite.addTest(new NewProjectFileTest("testCloseProject")); //must be last. It close the SampleMobileApplication project that is used in other tests.
      109         return suite;
      110     }
      111      */
      112     
      113     /** Use for execution inside IDE */
      114     public static void main(java.lang.String[] args) {
      115         
      116         junit.textui.TestRunner.run(new NewProjectFileTest("testCreateNewMIDPFilesValidation"));
      117     }
      118     
      119     public void setUp() {
      120         System.out.println("########  "+getName()+"  #######");
      121     }
      122     
      123     public void tearDown() {
      124     }
      125     
      126     
      127     public void testNewProject() throws IOException {
      128         //TODO it's necessary to have a J2ME platform to be able create Mobile Project
      129         //TODO we need a fake platform that can be used even when the mobility pack is built from sources and no regular platform is available
      130         createNewProject(PROJECT_MOBILE_APP, PROJECT_TO_BE_CREATED);
      131         // wait project appear in projects view
      132         new ProjectsTabOperator().getProjectRootNode(PROJECT_TO_BE_CREATED);
      133     }
      134     
      135     public String createNewFile(String category, String template, String name, String packageName) {
      136         NewFileWizardOperator newFile = NewFileWizardOperator.invoke(); 
      137         newFile.selectCategory(category);
      138         newFile.selectFileType(template);
      139         newFile.next();
      140         NewFileNameLocationStepOperator op = new NewFileNameLocationStepOperator();
      141         op.setObjectName(name); //TODO doesn't work with New > MIDP Canvas. It doesn;t change the name
      142         if(packageName != null) 
      143             op.setPackage(packageName);
      144         String fileLocation = op.txtCreatedFile().getText();
      145         op.finish();
      146         return fileLocation;
      147     }
      148     
      149     public String createNewProject(String projectType, String projectName) {
      150         MainWindowOperator mainWindow = MainWindowOperator.getDefault();
      151         NewProjectWizardOperator npwop = NewProjectWizardOperator.invoke();
      152         npwop.selectCategory(Bundle.getStringTrimmed("org.netbeans.modules.mobility.project.ui.wizard.Bundle", "Templates/Project/J2ME")); 
      153         npwop.selectProject(projectType); 
      154         npwop.next();
      155         NewProjectNameLocationStepOperator step = new NewProjectNameLocationStepOperator();
      156         step.txtProjectLocation().setText(getWorkDirPath());
      157         step.txtProjectName().setText(projectName);//NOI18N
      158         String projectLocation = step.txtProjectFolder().getText();
      159         sleep(1000);
      160         step.finish();
      161         return projectLocation;
      162     }
      163     
      164     public void testCloseProject() {
      165         //EditorOperator.closeDiscardAll();
      166         //select projects tab
      167         ProjectsTabOperator pto = ProjectsTabOperator.invoke();
      168         JTreeOperator tree = pto.tree();
      169         //select the project node
      170         Node projectNode = pto.getProjectRootNode(PROJECT_TO_BE_CLOSED);
      171         projectNode.select();
      172         //close it
      173         projectNode.performPopupAction("Close Project"); //TODO - I18N - get it from bundle
      174         //check that project is closed
      175         pto.getProjectRootNode(PROJECT_TO_BE_CLOSED);
      176         
      177     }
      178     
      179     public void testOpenProject() throws IOException {
      180         MainWindowOperator mainWindow = MainWindowOperator.getDefault();
      181         mainWindow.getToolbarButton(mainWindow.getToolbar("File"),"Open Project").push();//TODO I18N
      182         
      183         DialogOperator dia = new DialogOperator("Open Project"); //TODO I18N
      184         JTextFieldOperator text = new JTextFieldOperator(dia, 1);
      185         text.setText(getDataDir().getPath() +File.separator+PROJECT_TO_BE_OPENED);
      186         new JButtonOperator(dia, "Open Project Folder").push();//TODO I18N
      187         sleep(2000);
      188         JDialog resolveDialog = NbDialogOperator.findJDialog("Open Project", true, true);//TODO I18N
      189         if (resolveDialog != null) {
      190             new JButtonOperator(new JDialogOperator(resolveDialog), "Close").push();//TODO I18N
      191         }
      192         
      193         JMenuBarOperator menubar = mainWindow.menuBar();
      194         
      195         ProjectsTabOperator pto = ProjectsTabOperator.invoke();
      196         
      197         // get the tree if needed
      198         JTreeOperator tree = pto.tree();
      199         
      200         // Open HelloMidlet and Inspector
      201         Node projectNode = pto.getProjectRootNode("MobileApplication|hello|HelloMidlet.java");
      202         projectNode.select();
      203         projectNode.performPopupActionNoBlock("Open");
      204         sleep(2000);
      205         
      206         new PropertySheetOperator().close();
      207         EditorOperator.closeDiscardAll();
      208         
      209     }
      210     
      211     public void testCreateNewFiles() {
      212         //select the project in project view
      213         new ProjectsTabOperator().getProjectRootNode(PROJECT_FOR_NEW_FILES).select();
      214         //create all new files in the project
      215         createNewFile(CATEGORY_MIDP, ITEM_VISUALMIDLET, "NewVisualMidlet", "myPackage"); // NOI18N
      216         createNewFile(CATEGORY_MIDP, ITEM_MIDLET, "NewMIDlet", "myPackage"); // NOI18N
      217         createNewFile(CATEGORY_MIDP, ITEM_MIDPCANVAS, "MIDPCanvas", "myPackage"); // NOI18N
      218         
      219         
      220         //test that files are created and opened in editor
      221         new TopComponentOperator("NewVisualMidlet.java").close(); // NOI18N
      222         new EditorOperator("NewMIDlet.java").close(); // NOI18N
      223         new EditorOperator("MIDPCanvas.java").close();    // NOI18N    
      224         
      225     }
      226     
      227     public void testCreateNewMobileApplication(){
      228         //by default is the "Create HelloMidlet" checked when creating new project 
      229         String projectName = "NewMobileApplication"; // NOI18N
      230         //create
      231         String location = createNewProject(PROJECT_MOBILE_APP, projectName);
      232         System.out.println("project created : " + location); // NOI18N
      233         //check
      234         new ProjectsTabOperator().getProjectRootNode(projectName);
      235     }
      236     
      237     public void testCreateNewCDCApplication() {
      238         String projectName = "NewCDCApplication"; // NOI18N
      239         //create
      240         String location = createNewProject(PROJECT_CDC_APP, projectName);
      241         System.out.println("project created : " + location); // NOI18N
      242         //check
      243         new ProjectsTabOperator().getProjectRootNode(projectName);
      244     }
      245     
      246 ////------------------------------------- validation --------------
      247     
      248     public void testCreateNewMIDPFilesValidation() {
      249         //select the project in project view
      250         new ProjectsTabOperator().getProjectRootNode("NewMobileApplication").select(); // NOI18N
      251         //create all new files in the project
      252 
      253         createNewFile(CATEGORY_MIDP, ITEM_MIDLET, "NewMIDlet", "validation"); // NOI18N
      254         createNewFile(CATEGORY_MIDP, ITEM_MIDPCANVAS, "NewMIDPCanvas", "validation");    // NOI18N
      255         createNewFile(CATEGORY_MIDP, ITEM_VISUALMIDLET, "NewVisualMidlet", "validation"); // NOI18N
      256         
      257         //test that files are created and opened in editor
      258         new EditorOperator("NewMIDlet.java").close(); // NOI18N
      259         new EditorOperator("MIDPCanvas.java").close();  // NOI18N  //TODO: workaround for unchanged canvas name
      260         new TopComponentOperator("NewVisualMidlet.java").close(); // NOI18N //TODO: seems that this doesn't work :(
      261     }
      262     
      263     public void testCompileMobileMIDPProject() {
      264         // start to track Main Window status bar
      265         MainWindowOperator.StatusTextTracer stt = MainWindowOperator.getDefault().getStatusTextTracer();
      266         stt.start();
      267         // call Build on project node
      268         new ProjectsTabOperator().getProjectRootNode("NewMobileApplication").buildProject(); // NOI18N
      269 
      270         // wait message "Building NewMobileApplication (compile-single)..."
      271         stt.waitText("Building", true); // NOI18N
      272         // wait message "Finished building NewMobileApplication (compile-single)"
      273         stt.waitText("Finished building", true); // NOI18N
      274         stt.stop();
      275     }
      276 ////---------------------------------------------------------------
      277     public void testCreateNewMIDPCanvas() {
      278         //select the project in project view
      279         new ProjectsTabOperator().getProjectRootNode("NewMobileApplication").select(); // NOI18N
      280         //create new Canvas in the project
      281 
      282         createNewFile(CATEGORY_MIDP, ITEM_MIDPCANVAS, "NewMIDPCanvas", "validation");    // NOI18N
      283         
      284         //test that files are created and opened in editor
      285         new EditorOperator("NewMIDPCanvas.java").close();  // NOI18N
      286     }
      287     public void testCreateNewProjectIssue95668() {
      288         String projectName = PROJECT_TO_BE_CREATED + System.currentTimeMillis() ;
      289         System.out.println("creating project " + projectName); // NOI18N
      290         System.out.println("project created " + createNewProject(PROJECT_MOBILE_APP, projectName)); // NOI18N
      291         for(int i=0;i<50;i++) {
      292            new ProjectsTabOperator().getProjectRootNode(projectName).select();
      293            createNewFile(CATEGORY_MIDP, ITEM_VISUALMIDLET, "file"+i, "issue95668"); // NOI18N
      294         }
      295     }
      296     
      297 //        public void testCreateNewProjectIssue95668() {
      298 //        String projectName = PROJECT_TO_BE_CREATED + System.currentTimeMillis() ;
      299 //        System.out.println("creating project " + projectName);
      300 //        System.out.println("project created " + createNewProject(projectName));
      301 //        for(int i=0;i<50;i++) {
      302 //           new ProjectsTabOperator().getProjectRootNode(projectName).select();
      303 //           createNewFile(ITEM_VISUALMIDLET, "file"+i);
      304 //        }
      305 //    }
      306     
      307     public void testVMClosesImmediatellyIssue101539() {
      308         createNewProject(PROJECT_MOBILE_APP, "issue101539"); // NOI18N
      309         for (int i = 0; i < 20; i++) {
      310             createNewFile(CATEGORY_MIDP, ITEM_VISUALMIDLET, "issue101539_"+i, "testing"); // NOI18N
      311         }
      312         //EditorOperator.
      313     }
      314     public void sleep(int millis) {
      315         try {
      316             Thread.sleep(millis);
      317         } catch (InterruptedException ex) {
      318             ex.printStackTrace();
      319         }
      320     }
      321 }
      322