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:
043: package org.netbeans.test.ejb;
044:
045: import org.netbeans.jemmy.operators.*;
046: import org.netbeans.jemmy.*;
047: import org.netbeans.junit.NbTestSuite;
048: import junit.framework.Test;
049: import junit.framework.*;
050:
051: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
052: import org.netbeans.modules.visualweb.gravy.model.deployment.ApplicationServer;
053: import org.netbeans.modules.visualweb.gravy.plugins.PluginsOperator;
054: import org.netbeans.modules.visualweb.gravy.*;
055:
056: import javax.swing.tree.*;
057: import java.awt.event.*;
058: import java.io.*;
059:
060: /**
061: *
062: * @author Roman Mostyka
063: */
064: public class EJBAppSubnodeTest extends RaveTestCase {
065:
066: private static String pluginName = "Visual Web JSF Backwards Compatibility Kit";
067: public String _projectPath = System.getProperty("xtest.workdir")
068: + File.separator + "projects" + File.separator;
069: public String _projectName = "HelloWorldEJB";
070: public ServerNavigatorOperator server;
071: public JTreeOperator sntree;
072:
073: public EJBAppSubnodeTest(String testName) {
074: super (testName);
075: }
076:
077: public static Test suite() {
078: NbTestSuite suite = new NbTestSuite("EJB Application Subnode");
079: suite.addTest(new EJBAppSubnodeTest("testPreparation"));
080: suite.addTest(new EJBAppSubnodeTest(
081: "testEJB_Subnode_01_CheckPopupMenu"));
082: suite.addTest(new EJBAppSubnodeTest(
083: "testEJB_Subnode_02_ExpandCollapse"));
084: suite
085: .addTest(new EJBAppSubnodeTest(
086: "testEJB_Subnode_04_Modify"));
087: suite
088: .addTest(new EJBAppSubnodeTest(
089: "testEJB_Subnode_05_Remove"));
090: suite.addTest(new EJBAppSubnodeTest(
091: "testEJB_Subnode_06_Properties"));
092: /*
093: // can't be automated: suite.addTest(new EJBAppSubnodeTest("testEJB_Subnode_03_Refresh"));
094: */
095: return suite;
096: }
097:
098: /** method called before each testcase
099: */
100: protected void setUp() {
101: }
102:
103: public void testPreparation() {
104: PluginsOperator.getInstance().installAvailablePlugins(
105: pluginName);
106: ApplicationServer as = EJBTestUtils.getApplicationServer();
107: as.start();
108: TestUtils.wait(1000);
109: }
110:
111: public void testEJB_Subnode_01_CheckPopupMenu() {
112: String ejbSetName = "ValidJAR", ejbJarDir = "EJB_Valid_JAR_Valid_EAR", ejbJarName = ejbJarDir
113: + "Client.jar";
114: EJBTestUtils.addEJB(ejbSetName,
115: EJBTestUtils.RMI_IIOP_PORT_APPSERVER,
116: EJBTestUtils.EJB_JARS_PATH + File.separator + ejbJarDir
117: + File.separator + ejbJarName, "");
118: EJBTestUtils.endAddEJB();
119: server.showNavigatorOperator().getTree().findPath(
120: EJBTestUtils.ejbNode + "|" + ejbSetName);
121: TestUtils.wait(1000);
122:
123: String ejbSetNodeName = ejbSetName, ejbSetPath = EJBTestUtils.ejbNode
124: + "|" + ejbSetNodeName;
125:
126: server = ServerNavigatorOperator.showNavigatorOperator();
127: Util.wait(1000);
128: sntree = server.getTree();
129: sntree.callPopupOnPath(sntree.findPath(ejbSetPath));
130: Util.wait(1000);
131:
132: JPopupMenuOperator snpm = new JPopupMenuOperator();
133: Util.wait(1000);
134:
135: checkPopupMenuItems(snpm);
136: Util.wait(1000);
137:
138: sntree.pressKey(KeyEvent.VK_ESCAPE);
139: try {
140: snpm = new JPopupMenuOperator();
141: fail("Popup menu of EJB set [" + ejbSetNodeName
142: + "] is still visible, but it should disappear");
143: } catch (Exception e) {
144: TestUtils.outMsg("+++ Popup menu of EJB set ["
145: + ejbSetNodeName
146: + "] has disappeared after pressing ESC");
147: }
148: Util.wait(1000);
149:
150: sntree.callPopupOnPath(sntree.findPath(ejbSetPath));
151: Util.wait(1000);
152: snpm = new JPopupMenuOperator();
153: Util.wait(1000);
154: sntree.clickOnPath(sntree.findPath(EJBTestUtils.ejbNode));
155: Util.wait(1000);
156: try {
157: snpm = new JPopupMenuOperator();
158: fail("Popup menu of EJB set [" + ejbSetNodeName
159: + "] is still visible, but it should disappear");
160: } catch (Exception e) {
161: TestUtils
162: .outMsg("+++ Popup menu of EJB set ["
163: + ejbSetNodeName
164: + "] has disappeared after click of mouse button on the other place");
165: }
166:
167: }
168:
169: private void checkPopupMenuItems(JPopupMenuOperator menuOperator) {
170: EJBTestUtils.checkPopupMenuItemList(menuOperator, new String[] {
171: EJBTestUtils.refreshPopup, EJBTestUtils.modifyPopup,
172: EJBTestUtils.removePopup, EJBTestUtils.configurePopup,
173: EJBTestUtils.exportPopup });
174: }
175:
176: public void testEJB_Subnode_02_ExpandCollapse() {
177: String ejbSetName = "ValidJAR", ejbSetNodeName = ejbSetName, ejbNodeName = "GreeterEJB_HelloWorld", ejbSetPath = EJBTestUtils.ejbNode
178: + "|" + ejbSetNodeName, ejbPath = ejbSetPath + "|"
179: + ejbNodeName;
180:
181: server = ServerNavigatorOperator.showNavigatorOperator();
182: Util.wait(1000);
183: sntree = server.getTree();
184:
185: TreePath ejbTreePath = sntree.findPath(ejbPath);
186: Util.wait(1000);
187:
188: TestUtils.outMsg("+++ Tree path [" + ejbPath
189: + "] is expanded = " + sntree.isExpanded(ejbTreePath));
190:
191: sntree.expandPath(ejbTreePath);
192: Util.wait(1000);
193:
194: if (sntree.isExpanded(ejbTreePath)) {
195: TestUtils.outMsg("+++ Tree path [" + ejbPath
196: + "] is expanded = "
197: + sntree.isExpanded(ejbTreePath));
198: } else {
199: fail("Tree path [" + ejbPath + "] isn't expanded");
200: }
201:
202: TreePath rootEjbTreePath = sntree
203: .findPath(EJBTestUtils.ejbNode);
204: TestUtils.outMsg("+++ Tree path [" + EJBTestUtils.ejbNode
205: + "] is collapsed = "
206: + sntree.isCollapsed(rootEjbTreePath));
207:
208: sntree.collapsePath(rootEjbTreePath);
209: Util.wait(1000);
210: if (sntree.isCollapsed(rootEjbTreePath)) {
211: TestUtils.outMsg("+++ Tree path [" + EJBTestUtils.ejbNode
212: + "] is collapsed = "
213: + sntree.isCollapsed(rootEjbTreePath));
214: } else {
215: fail("Tree path [" + EJBTestUtils.ejbNode
216: + "] isn't collapsed");
217: }
218: EJBTestUtils.removeEJB(ejbSetName);
219: }
220:
221: /**
222: * Can't be automated (see test specification)
223: */
224: public void testEJB_Subnode_03_Refresh() {
225: EJBTestUtils.addEJB("13700", EJBTestUtils.EJB_JARS_PATH
226: + File.separator + "Example01" + File.separator
227: + "Example01Client.jar", EJBTestUtils.EJB_JARS_PATH
228: + File.separator + "Example01" + File.separator
229: + "Example01.ear");
230: EJBTestUtils.endAddEJB();
231: // undeploy EJB set
232: // modify its source code to add new business method
233: // modify or create new appropriate EAR-file
234: // deploy modified EAR-file
235: server = ServerNavigatorOperator.showNavigatorOperator();
236: Util.wait(1000);
237: server.pushPopup(EJBTestUtils.ejbNode + "|DeployedEjbApp1",
238: EJBTestUtils.refreshPopup);
239: }
240:
241: public void testEJB_Subnode_04_Modify() {
242: String ejbSetName = "Modified_EJB_Set", ejbJarDir = "EJB_Valid_JAR_Valid_EAR", ejbJarName = ejbJarDir
243: + "Client.jar";
244: EJBTestUtils.addEJB(ejbSetName, "23700",
245: EJBTestUtils.EJB_JARS_PATH + File.separator + ejbJarDir
246: + File.separator + ejbJarName, "");
247: EJBTestUtils.endAddEJB();
248: server.showNavigatorOperator().getTree().findPath(
249: EJBTestUtils.ejbNode + "|" + ejbSetName);
250: Util.wait(1000);
251:
252: // create and verify application (the exception should be thrown after project deployment:
253: // javax.naming.NameNotFoundException: No object bound for java:comp/env/GreeterEJB_HelloWorld)
254: String errMsg = EJBTestUtils.createProjectWithEJB(ejbSetName,
255: "getGreeting", null, "NameNotFoundException", false,
256: false);
257: String prjName = EJBTestUtils.getLastCreatedPrjName();
258: if (errMsg == null) {
259: String textField_ID = EJBTestUtils.getLastTextField_ID();
260: EJBTestUtils.modifyEJBSet(ejbSetName, 2,
261: EJBTestUtils.RMI_IIOP_PORT_APPSERVER);
262: errMsg = EJBTestUtils.checkDeploymentWithEJB(prjName,
263: textField_ID, "Hello World", true);
264: EJBTestUtils.doSaveAll();
265: }
266: EJBTestUtils.removeEJB(ejbSetName);
267: Util.wait(1000);
268: new QueueTool().waitEmpty();
269: EJBTestUtils.doCloseProject(prjName);
270: Util.wait(1000);
271: new QueueTool().waitEmpty();
272: if (errMsg != null) {
273: Assert.fail(errMsg);
274: }
275: }
276:
277: public void testEJB_Subnode_05_Remove() {
278: String ejbSetName = "Removed_EJB_Set", ejbJarDir = "EJB_Valid_JAR_Valid_EAR", ejbJarName = ejbJarDir
279: + "Client.jar";
280: EJBTestUtils.addEJB(ejbSetName,
281: EJBTestUtils.RMI_IIOP_PORT_APPSERVER,
282: EJBTestUtils.EJB_JARS_PATH + File.separator + ejbJarDir
283: + File.separator + ejbJarName, "");
284: EJBTestUtils.endAddEJB();
285: Util.wait(1000);
286:
287: EJBTestUtils.removeEJB(ejbSetName);
288: Util.wait(1000);
289: try {
290: server.showNavigatorOperator().getTree().findPath(
291: EJBTestUtils.ejbNode + "|" + ejbSetName);
292: fail("EJB Set [" + ejbSetName + "] has not been removed.");
293: } catch (Exception e) {
294: TestUtils.outMsg("+++ EJB Set [" + ejbSetName
295: + "] has been removed.");
296: }
297: }
298:
299: public void testEJB_Subnode_06_Properties() {
300: String oldEjbSetName = "EJB_Set_Old", ejbJarDir = "EJB_Valid_JAR_Valid_EAR", ejbJarName = ejbJarDir
301: + "Client.jar", newEjbSetName = "EJB_Set_New", newRMIPort = "12345", newServerHost = "new_server_host";
302: EJBTestUtils.addEJB(oldEjbSetName,
303: EJBTestUtils.RMI_IIOP_PORT_APPSERVER,
304: EJBTestUtils.EJB_JARS_PATH + File.separator + ejbJarDir
305: + File.separator + ejbJarName, "");
306: EJBTestUtils.endAddEJB();
307: Util.wait(1000);
308:
309: server = ServerNavigatorOperator.showNavigatorOperator();
310: Util.wait(1000);
311: sntree = server.getTree();
312: try {
313: sntree.selectPath(sntree.findPath(EJBTestUtils.ejbNode
314: + "|" + oldEjbSetName));
315: TestUtils.outMsg("+++ EJB Set [" + oldEjbSetName
316: + "] has been found.");
317: } catch (Exception e) {
318: fail("+++ EJB Set [" + oldEjbSetName
319: + "] has not been found.");
320: }
321: EJBTestUtils.changeEjbSetProperties(newEjbSetName, newRMIPort,
322: newServerHost);
323: EJBTestUtils.verifyModifiedEJBSet(newEjbSetName, new String[] {
324: newEjbSetName, newServerHost, newRMIPort });
325:
326: EJBTestUtils.removeEJB(newEjbSetName);
327: TestUtils.wait(1000);
328: }
329: }
|