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.util.*;
045: import java.io.*;
046: import junit.framework.Test;
047: import junit.framework.TestSuite;
048: import junit.framework.*;
049: import org.netbeans.junit.*;
050: import org.netbeans.modules.visualweb.gravy.*;
051: import org.netbeans.jemmy.*;
052: import java.lang.reflect.*;
053:
054: public abstract class BaseTests extends RaveTestCase implements
055: Constants {
056: protected static final String STOP_TEST_BECAUSE_PREVIOUS_TEST_FAILS = "Test is not performed because a previous test has been failed";
057: protected static String errMsg;
058: protected static int webResponseCode;
059: protected static boolean isTestSuiteRunning = false,
060: isProjectCreated;
061:
062: protected static String[] TEST_METHOD_ARRAY = {
063: "testAcceptance_01", "testAcceptance_02",
064: "testAcceptance_03",
065:
066: "testAcceptance_00" };
067:
068: public BaseTests(String testName) {
069: super (testName);
070: }
071:
072: protected static <T extends BaseTests> Test suite(
073: Class<T> classTestSet, String nameTestSuite) {
074: Utils.openLog();
075: TestPropertiesHandler.readTestProperties();
076: List<String> testMethodsNames = TestPropertiesHandler
077: .getTestMethodNames(TEST_METHOD_ARRAY);
078:
079: TestSuite suite = new TestSuite(nameTestSuite);
080: for (String testMethodName : testMethodsNames) {
081: //suite.addTest(new BaseTests(testMethodName));
082: try {
083: Constructor<T> constructor = classTestSet
084: .getConstructor(String.class);
085: suite.addTest(constructor.newInstance(testMethodName));
086: } catch (Exception e) {
087: e.printStackTrace(Utils.logStream);
088: e.printStackTrace();
089: throw new RuntimeException(e);
090: }
091: }
092: return suite;
093: }
094:
095: public void testAcceptance_01() { // checkDBConnection
096: Utils.logMsg("=== testAcceptance_01() ===");
097: errMsg = null;
098: webResponseCode = -1;
099: isProjectCreated = false;
100: if (!isTestSuiteRunning) {
101: isTestSuiteRunning = true;
102: } else {
103: TestPropertiesHandler.nextTestProperties();
104: }
105:
106: if (errMsg != null)
107: fail(STOP_TEST_BECAUSE_PREVIOUS_TEST_FAILS);
108:
109: Util.wait(1000);
110:
111: errMsg = new DatabaseTests().checkDBConnection();
112: Util.wait(1000);
113: new QueueTool().waitEmpty();
114: if (errMsg != null) {
115: fail(errMsg);
116: }
117: }
118:
119: public void testAcceptance_02() { // checkAppServer
120: Utils.logMsg("=== testAcceptance_02() ===");
121: if (errMsg != null)
122: fail(STOP_TEST_BECAUSE_PREVIOUS_TEST_FAILS);
123:
124: //JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK);
125: Util.wait(1000);
126: errMsg = new AppServerTests().checkAppServer();
127: Util.wait(1000);
128: new QueueTool().waitEmpty();
129: if (errMsg != null) {
130: fail(errMsg);
131: }
132: }
133:
134: public void testAcceptance_03() { // createNewProject
135: Utils.logMsg("=== testAcceptance_03() ===");
136: if (errMsg != null)
137: fail(STOP_TEST_BECAUSE_PREVIOUS_TEST_FAILS);
138:
139: //JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK);
140: Util.wait(1000);
141: errMsg = new ProjectTests().createNewProject();
142: Util.wait(1000);
143: new QueueTool().waitEmpty();
144: if (errMsg != null) {
145: fail(errMsg);
146: }
147: isProjectCreated = true;
148: }
149:
150: public void testAcceptance_00() { // undeploy, close project
151: Utils.logMsg("=== testAcceptance_00() ===");
152: Util.wait(1000);
153: Utils.logMsg(""); // don't remove this statement
154: errMsg = null;
155: if (webResponseCode == WEB_RESPONSE_CODE_OK) {
156: errMsg = new ProjectTests().undeployCurrentProject();
157: } else {
158: Utils
159: .logMsg("+++ Project undeployment is skipped because this project wasn't deployed properly");
160: }
161: if (isProjectCreated) {
162: String errText = new ProjectTests().closeCurrentProject();
163: if (errText != null) {
164: errMsg = (errMsg == null ? errText : errMsg + " "
165: + errText);
166: }
167: }
168: Util.wait(1000);
169: new QueueTool().waitEmpty();
170: if (errMsg != null) {
171: fail(errMsg);
172: }
173: }
174:
175: public void writeRefData(Object... dataArray) {
176: writeRefData(true, dataArray);
177: }
178:
179: public void writeRefData(boolean needChangeSpaces,
180: Object... dataArray) {
181: for (Object obj : dataArray) {
182: String s = (needChangeSpaces ? changeExtraWhiteSpaces(obj
183: .toString()) : obj.toString());
184: ref(s);
185: }
186: }
187:
188: public static String changeExtraWhiteSpaces(String s) {
189: return s.replaceAll("\t", " ").replaceAll("\n", " ")
190: .replaceAll("\r", " ").replaceAll(" *", " ").trim();
191: }
192:
193: @Override
194: protected void setUp() throws Exception {
195: //Utils.logStream = getLog();
196: }
197:
198: @Override
199: protected void tearDown() throws Exception {
200: }
201: }
|