visualweb.woodstock.webui.jsf/test/qa-functional/src/org/netbeans/modules/visualweb/test/components/composite/CompositeComponentsTest.java
author Jesse Glick <jglick@netbeans.org>
Wed, 23 Mar 2011 17:17:42 -0400
changeset 3214 cf80c1d5c3ea
parent 2930 7d06d7ce6d0d
permissions -rw-r--r--
Really making tests compilable.
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
     5  *
     6  * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
     7  * Other names may be trademarks of their respective owners.
     8  *
     9  * The contents of this file are subject to the terms of either the GNU
    10  * General Public License Version 2 only ("GPL") or the Common
    11  * Development and Distribution License("CDDL") (collectively, the
    12  * "License"). You may not use this file except in compliance with the
    13  * License. You can obtain a copy of the License at
    14  * http://www.netbeans.org/cddl-gplv2.html
    15  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    16  * specific language governing permissions and limitations under the
    17  * License.  When distributing the software, include this License Header
    18  * Notice in each file and include the License file at
    19  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    20  * particular file as subject to the "Classpath" exception as provided
    21  * by Oracle in the GPL Version 2 section of the License file that
    22  * accompanied this code. If applicable, add the following below the
    23  * License Header, with the fields enclosed by brackets [] replaced by
    24  * your own identifying information:
    25  * "Portions Copyrighted [year] [name of copyright owner]"
    26  *
    27  * Contributor(s):
    28  *
    29  * The Original Software is NetBeans. The Initial Developer of the Original
    30  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
    31  * Microsystems, Inc. All Rights Reserved.
    32  *
    33  * If you wish your version of this file to be governed by only the CDDL
    34  * or only the GPL Version 2, indicate your decision by adding
    35  * "[Contributor] elects to include this software in this distribution
    36  * under the [CDDL or GPL Version 2] license." If you do not indicate a
    37  * single choice of license, a recipient has the option to distribute
    38  * your version of this file under either the CDDL, the GPL Version 2 or
    39  * to extend the choice of license to its licensees as provided above.
    40  * However, if you add GPL Version 2 code and therefore, elected the GPL
    41  * Version 2 license, then the option applies only if the new code is
    42  * made subject to such option by the copyright holder.
    43  */
    44 package org.netbeans.modules.visualweb.test.components.composite;
    45 
    46 import junit.framework.Test;
    47 import junit.framework.TestSuite;
    48 import org.netbeans.jellytools.Bundle;
    49 import org.netbeans.jellytools.JellyTestCase;
    50 import org.netbeans.jellytools.OutputTabOperator;
    51 import org.netbeans.jellytools.ProjectsTabOperator;
    52 import org.netbeans.jellytools.actions.SaveAllAction;
    53 import org.netbeans.jellytools.nodes.Node;
    54 import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode;
    55 import org.netbeans.junit.NbTestSuite;
    56 import org.netbeans.modules.visualweb.gravy.Action;
    57 import org.netbeans.modules.visualweb.gravy.EditorOperator;
    58 import org.netbeans.modules.visualweb.gravy.TestUtils;
    59 import org.netbeans.modules.visualweb.gravy.Util;
    60 import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
    61 import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
    62 import org.netbeans.modules.visualweb.test.components.util.PaletteHelper;
    63 
    64 import static org.netbeans.modules.visualweb.test.components.util.ComponentUtils.selectForm1Component;
    65 import static org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator.switchToDesignerPane;
    66 import static org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator.switchToJSPSource;
    67 
    68 /**
    69  * @author Martin Schovanek (Martin.Schovanek@sun.com)
    70  */
    71 public class CompositeComponentsTest extends JellyTestCase {
    72 
    73     private String projectName;
    74     private boolean projectDeployed;
    75 
    76     public CompositeComponentsTest(String testName) {
    77         super(testName);
    78         dumpScreen = false;
    79     }
    80 
    81     public static Test suite() {
    82         TestSuite suite = new NbTestSuite();
    83         suite.addTest(new CompositeComponentsTest("testAccordion"));
    84         suite.addTest(new CompositeComponentsTest("testBubbleHelp"));
    85         suite.addTest(new CompositeComponentsTest("testMenu"));
    86         suite.addTest(new CheckIDELogTest("testCheckIDELog"));
    87         return suite;
    88     }
    89 
    90     /** method called before each testcase
    91      */
    92     @Override
    93     protected void setUp() {
    94         System.out.println(">> Running Test: " + getName() + " >>>>>>>>>>>>>>>");
    95         // Component Project so create a new Web Project
    96         if (getName().startsWith("test")) {
    97             projectName = getName().substring(4) + "TestPrj";
    98         } else {
    99             fail("Illegal test name, it must start with 'test' prefix");
   100         }
   101         ComponentUtils.createProject(projectName);
   102         // wait for project creation
   103         TestUtils.wait(10000);
   104 //        ProjectSupport.waitScanFinished();
   105         projectDeployed = false;
   106         // Workaround for issue
   107         switchToJSPSource();
   108         TestUtils.wait(2000);
   109         switchToDesignerPane();
   110     }
   111 
   112     /** method called after each testcase
   113      */
   114     @Override
   115     protected void tearDown() {
   116         // Close and Undeploy the project
   117         new SaveAllAction().performAPI(); // Prevents from Save Modified Files dialog.
   118         Node prjNode = new ProjectsTabOperator().getProjectRootNode(projectName);
   119         new Action(null, CLOSE).perform(prjNode);
   120         if (projectDeployed) {
   121             log("** Undeploing project: " + projectName);
   122             undeployWebApp(projectName);
   123             log("** Undeploy done");
   124         }
   125         log("<< Finished Test: " + getName() + " <<<<<<<<<<<<<<<<<");
   126     }
   127 
   128     public void testAccordion() {
   129         // Add Accordion component
   130         PaletteHelper.COMPOSITE.addComponent("Accordion", 50, 50, "id=testAcrd");
   131         // Add Accordion Tab component
   132         PaletteHelper.COMPOSITE.addComponent("AccordionTab", 75, 100,
   133                 "id=testAccrdTab\n" +
   134                 "contentHeight=133px");
   135         // Add a Static Text into the tab
   136         PaletteHelper.BASIC.addComponent("StaticText", 75, 150,
   137                 "id=stext1\n" +
   138                 "text=Accordion Tab Text\n" +
   139                 "toolTip=Accordion Tab Text Tooltip");
   140         new SaveAllAction().perform();
   141         // Verify JSP source
   142         switchToJSPSource();
   143         assertEditorContains(getEditorOperator("Page1"), new String[]{
   144                     "<webuijsf:accordion ",
   145                     "<webuijsf:accordionTab ",
   146                     "<webuijsf:staticText ",
   147                     " id=\"testAcrd\"",
   148                     " id=\"testAccrdTab\"",
   149                     " id=\"stext1\"",
   150                     " contentHeight=\"133px\""
   151                 });
   152         switchToDesignerPane();
   153         deployProject(projectName);
   154     }
   155 
   156     public void testBubbleHelp() {
   157         // Add Bubble Help component
   158         PaletteHelper.COMPOSITE.addComponent("Bubble", 50, 50,
   159                 "id=testBubble\n" +
   160                 "title=Bubble Help Test");
   161         // Add a Static Text into the component
   162         PaletteHelper.BASIC.addComponent("StaticText", 50 + 36, 50 + 59,
   163                 "id=stext1\n" +
   164                 "text=Bubble Help Text\n" +
   165                 "toolTip=Bubble Help Text Tooltip");
   166         new SaveAllAction().perform();
   167         // Verify JSP source
   168         switchToJSPSource();
   169         assertEditorContains(getEditorOperator("Page1"), new String[]{
   170                     "<webuijsf:bubble ",
   171                     " id=\"testBubble\"",
   172                     "<webuijsf:staticText ",
   173                     " id=\"stext1\""
   174                 });
   175         switchToDesignerPane();
   176         deployProject(projectName);
   177     }
   178 
   179     public void testMenu() {
   180         // Add Menu component
   181         PaletteHelper.COMPOSITE.addComponent("Menu", 50, 50, null);
   182         selectForm1Component("menu1");
   183         SheetTableOperator sheet = new SheetTableOperator();
   184         sheet.setTextValue("id", "testMenu");
   185         sheet.setCheckBoxValue("visible", "true");
   186         new SaveAllAction().perform();
   187         // Verify JSP source
   188         switchToJSPSource();
   189         assertEditorContains(getEditorOperator("Page1"), new String[]{
   190                     "<webuijsf:menu ",
   191                     " id=\"testMenu\"",
   192                     " visible=\"true\""
   193                 });
   194         switchToDesignerPane();
   195         deployProject(projectName);
   196     }
   197 
   198     @Override
   199     public void log(String msg) {
   200         super.log(msg);
   201         System.out.println(msg);
   202     }
   203 
   204     // TODO: move all this private utility methods into parent or Util clases
   205     private void waitBuildSuccessful(String projectName) {
   206         OutputTabOperator console = new OutputTabOperator(projectName);
   207         console.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 180000);
   208         console.waitText("BUILD SUCCESSFUL");
   209     }
   210 
   211     private void undeployWebApp(String app) {
   212         // XXX strings should come from Bundles
   213         String path = "Applications|Web Applications|" + app;
   214         Node webAppNode = new Node(J2eeServerNode.invoke("GlassFish"), path);
   215         new Action(null, "Undeploy").perform(webAppNode);
   216         projectDeployed = false;
   217     }
   218 
   219     private void deployProject(String prj) {
   220         log("** Deploy from menu");
   221         // XXX Add UndeploAndDeploy action into Jellytools
   222         Node prjNode = new ProjectsTabOperator().getProjectRootNode(projectName);
   223         new Action(null, UNDEPLOY_AND_DEPLOY).perform(prjNode);
   224         Util.wait(15000);
   225         waitBuildSuccessful(projectName);
   226         projectDeployed = true;
   227     }
   228 
   229     private EditorOperator getEditorOperator(String name) {
   230         return new EditorOperator(Util.getMainWindow(), name);
   231     }
   232 
   233     private void assertEditorContains(EditorOperator editor, String[] checkedItems) {
   234         for (String str : checkedItems) {
   235             assertTrue("Editor soource does not contain: " + str + "\n\nSOURCE DUMP:\n" + editor.getText(),
   236                     editor.contains(str));
   237         }
   238     }
   239     private static final String UNDEPLOY_AND_DEPLOY = Bundle.getStringTrimmed(
   240             "org.netbeans.modules.web.project.ui.Bundle",
   241             "LBL_RedeployAction_Name");
   242     private static final String CLOSE = Bundle.getStringTrimmed(
   243             "org.netbeans.modules.web.project.ui.customizer.Bundle",
   244             "CTL_WebSourceRootsUi_Close");
   245 }