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:
007: The contents of this file are subject to the terms of either the GNU
008: General Public License Version 2 only ("GPL") or the Common
009: Development and Distribution License("CDDL") (collectively, the
010: "License"). You may not use this file except in compliance with the
011: License. You can obtain a copy of the License at
012: http://www.netbeans.org/cddl-gplv2.html
013: or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
014: specific language governing permissions and limitations under the
015: License. When distributing the software, include this License Header
016: Notice in each file and include the License file at
017: nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
018: particular file as subject to the "Classpath" exception as provided
019: by Sun in the GPL Version 2 section of the License file that
020: accompanied this code. If applicable, add the following below the
021: License Header, with the fields enclosed by brackets [] replaced by
022: your own identifying information:
023: "Portions Copyrighted [year] [name of copyright owner]"
024:
025: Contributor(s):
026:
027: The Original Software is NetBeans. The Initial Developer of the Original
028: Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
029: Microsystems, Inc. All Rights Reserved.
030:
031: If you wish your version of this file to be governed by only the CDDL
032: or only the GPL Version 2, indicate your decision by adding
033: "[Contributor] elects to include this software in this distribution
034: under the [CDDL or GPL Version 2] license." If you do not indicate a
035: single choice of license, a recipient has the option to distribute
036: your version of this file under either the CDDL, the GPL Version 2 or
037: to extend the choice of license to its licensees as provided above.
038: However, if you add GPL Version 2 code and therefore, elected the GPL
039: Version 2 license, then the option applies only if the new code is
040: made subject to such option by the copyright holder.
041: */
042: package org.netbeans.test.dataprovider.common;
043:
044: import java.awt.event.*;
045: import java.util.*;
046: import java.awt.event.*;
047: import java.awt.*;
048: import javax.swing.*;
049: import javax.swing.tree.*;
050: import org.netbeans.jemmy.*;
051: import org.netbeans.jemmy.operators.*;
052: import org.netbeans.jellytools.actions.*;
053: import org.netbeans.modules.visualweb.gravy.*;
054: import org.netbeans.modules.visualweb.gravy.plugins.*;
055: import org.netbeans.modules.visualweb.gravy.designer.*;
056: import org.netbeans.modules.visualweb.gravy.dataconnectivity.*;
057: import org.netbeans.modules.visualweb.gravy.model.deployment.*;
058:
059: public class ProjectTests implements Constants {
060: private static java.util.List<String> prjNameList = new ArrayList<String>();
061: private static int indexCurrentProject = -1;
062: private static boolean is_J2EE14_PluginInstalled;
063:
064: public java.util.List<String> getPrjNameList() {
065: return Collections.unmodifiableList(prjNameList);
066: }
067:
068: public static String getCurrentPrjName() {
069: return (indexCurrentProject > -1 ? prjNameList
070: .get(indexCurrentProject) : null);
071: }
072:
073: private void addNewProject(String prjName) {
074: if (Utils.isStringEmpty(prjName))
075: return;
076: if (prjNameList.contains(prjName)) {
077: throw new RuntimeException("Project with the name: ["
078: + prjName + "] was already opened");
079: }
080: prjNameList.add(prjName);
081: indexCurrentProject = prjNameList.size() - 1;
082: }
083:
084: private void deleteProject(String prjName) {
085: if ((Utils.isStringEmpty(prjName))
086: || (!prjNameList.contains(prjName)))
087: return;
088: prjNameList.remove(prjName);
089: indexCurrentProject = prjNameList.size() - 1;
090: }
091:
092: public String createNewProject() {
093: if ((!is_J2EE14_PluginInstalled)
094: && (Utils.isUsedJ2EELevel_14())) {
095: PluginsOperator.getInstance().installAvailablePlugins(
096: J2EE_LEVEL_14_COMPATIBILITY_KIT);
097: Util.wait(500);
098: new QueueTool().waitEmpty();
099: is_J2EE14_PluginInstalled = true;
100: }
101: String errMsg = null;
102:
103: String j2EE_Level = TestPropertiesHandler
104: .getServerProperty("J2EE_Level");
105: String prjName = TestUtils.createNewProject(null, null, true,
106: PROJECT_CATEGORY_WEB, PROJECT_TYPE_WEB_APP,
107: TestPropertiesHandler
108: .getServerProperty("Source_Structure"),
109: j2EE_Level);
110: addNewProject(prjName);
111: Utils.logMsg("+++ Project [" + prjName + "] has been created");
112:
113: return errMsg;
114: }
115:
116: public String undeployCurrentProject() {
117: return undeployProject(getCurrentPrjName());
118: }
119:
120: private String undeployProject(String prjName) {
121: String errMsg = null;
122: try {
123: WebUtils.undeployProject(prjName);
124: new QueueTool().waitEmpty();
125: } catch (Throwable e) {
126: e.printStackTrace(Utils.logStream);
127: errMsg = (e.getMessage() == null ? e.toString() : e
128: .getMessage());
129: }
130: return errMsg;
131: }
132:
133: public String closeCurrentProject() {
134: return closeProject(getCurrentPrjName());
135: }
136:
137: private String closeProject(String prjName) {
138: String errMsg = null;
139: try {
140: Utils.putFocusOnWindowProjects();
141:
142: Utils.callPopupMenuOnProjectsTreeNode(prjName,
143: POPUP_MENU_ITEM_CLOSE);
144: deleteProject(prjName);
145:
146: Util.wait(2000);
147: new QueueTool().waitEmpty();
148: Utils.logMsg("+++ Project [" + prjName
149: + "] has been closed");
150: } catch (Throwable e) {
151: e.printStackTrace(Utils.logStream);
152: errMsg = (e.getMessage() == null ? e.toString() : e
153: .getMessage());
154: }
155: return errMsg;
156: }
157: }
|