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