0001: /*
0002: DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:
0004: Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:
0006:
0007: The contents of this file are subject to the terms of either the GNU
0008: General Public License Version 2 only ("GPL") or the Common
0009: Development and Distribution License("CDDL") (collectively, the
0010: "License"). You may not use this file except in compliance with the
0011: License. You can obtain a copy of the License at
0012: http://www.netbeans.org/cddl-gplv2.html
0013: or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0014: specific language governing permissions and limitations under the
0015: License. When distributing the software, include this License Header
0016: Notice in each file and include the License file at
0017: nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0018: particular file as subject to the "Classpath" exception as provided
0019: by Sun in the GPL Version 2 section of the License file that
0020: accompanied this code. If applicable, add the following below the
0021: License Header, with the fields enclosed by brackets [] replaced by
0022: your own identifying information:
0023: "Portions Copyrighted [year] [name of copyright owner]"
0024:
0025: Contributor(s):
0026:
0027: The Original Software is NetBeans. The Initial Developer of the Original
0028: Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0029: Microsystems, Inc. All Rights Reserved.
0030:
0031: If you wish your version of this file to be governed by only the CDDL
0032: or only the GPL Version 2, indicate your decision by adding
0033: "[Contributor] elects to include this software in this distribution
0034: under the [CDDL or GPL Version 2] license." If you do not indicate a
0035: single choice of license, a recipient has the option to distribute
0036: your version of this file under either the CDDL, the GPL Version 2 or
0037: to extend the choice of license to its licensees as provided above.
0038: However, if you add GPL Version 2 code and therefore, elected the GPL
0039: Version 2 license, then the option applies only if the new code is
0040: made subject to such option by the copyright holder.
0041: */
0042:
0043: package org.netbeans.test.ejb;
0044:
0045: import org.netbeans.jellytools.TopComponentOperator;
0046: import org.netbeans.jemmy.operators.*;
0047: import org.netbeans.jemmy.*;
0048: import junit.framework.*;
0049:
0050: import org.netbeans.modules.visualweb.gravy.DocumentOutlineOperator;
0051: import org.netbeans.modules.visualweb.gravy.properties.editors.*;
0052: import org.netbeans.modules.visualweb.gravy.properties.*;
0053: import org.netbeans.modules.visualweb.gravy.model.deployment.*;
0054: import org.netbeans.modules.visualweb.gravy.model.*;
0055: import org.netbeans.modules.visualweb.gravy.dataconnectivity.*;
0056: import org.netbeans.modules.visualweb.gravy.designer.*;
0057: import org.netbeans.modules.visualweb.gravy.toolbox.*;
0058: import org.netbeans.modules.visualweb.gravy.*;
0059: import org.netbeans.modules.visualweb.gravy.Bundle;
0060:
0061: import org.netbeans.modules.visualweb.ejb.ui.*;
0062: import com.meterware.httpunit.*;
0063: import javax.swing.tree.*;
0064: import javax.swing.*;
0065: import java.awt.event.*;
0066: import java.awt.*;
0067: import java.util.*;
0068: import java.io.*;
0069:
0070: /**
0071: * @author Roman Mostyka
0072: */
0073: public class EJBTestUtils {
0074:
0075: public static final String EJB_JARS_PATH = System
0076: .getProperty("xtest.ejb_jars.dir");
0077: public static final String RMI_IIOP_PORT_APPSERVER = "3700";
0078:
0079: public static final String ejbNode = Bundle.getStringTrimmed(
0080: "org.netbeans.modules.visualweb.ejb.nodes.Bundle",
0081: "ENTERPRISE_JAVA_BEANS");
0082:
0083: public static final String sessionEJBPopup = Bundle
0084: .getStringTrimmed(
0085: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0086: "ADD_EJB_GROUP");
0087: public static final String importEJBPopup = Bundle
0088: .getStringTrimmed(
0089: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0090: "IMPORT_EJB_DATASOURCE");
0091: public static final String exportEJBPopup = Bundle
0092: .getStringTrimmed(
0093: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0094: "EXPORT_EJB_DATASOURCE");
0095: public static final String exportEJBsPopup = Bundle
0096: .getStringTrimmed(
0097: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0098: "EXPORT_ALL_EJB_DATASOURCES");
0099: public static final String modifyPopup = Bundle.getStringTrimmed(
0100: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0101: "MODIFY_EJB_GROUP");
0102: public static final String refreshPopup = Bundle.getStringTrimmed(
0103: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0104: "REFRESH");
0105: public static final String removePopup = Bundle.getStringTrimmed(
0106: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0107: "DELETE");
0108: public static final String exportPopup = Bundle.getStringTrimmed(
0109: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0110: "EXPORT_EJB_DATASOURCE");
0111: public static final String configurePopup = Bundle
0112: .getStringTrimmed(
0113: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0114: "CONFIGURE_EJB_METHODS");
0115: public static final String addToPagePopup = Bundle
0116: .getStringTrimmed(
0117: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0118: "ADD_SESSION_BEAN_TO_PAGE");
0119: public static final String addBindingAttribute = Bundle
0120: .getStringTrimmed(
0121: "org.netbeans.modules.visualweb.insync.action.Bundle",
0122: "LBL_AddBindingAttributeActionName");
0123:
0124: public static final String dlg_sessionEJB = Bundle
0125: .getStringTrimmed(
0126: "org.netbeans.modules.visualweb.ejb.ui.Bundle",
0127: "ADD_EJB_GROUP");
0128: public static final String dlg_exportEJB = Bundle.getStringTrimmed(
0129: "org.netbeans.modules.visualweb.ejb.ui.Bundle",
0130: "EXPORT_EJB_DATASOURCES");
0131: public static final String dlg_importEJB = Bundle.getStringTrimmed(
0132: "org.netbeans.modules.visualweb.ejb.ui.Bundle",
0133: "IMPORT_EJB_DATASOURCES");
0134: public static final String dlg_modifyEJB = Bundle.getStringTrimmed(
0135: "org.netbeans.modules.visualweb.ejb.ui.Bundle",
0136: "MODIFY_EJB_GROUP");
0137: public static final String dlg_removeConfirm = Bundle
0138: .getStringTrimmed(
0139: "org.netbeans.modules.visualweb.ejb.actions.Bundle",
0140: "DELETE_DIALOG_TITLE");
0141: public static final String dlg_Error = "Error";
0142: public static final String dlg_save_export_file_name = "Save";
0143: public static final String dlg_open_import_file_name = "Open";
0144: public static final String dlg_question = "Question";
0145: public static final String dlg_information = "Information";
0146: public static final String dlg_export_help = "Help";
0147:
0148: public static final String msg_noEJBsFound = Bundle
0149: .getStringTrimmed(
0150: "org.netbeans.modules.visualweb.ejb.load.Bundle",
0151: "NO_SESSION_EJBS_FOUND");
0152: public static final String msg_skipped = Bundle.getStringTrimmed(
0153: "org.netbeans.modules.visualweb.ejb.load.Bundle",
0154: "SKIP_NO_PACKAGE_EJBS");
0155: public static final String msg_noDescriptor = Bundle
0156: .getStringTrimmed(
0157: "org.netbeans.modules.visualweb.ejb.load.Bundle",
0158: "NO_DEPLOYMENT_DESCRIPTOR");
0159: public static final String msg_emptyJAR = Bundle.getStringTrimmed(
0160: "org.netbeans.modules.visualweb.ejb.ui.Bundle",
0161: "EMPTY_CLIENT_JAR");
0162:
0163: private static String javaVersion = System
0164: .getProperty("java.version");
0165: private static String osName = System.getProperty("os.name");
0166:
0167: public static final String btn_Clear = Bundle.getStringTrimmed(
0168: "org.netbeans.modules.visualweb.ejb.ui.Bundle",
0169: "CLEAR_BUTTON_LABEL"), btn_SelectAll = Bundle
0170: .getStringTrimmed(
0171: "org.netbeans.modules.visualweb.ejb.ui.Bundle",
0172: "SELECT_ALL_BUTTON_LABEL"), btn_Cancel = "Cancel",
0173: btn_Add = "Add...", btn_Next = "Next", btn_Back = "Back",
0174: btn_Open = (javaVersion.indexOf("1.6") != -1 && osName
0175: .indexOf("Linux") != -1) ? "OK" : "Open",
0176: btn_Save = (javaVersion.indexOf("1.6") != -1 && osName
0177: .indexOf("Linux") != -1) ? "OK" : "Save",
0178: btn_Finish = "Finish", btn_Browse = "Browse...",
0179: btn_Yes = "Yes", btn_No = "No", btn_OK = "OK",
0180: btn_Help = "Help";
0181:
0182: private static final String WEB_PAGE_TITLE = "Page1",
0183: JAVA_EDITOR_TITLE = "Page1.java",
0184: MENU_ITEM_RUN_PROJECT = "Run",
0185: MENU_ITEM_REFRESH = "Refresh",
0186: MENU_ITEM_UNDEPLOY = "Undeploy",
0187: MENU_ITEM_CLOSE_PROJECT = "Close";
0188:
0189: private static final String PROP_NAME_EJB_SET_NAME = "Name",
0190: PROP_NAME_RMI_IIOP_PORT = "RMI-IIOP Port",
0191: PROP_NAME_SERVER_HOST = "Server Host";
0192:
0193: private static final String WEB_PAGE_FORM_NAME = "form1";
0194: private static final int WEB_RESPONSE_CODE_OK = 200;
0195: private static final long WEB_RESPONSE_RECEIVING_DELAY = 10000;
0196:
0197: private static final String DEFAULT_EXPORT_NAME = "exported_ejb_datasources.jar";
0198:
0199: public static ServerNavigatorOperator server;
0200: public static JTreeOperator sntree;
0201: public static DesignerPaneOperator designer;
0202:
0203: private static String lastCreatedPrjName, lastTextField_ID;
0204: private static String serverType = "GlassFish V2";
0205: private static DeploymentTargetDescriptor dtd;
0206: private static DeploymentTarget dt;
0207: private static ApplicationServer as;
0208: private static String NODE_NAME_DEPLOYMENT_SERVER,
0209: NODE_NAME_DEPLOYED_COMPONENTS;
0210:
0211: public static String getLastCreatedPrjName() {
0212: return lastCreatedPrjName;
0213: }
0214:
0215: public static String getLastTextField_ID() {
0216: return lastTextField_ID;
0217: }
0218:
0219: public static ApplicationServer addApplicationServer() {
0220: dtd = new DeploymentTargetDescriptor();
0221: dtd.load();
0222: if (serverType != null)
0223: dtd.setProperty(dtd.SERVER_TYPE_KEY, serverType);
0224: dt = IDE.getIDE().addDeploymentTarget(dtd);
0225: as = (ApplicationServer) dt;
0226: NODE_NAME_DEPLOYMENT_SERVER = "Servers|" + as.getName();
0227: NODE_NAME_DEPLOYED_COMPONENTS = "Servers|"
0228: + as.web_applications_path;
0229: return as;
0230: }
0231:
0232: public static ApplicationServer getApplicationServer() {
0233: if (as != null)
0234: return as;
0235: else
0236: return addApplicationServer();
0237: }
0238:
0239: public static void checkPopupMenuItemList(
0240: JPopupMenuOperator menuOperator, String[] menuItemList) {
0241: for (int i = 0; i < menuItemList.length; ++i) {
0242: checkPopupMenuItem(menuOperator, menuItemList[i]);
0243: }
0244: }
0245:
0246: private static void checkPopupMenuItem(
0247: JPopupMenuOperator menuOperator, String menuItemLabel) {
0248: if (TestUtils.findPopupMenuItemByLabel(menuOperator,
0249: menuItemLabel, false, false) == null) {
0250: Assert.fail("Popup menu doesn't contain the item ["
0251: + menuItemLabel + "]");
0252: } else {
0253: TestUtils.outMsg("+++ Popup menu contains the item ["
0254: + menuItemLabel + "]");
0255: }
0256: }
0257:
0258: public static void addEJB(String EJBName, String host, String port,
0259: String pathToJAR, String pathToEAR) {
0260: server = ServerNavigatorOperator.showNavigatorOperator();
0261: Util.wait(1000);
0262: sntree = server.getTree();
0263: server.pushPopup(ejbNode, sessionEJBPopup);
0264: Util.wait(1000);
0265: //JDialogOperator addDialog = new JDialogOperator(dlg_sessionEJB);
0266: JDialogOperator addDialog = new JDialogOperator();
0267: Util.wait(1000);
0268: if (!EJBName.equals(""))
0269: new JTextFieldOperator(addDialog, 0).setText(EJBName);
0270: if (!host.equals(""))
0271: new JTextFieldOperator(addDialog, 1).setText(host);
0272: if (!port.equals(""))
0273: new JTextFieldOperator(addDialog, 2).setText(port);
0274: Util.wait(1000);
0275: if (!pathToEAR.equals("")) {
0276: new JButtonOperator(addDialog, btn_Browse).pushNoBlock();
0277: Util.wait(1000);
0278: JDialogOperator dlg_open = new JDialogOperator("Open");
0279: if (System.getProperty("os.name").equals("Mac OS X")) {
0280: String[] splittedPath = pathToEAR.substring(1,
0281: pathToEAR.length()).split(File.separator);
0282: TestUtils.wait(1000);
0283: JComboBoxOperator cbRoot = new JComboBoxOperator(
0284: dlg_open);
0285: for (int i = 0; i < cbRoot.getItemCount(); i++)
0286: if (cbRoot.getItemAt(i).toString().equals(
0287: File.separator)) {
0288: cbRoot.setSelectedIndex(i);
0289: break;
0290: }
0291: String toCompare = "";
0292: for (int i = 0; i < splittedPath.length; i++) {
0293: JTableOperator jtoPath = new JTableOperator(
0294: dlg_open);
0295: toCompare += "/" + splittedPath[i];
0296: System.out.println("toComapre=" + toCompare);
0297: Point cell = jtoPath.findCell(toCompare,
0298: new Operator.DefaultStringComparator(true,
0299: true), 0);
0300: jtoPath.clickOnCell((int) cell.getY(), (int) cell
0301: .getX(), 2);
0302: TestUtils.wait(500);
0303: }
0304: } else {
0305: new JTextFieldOperator(dlg_open, 0).setText(pathToEAR);
0306: Util.wait(1000);
0307: new JButtonOperator(dlg_open, btn_Open).pushNoBlock();
0308: Util.wait(1000);
0309: }
0310: }
0311: if (!pathToJAR.equals("")) {
0312: new JButtonOperator(addDialog, btn_Add).pushNoBlock();
0313: Util.wait(1000);
0314: JDialogOperator dlg_open = new JDialogOperator("Open");
0315: if (System.getProperty("os.name").equals("Mac OS X")) {
0316: String[] splittedPath = pathToJAR.substring(1,
0317: pathToJAR.length()).split(File.separator);
0318: TestUtils.wait(1000);
0319: JComboBoxOperator cbRoot = new JComboBoxOperator(
0320: dlg_open);
0321: for (int i = 0; i < cbRoot.getItemCount(); i++)
0322: if (cbRoot.getItemAt(i).toString().equals(
0323: File.separator)) {
0324: cbRoot.setSelectedIndex(i);
0325: break;
0326: }
0327: String toCompare = "";
0328: for (int i = 0; i < splittedPath.length; i++) {
0329: JTableOperator jtoPath = new JTableOperator(
0330: dlg_open);
0331: toCompare += "/" + splittedPath[i];
0332: System.out.println("toComapre=" + toCompare);
0333: Point cell = jtoPath.findCell(toCompare,
0334: new Operator.DefaultStringComparator(true,
0335: true), 0);
0336: jtoPath.clickOnCell((int) cell.getY(), (int) cell
0337: .getX(), 2);
0338: TestUtils.wait(500);
0339: }
0340: } else {
0341: JTextFieldOperator textField = new JTextFieldOperator(
0342: dlg_open, 0);
0343: textField.setText(pathToJAR);
0344: Util.wait(1000);
0345:
0346: new JButtonOperator(dlg_open, btn_Open).pushNoBlock();
0347: Util.wait(1000);
0348: }
0349: }
0350: new JButtonOperator(addDialog, btn_Next).pushNoBlock();
0351: Util.wait(1500);
0352: new QueueTool().waitEmpty();
0353: }
0354:
0355: public static void addEJB() {
0356: addEJB("", "", "", "", "");
0357: }
0358:
0359: public static void addEJB(String pathToJAR) {
0360: addEJB("", "", "", pathToJAR, "");
0361: }
0362:
0363: public static void addEJB(String pathToJAR, String pathToEAR) {
0364: addEJB("", "", "", pathToJAR, pathToEAR);
0365: }
0366:
0367: public static void addEJB(String port, String pathToJAR,
0368: String pathToEAR) {
0369: addEJB("", "", port, pathToJAR, pathToEAR);
0370: }
0371:
0372: public static void addEJB(String EJBName, String port,
0373: String pathToJAR, String pathToEAR) {
0374: addEJB(EJBName, "", port, pathToJAR, pathToEAR);
0375: }
0376:
0377: public static void endAddEJB() {
0378: //new JButtonOperator(new JDialogOperator(dlg_sessionEJB), btn_Finish).pushNoBlock();
0379: new JButtonOperator(new JDialogOperator(), btn_Finish)
0380: .pushNoBlock();
0381: Util.wait(3500);
0382: new QueueTool().waitEmpty();
0383: }
0384:
0385: public static void removeEJB(String EJBname) {
0386: server = ServerNavigatorOperator.showNavigatorOperator();
0387: Util.wait(1000);
0388: server.pushPopup(ejbNode + "|" + EJBname, removePopup);
0389: Util.wait(1000);
0390: new JButtonOperator(new JDialogOperator(dlg_removeConfirm),
0391: btn_Yes).pushNoBlock();
0392: Util.wait(2000);
0393: }
0394:
0395: public static void modifyEJBSet(String EJBSetName,
0396: int textFieldNumber, String textFieldValue) {
0397: server = ServerNavigatorOperator.showNavigatorOperator();
0398: Util.wait(1000);
0399: server.pushPopup(ejbNode + "|" + EJBSetName, modifyPopup);
0400: Util.wait(1000);
0401: new QueueTool().waitEmpty();
0402:
0403: JDialogOperator dlg_modify = new JDialogOperator(dlg_modifyEJB);
0404: new JTextFieldOperator(dlg_modify, textFieldNumber)
0405: .setText(textFieldValue);
0406: Util.wait(1000);
0407: new JButtonOperator(dlg_modify, btn_OK).pushNoBlock();
0408: Util.wait(2000);
0409: new QueueTool().waitEmpty();
0410: }
0411:
0412: public static String verifyModifiedEJBSet(String EJBSetName,
0413: String[] propertyValues) {
0414: server = ServerNavigatorOperator.showNavigatorOperator();
0415: Util.wait(1000);
0416: server.pushPopup(ejbNode + "|" + EJBSetName, modifyPopup);
0417: Util.wait(1000);
0418: new QueueTool().waitEmpty();
0419:
0420: JDialogOperator dlg_modify = new JDialogOperator(dlg_modifyEJB);
0421: String errMsg = null;
0422: for (int i = 0; i < propertyValues.length; ++i) {
0423: errMsg = verifyModifiedEJBSetProperty(dlg_modify, i,
0424: propertyValues[i]);
0425: if (errMsg != null) {
0426: break;
0427: }
0428: }
0429: new JButtonOperator(dlg_modify, btn_OK).pushNoBlock();
0430: Util.wait(1000);
0431: new QueueTool().waitEmpty();
0432:
0433: return errMsg;
0434: }
0435:
0436: private static String verifyModifiedEJBSetProperty(
0437: JDialogOperator dlg_modify, int textFieldNumber,
0438: String controlValue) {
0439: String errMsg = null;
0440:
0441: String propertyValue = new JTextFieldOperator(dlg_modify,
0442: textFieldNumber).getText();
0443: TestUtils.outMsg("+++ Value of text field [" + textFieldNumber
0444: + "] = [" + propertyValue + "], control value = ["
0445: + controlValue + "]");
0446: if (!propertyValue.equals(controlValue)) {
0447: errMsg = "+++ Value of text field [" + textFieldNumber
0448: + "] = [" + propertyValue
0449: + "] not equals the control value = ["
0450: + controlValue + "]";
0451: }
0452: return errMsg;
0453: }
0454:
0455: public static String exportEJBSet(String ejbSetName,
0456: String exportFileName, boolean verification) {
0457: server = ServerNavigatorOperator.showNavigatorOperator();
0458: Util.wait(1000);
0459: server.pushPopup(ejbNode + "|" + ejbSetName, exportEJBPopup);
0460: Util.wait(1000);
0461:
0462: JDialogOperator dlg_export = new JDialogOperator(dlg_exportEJB);
0463: Util.wait(1000);
0464: new QueueTool().waitEmpty();
0465:
0466: String errMsg = null;
0467: if (verification) {
0468: if (!isEJBSetSelected(new JListOperator(dlg_export),
0469: ejbSetName)) {
0470: errMsg = "EJB Set [" + ejbSetName
0471: + "] is not selected in the dialog ["
0472: + dlg_exportEJB + "]";
0473: }
0474: }
0475: if (errMsg == null) {
0476: exportFileName = defineExportFileName(dlg_export,
0477: exportFileName);
0478: new JButtonOperator(dlg_export, btn_OK).pushNoBlock();
0479: Util.wait(1200);
0480: new QueueTool().waitEmpty();
0481:
0482: JDialogOperator dialog = new JDialogOperator(dlg_export);
0483: // if dialog "Question" appears (overwrite an existing file), press OK
0484: if (dialog.getTitle().equals(dlg_question)) {
0485: new JButtonOperator(dialog, btn_OK).pushNoBlock();
0486: Util.wait(1200);
0487: new QueueTool().waitEmpty();
0488: }
0489: new JButtonOperator(new JDialogOperator(dlg_information),
0490: btn_OK).pushNoBlock();
0491: Util.wait(1500);
0492: new QueueTool().waitEmpty();
0493:
0494: if (!new File(exportFileName).exists()) {
0495: errMsg = "Export file [" + exportFileName
0496: + "] of EJB Set [" + ejbSetName + "] not found";
0497: } else {
0498: TestUtils.outMsg("+++ Export file [" + exportFileName
0499: + "] of EJB Set [" + ejbSetName + "] exists");
0500: }
0501: } else {
0502: new JButtonOperator(new JDialogOperator(dlg_information),
0503: btn_Cancel).pushNoBlock();
0504: Util.wait(1000);
0505: new QueueTool().waitEmpty();
0506: }
0507: return errMsg;
0508: }
0509:
0510: private static String defineExportFileName(
0511: JDialogOperator dialogExport, String exportFileName) {
0512: if (!exportFileName.equals("")) {
0513: new JButtonOperator(dialogExport, btn_Browse).pushNoBlock();
0514: Util.wait(1000);
0515: JDialogOperator dlg_save = new JDialogOperator(
0516: dlg_save_export_file_name);
0517: Util.wait(1000);
0518: new JTextFieldOperator(dlg_save, 0).setText(exportFileName);
0519: Util.wait(1000);
0520: new JButtonOperator(dlg_save, btn_Save).pushNoBlock();
0521: Util.wait(1000);
0522: new QueueTool().waitEmpty();
0523: } else {
0524: exportFileName = new JTextFieldOperator(dialogExport, 0)
0525: .getText();
0526: }
0527: return exportFileName;
0528: }
0529:
0530: public static String exportEJBSet(String ejbSetName,
0531: boolean verification) {
0532: return exportEJBSet(ejbSetName, "", verification);
0533: }
0534:
0535: public static String exportRequiredEJBSets(String[] ejbSetNames) {
0536: server = ServerNavigatorOperator.showNavigatorOperator();
0537: Util.wait(1000);
0538: java.util.List ejbSetNameList = getAvailableEJBSetNameList();
0539:
0540: server.pushPopup(ejbNode, exportEJBsPopup);
0541: Util.wait(1000);
0542:
0543: JDialogOperator dlg_export = new JDialogOperator(dlg_exportEJB);
0544: Util.wait(1000);
0545: new QueueTool().waitEmpty();
0546:
0547: new JButtonOperator(dlg_export, btn_Clear).pushNoBlock();
0548: Util.wait(1000);
0549: new QueueTool().waitEmpty();
0550: String errMsg = checkAllEJBSetsSelected(dlg_export,
0551: ejbSetNameList, false);
0552:
0553: if (errMsg == null) {
0554: JListOperator listOperator = new JListOperator(dlg_export);
0555: for (int i = 0; i < ejbSetNames.length; ++i) {
0556: String ejbSetName = ejbSetNames[i];
0557: selectEJBSetInList(listOperator, ejbSetName);
0558: if (!isEJBSetSelected(listOperator, ejbSetName)) {
0559: errMsg = "EJB Set [" + ejbSetName
0560: + "] is not selected in the dialog ["
0561: + dlg_exportEJB + "]";
0562: break;
0563: }
0564: }
0565: }
0566: if (errMsg == null) {
0567: String exportFileName = defineExportFileName(dlg_export, "");
0568: new JButtonOperator(dlg_export, btn_OK).pushNoBlock();
0569: Util.wait(1200);
0570: new QueueTool().waitEmpty();
0571:
0572: JDialogOperator dialog = new JDialogOperator(dlg_export);
0573: // if dialog "Question" appears (overwrite an existing file), press OK
0574: if (dialog.getTitle().equals(dlg_question)) {
0575: new JButtonOperator(dialog, btn_OK).pushNoBlock();
0576: Util.wait(1200);
0577: new QueueTool().waitEmpty();
0578: }
0579: new JButtonOperator(new JDialogOperator(dlg_information),
0580: btn_OK).pushNoBlock();
0581: Util.wait(1500);
0582: new QueueTool().waitEmpty();
0583:
0584: if (!new File(exportFileName).exists()) {
0585: errMsg = "Export file [" + exportFileName
0586: + "] for EJB Sets "
0587: + Arrays.asList(ejbSetNames) + " not found";
0588: } else {
0589: TestUtils.outMsg("+++ Export file [" + exportFileName
0590: + "] for EJB Sets "
0591: + Arrays.asList(ejbSetNames) + " exists");
0592: }
0593: } else {
0594: new JButtonOperator(new JDialogOperator(dlg_information),
0595: btn_Cancel).pushNoBlock();
0596: Util.wait(1000);
0597: new QueueTool().waitEmpty();
0598: }
0599: return errMsg;
0600: }
0601:
0602: public static String exportAllEJBSets(String ejbTreeNodePath,
0603: java.util.List ejbSetNameList, String exportFileName,
0604: boolean clickButtonsClearSelect, boolean verification) {
0605: server = ServerNavigatorOperator.showNavigatorOperator();
0606: Util.wait(1000);
0607: server.pushPopup(ejbTreeNodePath, (ejbTreeNodePath
0608: .equals(ejbNode) ? exportEJBsPopup : exportEJBPopup));
0609: Util.wait(1000);
0610:
0611: JDialogOperator dlg_export = new JDialogOperator(dlg_exportEJB);
0612: Util.wait(1000);
0613: new QueueTool().waitEmpty();
0614:
0615: String errMsg = null;
0616: if (clickButtonsClearSelect) {
0617: new JButtonOperator(dlg_export, btn_SelectAll)
0618: .pushNoBlock();
0619: Util.wait(1000);
0620: new QueueTool().waitEmpty();
0621: if (verification) {
0622: errMsg = checkAllEJBSetsSelected(dlg_export,
0623: ejbSetNameList, true);
0624: }
0625: }
0626: if (clickButtonsClearSelect && (errMsg == null)) {
0627: new JButtonOperator(dlg_export, btn_Clear).pushNoBlock();
0628: Util.wait(1000);
0629: new QueueTool().waitEmpty();
0630: if (verification) {
0631: errMsg = checkAllEJBSetsSelected(dlg_export,
0632: ejbSetNameList, false);
0633: }
0634: }
0635: if (clickButtonsClearSelect && (errMsg == null)) {
0636: new JButtonOperator(dlg_export, btn_SelectAll)
0637: .pushNoBlock();
0638: Util.wait(1000);
0639: new QueueTool().waitEmpty();
0640: }
0641: if (verification && (errMsg == null)) {
0642: errMsg = checkAllEJBSetsSelected(dlg_export,
0643: ejbSetNameList, true);
0644: }
0645: if (errMsg == null) {
0646: exportFileName = defineExportFileName(dlg_export,
0647: exportFileName);
0648: new JButtonOperator(dlg_export, btn_OK).pushNoBlock();
0649: Util.wait(1200);
0650: new QueueTool().waitEmpty();
0651:
0652: JDialogOperator dialog = new JDialogOperator(dlg_export);
0653: // if dialog "Question" appears (overwrite an existing file), press OK
0654: if (dialog.getTitle().equals(dlg_question)) {
0655: new JButtonOperator(dialog, btn_OK).pushNoBlock();
0656: Util.wait(1200);
0657: new QueueTool().waitEmpty();
0658: }
0659: new JButtonOperator(new JDialogOperator(dlg_information),
0660: btn_OK).pushNoBlock();
0661: Util.wait(1500);
0662: new QueueTool().waitEmpty();
0663:
0664: if (!new File(exportFileName).exists()) {
0665: errMsg = "Export file [" + exportFileName
0666: + "] of all EJB Sets not found";
0667: } else {
0668: TestUtils.outMsg("+++ Export file [" + exportFileName
0669: + "] of all EJB Sets exists");
0670: }
0671: } else {
0672: new JButtonOperator(new JDialogOperator(dlg_information),
0673: btn_Cancel).pushNoBlock();
0674: Util.wait(1000);
0675: new QueueTool().waitEmpty();
0676: }
0677: return errMsg;
0678: }
0679:
0680: public static String exportAllEJBSets(String ejbTreeNodePath,
0681: java.util.List ejbSetNames,
0682: boolean clickButtonsClearSelect, boolean verification) {
0683: return exportAllEJBSets(ejbTreeNodePath, ejbSetNames, "",
0684: clickButtonsClearSelect, verification);
0685: }
0686:
0687: public static java.util.List getAvailableEJBSetNameList() {
0688: java.util.List ejbSetNameList = new ArrayList();
0689: // make a list of names of available EJB Sets
0690: sntree = ServerNavigatorOperator.showNavigatorOperator()
0691: .getTree();
0692: TreePath treePath = sntree.findPath(ejbNode);
0693: Util.wait(1000);
0694: new QueueTool().waitEmpty();
0695: TreeNode treeNode = (TreeNode) treePath.getLastPathComponent();
0696: for (int i = 0; i < treeNode.getChildCount(); ++i) {
0697: String ejbSetNodeName = treeNode.getChildAt(i).toString();
0698: ejbSetNameList.add(ejbSetNodeName);
0699: TestUtils.outMsg("+++ Available EJB Set = ["
0700: + ejbSetNodeName + "]");
0701: }
0702: TestUtils.outMsg("+++ List of available EJB Sets = "
0703: + ejbSetNameList);
0704: return ejbSetNameList;
0705: }
0706:
0707: public static String importEJBSets(String importFileName,
0708: String[] ejbSetNames, boolean doClear, boolean verification) {
0709: server = ServerNavigatorOperator.showNavigatorOperator();
0710: Util.wait(1000);
0711: new QueueTool().waitEmpty();
0712:
0713: server.pushPopup(ejbNode, importEJBPopup);
0714: Util.wait(1000);
0715: new QueueTool().waitEmpty();
0716:
0717: JDialogOperator dlg_open = new JDialogOperator(
0718: dlg_open_import_file_name);
0719: Util.wait(1000);
0720: new QueueTool().waitEmpty();
0721: if (!importFileName.equals("")) {
0722: if (System.getProperty("os.name").equals("Mac OS X")) {
0723: String[] splittedPath = importFileName.substring(1,
0724: importFileName.length()).split(File.separator);
0725: TestUtils.wait(1000);
0726: JComboBoxOperator cbRoot = new JComboBoxOperator(
0727: dlg_open);
0728: for (int i = 0; i < cbRoot.getItemCount(); i++)
0729: if (cbRoot.getItemAt(i).toString().equals(
0730: File.separator)) {
0731: cbRoot.setSelectedIndex(i);
0732: break;
0733: }
0734: String toCompare = "";
0735: for (int i = 0; i < splittedPath.length; i++) {
0736: JTableOperator jtoPath = new JTableOperator(
0737: dlg_open);
0738: toCompare += "/" + splittedPath[i];
0739: System.out.println("toComapre=" + toCompare);
0740: Point cell = jtoPath.findCell(toCompare,
0741: new Operator.DefaultStringComparator(true,
0742: true), 0);
0743: jtoPath.clickOnCell((int) cell.getY(), (int) cell
0744: .getX(), 2);
0745: TestUtils.wait(500);
0746: }
0747: } else {
0748: new JTextFieldOperator(dlg_open, 0)
0749: .setText(importFileName);
0750: Util.wait(1000);
0751: new QueueTool().waitEmpty();
0752: }
0753: }
0754: if (System.getProperty("os.name").equals("Mac OS X")) {
0755: JTableOperator jtoPath = new JTableOperator(dlg_open);
0756: Point cell = jtoPath
0757: .findCell(System.getProperty("user.home")
0758: + File.separator + DEFAULT_EXPORT_NAME,
0759: new Operator.DefaultStringComparator(true,
0760: true), 0);
0761: jtoPath
0762: .clickOnCell((int) cell.getY(), (int) cell.getX(),
0763: 2);
0764: TestUtils.wait(500);
0765: } else {
0766: new JButtonOperator(dlg_open, btn_Open).pushNoBlock();
0767: Util.wait(1000);
0768: new QueueTool().waitEmpty();
0769: }
0770:
0771: JDialogOperator dlg_import = new JDialogOperator(dlg_importEJB);
0772: Util.wait(1000);
0773: new QueueTool().waitEmpty();
0774:
0775: if (doClear) {
0776: new JButtonOperator(dlg_import, btn_Clear).pushNoBlock();
0777: Util.wait(1000);
0778: new QueueTool().waitEmpty();
0779:
0780: JListOperator listOperator = new JListOperator(dlg_import);
0781: for (int i = 0; i < ejbSetNames.length; ++i) {
0782: String ejbSetName = ejbSetNames[i];
0783: selectEJBSetInList(listOperator, ejbSetName);
0784: }
0785: }
0786: String errMsg = null;
0787: if (verification) {
0788: errMsg = checkAllEJBSetsSelected(dlg_import, Arrays
0789: .asList(ejbSetNames), true);
0790: }
0791: Util.wait(500);
0792: new QueueTool().waitEmpty();
0793:
0794: new JButtonOperator(dlg_import, btn_OK).pushNoBlock();
0795: Util.wait(2000);
0796: new QueueTool().waitEmpty();
0797:
0798: if (errMsg == null) {
0799: server = ServerNavigatorOperator.showNavigatorOperator();
0800: Util.wait(1000);
0801: new QueueTool().waitEmpty();
0802: sntree = server.getTree();
0803: Util.wait(1000);
0804:
0805: for (int i = 0; i < ejbSetNames.length; ++i) {
0806: String ejbSetName = ejbSetNames[i];
0807: try {
0808: sntree.findPath(ejbNode + "|" + ejbSetName);
0809: TestUtils.outMsg("+++ EJB-subnode [" + ejbSetName
0810: + "] has been found under tree node ["
0811: + ejbNode + "]");
0812:
0813: EJBTestUtils.removeEJB(ejbSetName);
0814: } catch (TimeoutExpiredException tee) {
0815: errMsg = "EJB-subnode [" + ejbSetName
0816: + "] not found under tree node [" + ejbNode
0817: + "]";
0818: break;
0819: }
0820: }
0821: }
0822: return errMsg;
0823: }
0824:
0825: public static boolean isEJBSetSelected(JListOperator jlo,
0826: String EJBSetName) {
0827: boolean result = false;
0828: ListCellRenderer lcr = ((JList) jlo.getSource())
0829: .getCellRenderer();
0830: int item_count = ((ListModel) jlo.getModel()).getSize();
0831: for (int i = 0; i < item_count; ++i) {
0832: Object objListElement = jlo.getModel().getElementAt(i);
0833: Component listElement = lcr.getListCellRendererComponent(
0834: (JList) jlo.getSource(), objListElement, i,
0835: ((PortableEjbDataSource) objListElement)
0836: .isPortable(), true);
0837:
0838: TestUtils
0839: .outMsg("+++ "
0840: + (((PortableEjbDataSource) objListElement)
0841: .getName()
0842: + " is selected = ["
0843: + ((JCheckBox) listElement)
0844: .isSelected() + "]"));
0845:
0846: boolean ejbSetFound = (((PortableEjbDataSource) objListElement)
0847: .getName().equals(EJBSetName));
0848: result = ejbSetFound
0849: && (((JCheckBox) listElement).isSelected());
0850: if (ejbSetFound)
0851: break;
0852: }
0853: return result;
0854: }
0855:
0856: public static String checkAllEJBSetsSelected(
0857: JDialogOperator dialog, java.util.List ejbSetNameList,
0858: boolean shouldSelected) {
0859: JListOperator listOperator = new JListOperator(dialog);
0860: String errMsg = null;
0861: for (int i = 0; i < ejbSetNameList.size(); ++i) {
0862: String ejbSetName = (String) ejbSetNameList.get(i);
0863: if (isEJBSetSelected(listOperator, ejbSetName) != shouldSelected) {
0864: errMsg = (shouldSelected ? "Not all" : "All")
0865: + " EJB Sets are selected in the dialog ["
0866: + dialog.getTitle() + "]: EJB Set ["
0867: + ejbSetName + "]";
0868: break;
0869: }
0870: }
0871: return errMsg;
0872: }
0873:
0874: public static void selectEJBSetInList(JListOperator jlo,
0875: String ejbSetName) {
0876: ListCellRenderer lcr = ((JList) jlo.getSource())
0877: .getCellRenderer();
0878: int item_count = ((ListModel) jlo.getModel()).getSize();
0879: for (int i = 0; i < item_count; ++i) {
0880: Object objListElement = jlo.getModel().getElementAt(i);
0881: String elementName = ((PortableEjbDataSource) objListElement)
0882: .getName();
0883: Component cr = lcr.getListCellRendererComponent((JList) jlo
0884: .getSource(), objListElement, i,
0885: ((PortableEjbDataSource) objListElement)
0886: .isPortable(), true);
0887: if (elementName.equals(ejbSetName)) {
0888: TestUtils.outMsg("+++ Current value [Portable] of ["
0889: + elementName
0890: + "] = ["
0891: + ((PortableEjbDataSource) objListElement)
0892: .isPortable() + "]");
0893: TestUtils.outMsg("+++ Current value [Selected] of ["
0894: + elementName + "] = ["
0895: + ((JCheckBox) cr).isSelected() + "]");
0896:
0897: //jlo.clickMouse(cr.getPreferredSize().height/2,(cr.getPreferredSize().height*(2*i+1))/2,1);
0898: ((PortableEjbDataSource) objListElement)
0899: .setIsPortable(!((PortableEjbDataSource) objListElement)
0900: .isPortable());
0901: ((JCheckBox) cr)
0902: .setSelected(((PortableEjbDataSource) objListElement)
0903: .isPortable());
0904: jlo.repaint();
0905: Util.wait(1500);
0906: new QueueTool().waitEmpty();
0907:
0908: objListElement = jlo.getModel().getElementAt(i);
0909: cr = lcr.getListCellRendererComponent((JList) jlo
0910: .getSource(), objListElement, i,
0911: ((PortableEjbDataSource) objListElement)
0912: .isPortable(), true);
0913: TestUtils.outMsg("+++ New value [Portable] of ["
0914: + elementName
0915: + "] = ["
0916: + ((PortableEjbDataSource) objListElement)
0917: .isPortable() + "]");
0918: TestUtils.outMsg("+++ New value [Selected] of ["
0919: + elementName + "] = ["
0920: + ((JCheckBox) cr).isSelected() + "]");
0921: }
0922: }
0923: Util.wait(2000);
0924: new QueueTool().waitEmpty();
0925: }
0926:
0927: public static void addEJBToPage(String EJBSetName, String EJBName) {
0928: server = ServerNavigatorOperator.showNavigatorOperator();
0929: Util.wait(1000);
0930: sntree = server.getTree();
0931: sntree.selectPath(sntree.findPath(ejbNode + "|" + EJBSetName
0932: + "|" + EJBName));
0933: Util.wait(2000);
0934: server.pushPopup(ejbNode + "|" + EJBSetName + "|" + EJBName,
0935: addToPagePopup);
0936: Util.wait(5000);
0937: }
0938:
0939: public static void changeEjbSetProperties(String newEjbSetName,
0940: String newRMIPort, String newServerHost) {
0941: Util.getMainMenu().pushMenuNoBlock("Window|Properties");
0942: Util.wait(1000);
0943: new QueueTool().waitEmpty();
0944:
0945: PropertySheetOperator pso = new PropertySheetOperator(
0946: RaveWindowOperator.getDefaultRave());
0947: new QueueTool().waitEmpty();
0948: Util.wait(500);
0949:
0950: PropertySheetTabOperator propertyTable = new PropertySheetTabOperator(
0951: pso);
0952: propertyTable
0953: .setComparator(new Operator.DefaultStringComparator(
0954: true, true));
0955: new QueueTool().waitEmpty();
0956: Util.wait(500);
0957:
0958: Property pr = new Property(propertyTable,
0959: PROP_NAME_EJB_SET_NAME);
0960: pr.setValue(newEjbSetName);
0961: Util.wait(500);
0962: new QueueTool().waitEmpty();
0963:
0964: pr = new Property(propertyTable, PROP_NAME_SERVER_HOST);
0965: pr.setValue(newServerHost);
0966: Util.wait(500);
0967: new QueueTool().waitEmpty();
0968:
0969: pr = new Property(propertyTable, PROP_NAME_RMI_IIOP_PORT);
0970: pr.setValue(newRMIPort);
0971: Util.wait(500);
0972: new QueueTool().waitEmpty();
0973: }
0974:
0975: public static String createProjectWithEJB(String ejbSetName,
0976: String ejbBusinessMethodName, String[] ejbLibJarNames,
0977: String ejbReturnedValue, boolean isComparisonStrict,
0978: boolean closeProject) {
0979: String prjName = TestUtils.createNewJSFProject(), prjPath = TestUtils
0980: .getPathLastCreatedProject();
0981: Util.wait(1000);
0982: new QueueTool().waitEmpty();
0983: TestUtils.outMsg("+++ Project Path = [" + prjPath + "]");
0984: TestUtils.outMsg("+++ Project Name = [" + prjName + "]");
0985:
0986: lastCreatedPrjName = prjName; // remember name of created project
0987:
0988: ServerNavigatorOperator serverNavigator = ServerNavigatorOperator
0989: .showNavigatorOperator();
0990: JTreeOperator tree = serverNavigator.getTree();
0991:
0992: String strEjbSetPath = ejbNode + "|" + ejbSetName;
0993: TreePath treePath = tree.findPath(strEjbSetPath);
0994:
0995: // get a name of the 1st EJB: a name of the 1st child subnode (the 1st EJB) of tree node [EJB Set]
0996: TreeNode treeNode = (TreeNode) treePath.getLastPathComponent();
0997: for (int i = 0; i < treeNode.getChildCount(); ++i) {
0998: TestUtils.outMsg("+++ EJB[" + i + "] of EJB Set ["
0999: + ejbSetName + "] = " + treeNode.getChildAt(i));
1000: }
1001: String ejbName = treeNode.getChildAt(0).toString();
1002: String strEjbPath = strEjbSetPath + "|" + ejbName;
1003:
1004: treePath = tree.findPath(strEjbPath);
1005: JPopupMenuOperator popupMenu = new JPopupMenuOperator(tree
1006: .callPopupOnPath(treePath));
1007:
1008: JMenuItemOperator menuItem = new JMenuItemOperator(popupMenu,
1009: addToPagePopup);
1010: menuItem.doClick();
1011: Util.wait(500);
1012: popupMenu.pressKey(KeyEvent.VK_ESCAPE);
1013: Util.wait(500);
1014: new QueueTool().waitEmpty();
1015:
1016: // check Application Outline:
1017: String ejbClientName = checkAppOutlineWindowForEJB(ejbName);
1018: // check Projects | Library:
1019: checkProjectsWindowForEJB(prjName, ejbLibJarNames);
1020:
1021: // add Text Field and modify Page1.java to check availability of EJB's business method
1022: String textField_ID = putTextFieldOnDesigner();
1023: addBindingAttribute(WEB_PAGE_TITLE, "page1|html1|body1|form1|"
1024: + textField_ID);
1025: lastTextField_ID = textField_ID; // remember name of added text field
1026:
1027: addJavaCodeUsingEJBBusinessMethod(textField_ID, ejbClientName,
1028: ejbBusinessMethodName);
1029:
1030: //=====================
1031: // workaround:
1032: // when EJB is added to web-page, a value of a project property
1033: // "display.browser" will be replaced by "true" instead of "false"
1034: TestUtils.disableBrowser(prjName, prjPath, true);
1035: //=====================
1036: String errMsg = checkDeploymentWithEJB(prjName, textField_ID,
1037: ejbReturnedValue, isComparisonStrict);
1038: doSaveAll();
1039: if (closeProject)
1040: doCloseProject(prjName);
1041:
1042: Util.wait(1000);
1043: new QueueTool().waitEmpty();
1044:
1045: return errMsg;
1046: }
1047:
1048: public static String checkDeploymentWithEJB(String prjName,
1049: String textField_ID, String ejbReturnText,
1050: boolean isComparisonStrict) {
1051: deployProject(prjName);
1052: String errMsg = checkDeployment(prjName, textField_ID,
1053: ejbReturnText, isComparisonStrict);
1054: undeployProject(prjName);
1055: return errMsg;
1056: }
1057:
1058: private static void deployProject(String prjName) {
1059: /*
1060: ProjectNavigatorOperator projectNavigator = ProjectNavigatorOperator.pressPopupItemOnNode(prjName,
1061: MENU_ITEM_RUN_PROJECT);
1062: */
1063: Util.getMainWindow().deploy();
1064: Util.wait(1000);
1065: new QueueTool().waitEmpty();
1066:
1067: Util.wait(20000);
1068: new QueueTool().waitEmpty();
1069:
1070: ServerNavigatorOperator serverNavigator = ServerNavigatorOperator
1071: .showNavigatorOperator();
1072: JTreeOperator tree = serverNavigator.getTree();
1073: Util.wait(500);
1074:
1075: serverNavigator.pushPopup(NODE_NAME_DEPLOYMENT_SERVER,
1076: MENU_ITEM_REFRESH);
1077: Util.wait(5000);
1078: serverNavigator.pushPopup(NODE_NAME_DEPLOYED_COMPONENTS,
1079: MENU_ITEM_REFRESH);
1080: Util.wait(1000);
1081: new QueueTool().waitEmpty();
1082:
1083: TestUtils.outMsg("+++ Project [" + prjName
1084: + "] has been deployed");
1085: }
1086:
1087: private static String checkDeployment(String prjName,
1088: String textField_ID, String ejbReturnedValue,
1089: boolean isComparisonStrict) {
1090: String errMsg = null;
1091: try {
1092: //String requestPrefix = TestUtils.getRequestPrefix(600000);
1093: String requestPrefix = as.requestPrefix + prjName;
1094: TestUtils.outMsg("+++ requestPrefix = " + requestPrefix);
1095:
1096: WebResponse response = getWebResponseAfterDeployment(requestPrefix);
1097:
1098: Util.wait(1500);
1099: String contentData = response.getText();
1100: TestUtils
1101: .outMsg("+++ Web response after project deployment: "
1102: + "content type = ["
1103: + response.getContentType()
1104: + "], "
1105: + "response code = ["
1106: + response.getResponseCode()
1107: + "], "
1108: + "content data = [" + contentData + "]");
1109: if (!isWebResponseOK(response)) {
1110: errMsg = "Result of deployment: web application isn't running correctly (web response code "
1111: + "is "
1112: + response.getResponseCode()
1113: + " instead of "
1114: + EJBTestUtils.WEB_RESPONSE_CODE_OK + ")";
1115: return errMsg;
1116: }
1117:
1118: // check values of a text field
1119: String textfieldValue = (String) getTextFieldValueWaiter(
1120: textField_ID).waitAction(response);
1121: TestUtils.outMsg("+++ Value of " + textField_ID + " = ["
1122: + textfieldValue + "]");
1123: Util.wait(1000);
1124:
1125: boolean isComparisonOK = (isComparisonStrict ? textfieldValue
1126: .equals(ejbReturnedValue)
1127: : textfieldValue.indexOf(ejbReturnedValue) > -1);
1128: if (!isComparisonOK) {
1129: errMsg = "Value of " + textField_ID + " ["
1130: + textfieldValue + "] "
1131: + "is different from value ["
1132: + ejbReturnedValue
1133: + "], expected from EJB method";
1134: } else {
1135: TestUtils.outMsg("+++ Value of " + textField_ID + " ["
1136: + textfieldValue
1137: + "] equals value, returned from EJB method");
1138: errMsg = null;
1139: }
1140: } catch (Throwable t) {
1141: String internalMsg = t.getMessage();
1142: if (internalMsg == null) {
1143: errMsg = t.toString();
1144: } else {
1145: t.printStackTrace();
1146: errMsg = internalMsg;
1147: }
1148: } finally {
1149: return errMsg;
1150: }
1151: }
1152:
1153: private static void undeployProject(String prjName) {
1154: ServerNavigatorOperator serverNavigator = ServerNavigatorOperator
1155: .showNavigatorOperator();
1156: JTreeOperator tree = serverNavigator.getTree();
1157: Util.wait(1000);
1158: String deployedApplicationNodeName = NODE_NAME_DEPLOYED_COMPONENTS
1159: + "|" + prjName;
1160: TestUtils.outMsg("+++ Undeploying Application Node = "
1161: + deployedApplicationNodeName);
1162:
1163: serverNavigator.pushPopup(NODE_NAME_DEPLOYED_COMPONENTS,
1164: MENU_ITEM_REFRESH);
1165: Util.wait(1000);
1166: serverNavigator.pushPopup(deployedApplicationNodeName,
1167: MENU_ITEM_UNDEPLOY);
1168: Util.wait(2000);
1169: new QueueTool().waitEmpty();
1170:
1171: TestUtils.outMsg("+++ Project [" + prjName
1172: + "] has been undeployed");
1173: }
1174:
1175: private static String checkAppOutlineWindowForEJB(String ejbName) {
1176: String ejbClientName = ejbName.substring(0,
1177: ejbName.indexOf("EJB")).toLowerCase()
1178: + "Client1";
1179: TestUtils.outMsg("+++ Application Outline EJB's node = "
1180: + ejbClientName);
1181: DocumentOutlineOperator outline = new DocumentOutlineOperator(
1182: RaveWindowOperator.getDefaultRave());
1183: JTreeOperator outlineTree = outline.getStructTreeOperator();
1184: Util.wait(500);
1185: new QueueTool().waitEmpty();
1186: outlineTree.findPath("Page1|" + ejbClientName);
1187: Util.wait(500);
1188: new QueueTool().waitEmpty();
1189:
1190: return ejbClientName;
1191: }
1192:
1193: private static void checkProjectsWindowForEJB(String prjName,
1194: String[] ejbLibJarNames) {
1195: // check Projects | Library:
1196: if ((ejbLibJarNames != null) && (ejbLibJarNames.length > 0)) {
1197: ProjectNavigatorOperator prjNavigator = new ProjectNavigatorOperator();
1198: Util.wait(500);
1199: new QueueTool().waitEmpty();
1200: for (int i = 0; i < ejbLibJarNames.length; ++i) {
1201: prjNavigator.tree().findPath(
1202: prjName + "|Libraries|" + ejbLibJarNames[i]);
1203: Util.wait(100);
1204: new QueueTool().waitEmpty();
1205: TestUtils.outMsg("+++ EJB Jar[" + i + "] is found = ["
1206: + ejbLibJarNames[i] + "]");
1207: }
1208: } else {
1209: TestUtils.outMsg("+++ No EJB Jars were defined");
1210: }
1211: }
1212:
1213: private static String putTextFieldOnDesigner() {
1214: String id = null;
1215: showPalette();
1216: PaletteContainerOperator palette = new PaletteContainerOperator(
1217: "Basic");
1218: Util.wait(500);
1219: new QueueTool().waitEmpty();
1220:
1221: DesignerPaneOperator designer = getDesigner(WEB_PAGE_TITLE);
1222: palette.addComponent("Text Field", designer, new Point(48, 48));
1223: // doesn't work out: palette.dndPaletteComponent("Text Field", designer, new Point(48, 48));
1224: Util.wait(500);
1225: new QueueTool().waitEmpty();
1226:
1227: SheetTableOperator sheetTable = getSheetTableOperator(true,
1228: true);
1229: id = sheetTable.getValue("id");
1230: new QueueTool().waitEmpty();
1231: Util.wait(500);
1232: TestUtils.outMsg("+++ new Text Field [" + id
1233: + "] is put on Designer");
1234:
1235: doSaveAll();
1236: return id;
1237: }
1238:
1239: public static void showPalette() {
1240: Util.wait(1000);
1241: new QueueTool().waitEmpty();
1242: String menuString = "Window|Palette";
1243: Util.getMainMenu().pushMenuNoBlock(menuString);
1244: Util.wait(1000);
1245: new QueueTool().waitEmpty();
1246: }
1247:
1248: private static void addJavaCodeUsingEJBBusinessMethod(
1249: String textField_ID, String ejbClientName,
1250: String ejbBusinessMethodName) {
1251:
1252: DesignerPaneOperator.switchToJavaSource();
1253: Util.wait(500);
1254: new QueueTool().waitEmpty();
1255:
1256: EditorOperator javaEditor = getJavaEditor();
1257:
1258: // put editor's caret to the start position of the last line
1259: putCaretToBeginOfLastLine(javaEditor);
1260: Util.wait(500);
1261: new QueueTool().waitEmpty();
1262:
1263: String javaCodeText = getJavaCodeUsingEJBBusinessMethod(
1264: textField_ID, ejbClientName, ejbBusinessMethodName);
1265:
1266: //=====================
1267: // workaround:
1268: // if getVerification() returns "true", waiter, defined in the method
1269: // JTextComponentOperator.waitText(String, int), won't find inserted
1270: // javaCodeText
1271: javaEditor.txtEditorPane().setVerification(false);
1272: //=====================
1273:
1274: javaEditor.txtEditorPane().typeText(javaCodeText);
1275: Util.wait(1000);
1276: new QueueTool().waitEmpty();
1277: TestUtils.outMsg("+++ java code inserted into ["
1278: + JAVA_EDITOR_TITLE + "]: \n" + javaCodeText);
1279:
1280: //=====================
1281: // workaround:
1282: // Java Editor will insert an extra line containing characters "}}",
1283: // but it should be deleted.
1284: deleteLastLines(javaEditor, 2);
1285: //=====================
1286:
1287: TestUtils.outMsg("+++ Java code of [" + JAVA_EDITOR_TITLE
1288: + "]: \n"
1289: + javaEditor.txtEditorPane().getDisplayedText());
1290: doSaveAll();
1291: }
1292:
1293: private static String getJavaCodeUsingEJBBusinessMethod(
1294: String textField_ID, String ejbClientName,
1295: String ejbBusinessMethodName) {
1296: /* template of inserted java code block
1297: {
1298: try {
1299: textField1.setText(greeterClient1.getGreeting());
1300: } catch (Exception e) {
1301: textField1.setText(e.getClass().getName() + ": " + e.getMessage());
1302: }
1303: }
1304: */
1305: String[] javaCode = new String[] {
1306: " {",
1307: " try {",
1308: " " + textField_ID + ".setText("
1309: + ejbClientName + "." + ejbBusinessMethodName
1310: + "());",
1311: " } catch (Exception e) {",
1312: " textField1.setText(e.getClass().getName() + \": \" + e.getMessage());",
1313: " }", " }" };
1314: StringBuffer buffer = new StringBuffer();
1315: for (int i = 0; i < javaCode.length; ++i) {
1316: buffer.append(javaCode[i]);
1317: buffer.append("\n");
1318: }
1319: return buffer.toString();
1320: }
1321:
1322: public static void doSaveAll() {
1323: Util.saveAllAPICall();
1324: //Util.getMainMenu().pushMenuNoBlock("File|Save All");
1325: Util.wait(1000);
1326: new QueueTool().waitEmpty();
1327: TestUtils.outMsg("+++ [Save All] action has been performed");
1328: }
1329:
1330: public static void doCloseProject(String projectName) {
1331: ProjectNavigatorOperator projectNavigator = ProjectNavigatorOperator
1332: .pressPopupItemOnNode(projectName,
1333: MENU_ITEM_CLOSE_PROJECT);
1334: Util.wait(500);
1335: new QueueTool().waitEmpty();
1336: }
1337:
1338: private static DesignerPaneOperator getDesigner(String webPageTitle) {
1339: DesignerPaneOperator designer = new DesignerPaneOperator(
1340: RaveWindowOperator.getDefaultRave());
1341: return designer;
1342: }
1343:
1344: private static SheetTableOperator getSheetTableOperator(
1345: boolean strictComparison, boolean ignoreCase) {
1346: SheetTableOperator sto = new SheetTableOperator();
1347: sto.setCompareStyle(strictComparison, ignoreCase);
1348: return sto;
1349: }
1350:
1351: private static EditorOperator getJavaEditor() {
1352: EditorOperator editor = new EditorOperator(
1353: Util.getMainWindow(), JAVA_EDITOR_TITLE);
1354: new QueueTool().waitEmpty();
1355: Util.wait(1000);
1356: TestUtils.outMsg("+++ Source editor for [" + JAVA_EDITOR_TITLE
1357: + "] found");
1358: return editor;
1359: }
1360:
1361: private static void putCaretToBeginOfLastLine(EditorOperator editor) {
1362: if (System.getProperty("os.name").equals("Mac OS X"))
1363: editor.pushKey(KeyEvent.VK_END, KeyEvent.META_DOWN_MASK);
1364: else
1365: editor.pushKey(KeyEvent.VK_END, KeyEvent.CTRL_DOWN_MASK);
1366: Util.wait(1000);
1367: new QueueTool().waitEmpty();
1368: for (int i = 0; i < 2; ++i) {
1369: editor.pushUpArrowKey();
1370: Util.wait(500);
1371: new QueueTool().waitEmpty();
1372: }
1373: Util.wait(1000);
1374: new QueueTool().waitEmpty();
1375: }
1376:
1377: private static void deleteLastLines(EditorOperator editor,
1378: int lineCount) {
1379: editor.pushKey(KeyEvent.VK_END, KeyEvent.CTRL_DOWN_MASK);
1380: Util.wait(1000);
1381: new QueueTool().waitEmpty();
1382:
1383: for (int i = 0; i < lineCount; ++i) {
1384: editor.pushKey(KeyEvent.VK_UP, KeyEvent.SHIFT_DOWN_MASK);
1385: Util.wait(500);
1386: new QueueTool().waitEmpty();
1387: }
1388: editor.pushKey(KeyEvent.VK_DELETE, 0);
1389: Util.wait(1000);
1390: new QueueTool().waitEmpty();
1391: }
1392:
1393: private static WebResponse getWebResponseAfterDeployment(
1394: String requestPrefix) throws Throwable {
1395: WebResponse response = null;
1396: try {
1397: response = getResponseUsingWaiter(requestPrefix);
1398: } catch (TimeoutExpiredException tee) {
1399: throw new JemmyException(
1400: "Web response for URL ["
1401: + requestPrefix
1402: + "] has not been received in "
1403: + WEB_RESPONSE_RECEIVING_DELAY
1404: + " milliseconds (see the log of Application Server)");
1405: } catch (Throwable t) {
1406: String internalMsg = t.getMessage();
1407: if (internalMsg == null) {
1408: String errInfoMsg = "Web response was not received for URL ["
1409: + requestPrefix
1410: + "] due to ["
1411: + t.toString()
1412: + "]";
1413: throw new JemmyException(errInfoMsg, t);
1414: } else {
1415: t.printStackTrace();
1416: throw t;
1417: }
1418: }
1419: return response;
1420: }
1421:
1422: private static WebResponse getResponseUsingWaiter(
1423: String requestPrefix) throws Exception {
1424: Waiter responseWaiter = getResponseWaiter(requestPrefix);
1425: return ((WebResponse) responseWaiter.waitAction(null));
1426: }
1427:
1428: private static Waiter getResponseWaiter(final String requestPrefix) {
1429: final WebConversation webConversation = new WebConversation();
1430: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
1431: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
1432:
1433: Waiter responseWaiter = new Waiter(new Waitable() {
1434: public Object actionProduced(Object obj) {
1435: try {
1436: WebResponse webResponse = webConversation
1437: .getResponse(requestPrefix);
1438: return webResponse;
1439: } catch (Throwable t) {
1440: t.printStackTrace();
1441: }
1442: return null;
1443: }
1444:
1445: public String getDescription() {
1446: return ("Receiving web response");
1447: }
1448: });
1449: responseWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
1450: WEB_RESPONSE_RECEIVING_DELAY);
1451: return responseWaiter;
1452: }
1453:
1454: private static boolean isWebResponseOK(WebResponse response) {
1455: if ((response != null)
1456: && (response.getResponseCode() == WEB_RESPONSE_CODE_OK)) {
1457: return true;
1458: }
1459: return false;
1460: }
1461:
1462: private static String makeWebFormComponentID(String componentID) {
1463: return (WEB_PAGE_FORM_NAME + ":" + componentID);
1464: }
1465:
1466: private static Waiter getTextFieldValueWaiter(
1467: final String textField_ID) {
1468: Waiter dropdownWaiter = new Waiter(new Waitable() {
1469: public Object actionProduced(Object response) {
1470: try {
1471: String value = ((WebResponse) response).getForms()[0]
1472: .getParameterValue(makeWebFormComponentID(textField_ID));
1473: return value;
1474: } catch (Exception e) {
1475: e.printStackTrace();
1476: }
1477: return null;
1478: }
1479:
1480: public String getDescription() {
1481: return ("Getting values of Dropdown List...");
1482: }
1483: });
1484: dropdownWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
1485: 5000);
1486: return dropdownWaiter;
1487: }
1488:
1489: public static int getLabelIndex() {
1490: return 9;
1491: }
1492:
1493: public static void addBindingAttribute(String page,
1494: String full_component_path) {
1495: DocumentOutlineOperator outline = new DocumentOutlineOperator(
1496: RaveWindowOperator.getDefaultRave());
1497: TestUtils.wait(1000);
1498: JTreeOperator aotree = outline.getStructTreeOperator();
1499: aotree.callPopupOnPath(aotree.findPath(page + "|"
1500: + full_component_path));
1501: TestUtils.wait(1000);
1502: JPopupMenuOperator aopm = new JPopupMenuOperator();
1503: TestUtils.wait(1000);
1504: new JMenuItemOperator(aopm, addBindingAttribute).pushNoBlock();
1505: TestUtils.wait(1000);
1506: }
1507: }
|