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-2008 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.modules.visualweb.test.components.composite;
042:
043: import junit.framework.Test;
044: import junit.framework.TestSuite;
045: import org.netbeans.jellytools.Bundle;
046: import org.netbeans.jellytools.OutputTabOperator;
047: import org.netbeans.jellytools.ProjectsTabOperator;
048: import org.netbeans.jellytools.actions.SaveAllAction;
049: import org.netbeans.jellytools.nodes.Node;
050: import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode;
051: import org.netbeans.junit.NbTestSuite;
052: import org.netbeans.junit.ide.ProjectSupport;
053: import org.netbeans.modules.visualweb.gravy.Action;
054: import org.netbeans.modules.visualweb.gravy.EditorOperator;
055: import org.netbeans.modules.visualweb.gravy.RaveTestCase;
056: import org.netbeans.modules.visualweb.gravy.TestUtils;
057: import org.netbeans.modules.visualweb.gravy.Util;
058: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
059: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
060: import org.netbeans.modules.visualweb.test.components.util.PaletteHelper;
061:
062: import static org.netbeans.modules.visualweb.test.components.util.ComponentUtils.selectForm1Component;
063: import static org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator.switchToDesignerPane;
064: import static org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator.switchToJSPSource;
065:
066: /**
067: * @author Martin Schovanek (Martin.Schovanek@sun.com)
068: */
069: public class CompositeComponentsTest extends RaveTestCase {
070:
071: private String projectName;
072: private boolean projectDeployed;
073:
074: public CompositeComponentsTest(String testName) {
075: super (testName);
076: dumpScreen = false;
077: }
078:
079: public static Test suite() {
080: TestSuite suite = new NbTestSuite();
081: suite.addTest(new CompositeComponentsTest("testAccordion"));
082: suite.addTest(new CompositeComponentsTest("testBubbleHelp"));
083: suite.addTest(new CompositeComponentsTest("testMenu"));
084: suite.addTest(new CheckIDELogTest("testCheckIDELog"));
085: return suite;
086: }
087:
088: /** method called before each testcase
089: */
090: @Override
091: protected void setUp() {
092: System.out.println(">> Running Test: " + getName()
093: + " >>>>>>>>>>>>>>>");
094: // Component Project so create a new Web Project
095: if (getName().startsWith("test")) {
096: projectName = getName().substring(4) + "TestPrj";
097: } else {
098: fail("Illegal test name, it must start with 'test' prefix");
099: }
100: ComponentUtils.createProject(projectName);
101: // wait for project creation
102: TestUtils.wait(10000);
103: ProjectSupport.waitScanFinished();
104: projectDeployed = false;
105: // Workaround for issue
106: switchToJSPSource();
107: TestUtils.wait(2000);
108: switchToDesignerPane();
109: }
110:
111: /** method called after each testcase
112: */
113: @Override
114: protected void tearDown() {
115: // Close and Undeploy the project
116: new SaveAllAction().performAPI(); // Prevents from Save Modified Files dialog.
117: Node prjNode = new ProjectsTabOperator()
118: .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,
131: "id=testAcrd");
132: // Add Accordion Tab component
133: PaletteHelper.COMPOSITE.addComponent("AccordionTab", 75, 100,
134: "id=testAccrdTab\n" + "contentHeight=133px");
135: // Add a Static Text into the tab
136: PaletteHelper.BASIC.addComponent("StaticText", 75, 150,
137: "id=stext1\n" + "text=Accordion Tab Text\n"
138: + "toolTip=Accordion Tab Text Tooltip");
139: new SaveAllAction().perform();
140: // Verify JSP source
141: switchToJSPSource();
142: assertEditorContains(getEditorOperator("Page1"), new String[] {
143: "<webuijsf:accordion ", "<webuijsf:accordionTab ",
144: "<webuijsf:staticText ", " id=\"testAcrd\"",
145: " id=\"testAccrdTab\"", " id=\"stext1\"",
146: " contentHeight=\"133px\"" });
147: switchToDesignerPane();
148: deployProject(projectName);
149: }
150:
151: public void testBubbleHelp() {
152: // Add Bubble Help component
153: PaletteHelper.COMPOSITE.addComponent("Bubble", 50, 50,
154: "id=testBubble\n" + "title=Bubble Help Test");
155: // Add a Static Text into the component
156: PaletteHelper.BASIC.addComponent("StaticText", 50 + 36,
157: 50 + 59, "id=stext1\n" + "text=Bubble Help Text\n"
158: + "toolTip=Bubble Help Text Tooltip");
159: new SaveAllAction().perform();
160: // Verify JSP source
161: switchToJSPSource();
162: assertEditorContains(getEditorOperator("Page1"), new String[] {
163: "<webuijsf:bubble ", " id=\"testBubble\"",
164: "<webuijsf:staticText ", " id=\"stext1\"" });
165: switchToDesignerPane();
166: deployProject(projectName);
167: }
168:
169: public void testMenu() {
170: // Add Menu component
171: PaletteHelper.COMPOSITE.addComponent("Menu", 50, 50, null);
172: selectForm1Component("menu1");
173: SheetTableOperator sheet = new SheetTableOperator();
174: sheet.setTextValue("id", "testMenu");
175: sheet.setCheckBoxValue("visible", "true");
176: new SaveAllAction().perform();
177: // Verify JSP source
178: switchToJSPSource();
179: assertEditorContains(getEditorOperator("Page1"), new String[] {
180: "<webuijsf:menu ", " id=\"testMenu\"",
181: " visible=\"true\"" });
182: switchToDesignerPane();
183: deployProject(projectName);
184: }
185:
186: @Override
187: public void log(String msg) {
188: super .log(msg);
189: System.out.println(msg);
190: }
191:
192: // TODO: move all this private utility methods into parent or Util clases
193: private void waitBuildSuccessful(String projectName) {
194: OutputTabOperator console = new OutputTabOperator(projectName);
195: console.getTimeouts().setTimeout(
196: "ComponentOperator.WaitStateTimeout", 180000);
197: console.waitText("BUILD SUCCESSFUL");
198: }
199:
200: private void undeployWebApp(String app) {
201: // XXX strings should come from Bundles
202: String path = "Applications|Web Applications|" + app;
203: Node webAppNode = new Node(J2eeServerNode.invoke("GlassFish"),
204: path);
205: new Action(null, "Undeploy").perform(webAppNode);
206: projectDeployed = false;
207: }
208:
209: private void deployProject(String prj) {
210: log("** Deploy from menu");
211: // XXX Add UndeploAndDeploy action into Jellytools
212: Node prjNode = new ProjectsTabOperator()
213: .getProjectRootNode(projectName);
214: new Action(null, UNDEPLOY_AND_DEPLOY).perform(prjNode);
215: Util.wait(15000);
216: waitBuildSuccessful(projectName);
217: projectDeployed = true;
218: }
219:
220: private EditorOperator getEditorOperator(String name) {
221: return new EditorOperator(Util.getMainWindow(), name);
222: }
223:
224: private void assertEditorContains(EditorOperator editor,
225: String[] checkedItems) {
226: for (String str : checkedItems) {
227: assertTrue("Editor soource does not contain: " + str
228: + "\n\nSOURCE DUMP:\n" + editor.getText(), editor
229: .contains(str));
230: }
231: }
232:
233: private static final String UNDEPLOY_AND_DEPLOY = Bundle
234: .getStringTrimmed(
235: "org.netbeans.modules.web.project.ui.Bundle",
236: "LBL_RedeployAction_Name");
237: private static final String CLOSE = Bundle.getStringTrimmed(
238: "org.netbeans.modules.web.project.ui.customizer.Bundle",
239: "CTL_WebSourceRootsUi_Close");
240: }
|