KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > AppserverValidation


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.test.j2ee;
22
23 import java.io.File JavaDoc;
24 import junit.textui.TestRunner;
25 import org.netbeans.jellytools.*;
26 import org.netbeans.jellytools.nodes.JavaNode;
27 import org.netbeans.jellytools.nodes.Node;
28 import org.netbeans.jellytools.nodes.ProjectRootNode;
29 import org.netbeans.jemmy.operators.JFrameOperator;
30 import org.netbeans.junit.NbTestSuite;
31 import org.netbeans.junit.ide.ProjectSupport;
32 import org.netbeans.jellytools.actions.Action;
33 import org.netbeans.test.j2ee.lib.J2eeProjectSupport;
34 import org.netbeans.test.j2ee.lib.Utils;
35 import org.netbeans.test.j2ee.lib.ProgressSupport;
36 import java.awt.event.KeyEvent JavaDoc;
37 import java.util.Hashtable JavaDoc;
38 import java.util.Properties JavaDoc;
39 import javax.naming.Context JavaDoc;
40 import javax.naming.InitialContext JavaDoc;
41 import javax.rmi.PortableRemoteObject JavaDoc;
42 import org.netbeans.test.j2ee.debug.TestDebugRemote;
43 import org.netbeans.test.j2ee.debug.TestDebugRemoteHome;
44 import org.netbeans.jellytools.Bundle;
45 import org.netbeans.jellytools.NbDialogOperator;
46 import org.netbeans.jellytools.TopComponentOperator;
47 import org.netbeans.jellytools.actions.CloseAllDocumentsAction;
48 import org.netbeans.jemmy.operators.*;
49 import java.util.*;
50 import org.netbeans.jemmy.operators.JMenuBarOperator;
51
52 /**
53  *
54  * @author jhorvath
55  */

56 public class AppserverValidation extends JellyTestCase {
57     
58     public static final String JavaDoc EAR_PROJECT_NAME = "TestDebugEAR";
59     public static final String JavaDoc EJB_PROJECT_NAME = EAR_PROJECT_NAME + "-EJBModule";
60     
61     public static final String JavaDoc EAR_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_PROJECT_NAME;
62     public static final String JavaDoc EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_PROJECT_NAME + File.separator + EAR_PROJECT_NAME+ "-ejb";
63     
64     
65     
66     int modifiers;
67     
68     public static String JavaDoc openSourceAction = Bundle.getStringTrimmed("org.openide.actions.Bundle", "Open");
69     
70     /** Need to be defined because of JUnit */
71     public AppserverValidation(String JavaDoc name) {
72         super(name);
73     }
74     
75     public static NbTestSuite suite() {
76         NbTestSuite suite = new NbTestSuite();
77         suite.addTest(new AppserverValidation("addAppserver"));
78         suite.addTest(new AppserverValidation("startAppserver"));
79         suite.addTest(new AppserverValidation("deployEJBModule"));
80         suite.addTest(new AppserverValidation("addBreakpoint"));
81         suite.addTest(new AppserverValidation("debugEJBModule"));
82         suite.addTest(new AppserverValidation("startAppClient"));
83         suite.addTest(new AppserverValidation("undeployEJBModule"));
84         suite.addTest(new AppserverValidation("deployEAR"));
85         suite.addTest(new AppserverValidation("undeployEAR"));
86         suite.addTest(new AppserverValidation("stopAppserver"));
87         return suite;
88     }
89     
90     
91     public void setUp() {
92         System.out.println("######## "+getName()+" #######");
93         if (System.getProperty("os.name").startsWith("Mac OS X")) {
94             modifiers = KeyEvent.META_DOWN_MASK;
95         } else {
96             modifiers = KeyEvent.CTRL_DOWN_MASK;
97         }
98     }
99     
100     public void tearDown() {
101     }
102     
103     public void addAppserver() {
104         Utils.addAppServer();
105     }
106     
107     public void startAppserver() {
108         Utils.startStopServer(true);
109     }
110     
111     public void stopAppserver() {
112         Utils.startStopServer(false);
113     }
114
115     
116     public void addBreakpoint() {
117         ProjectsTabOperator projectTab=ProjectsTabOperator.invoke();
118         ProjectRootNode prn = projectTab.getProjectRootNode(EJB_PROJECT_NAME);
119         new org.netbeans.jemmy.EventTool().waitNoEvent(1000);
120         JavaNode javaNode = new JavaNode(prn, "Source Packages|test|TestDebugBean.java");
121         javaNode.select();
122         javaNode.performPopupAction(openSourceAction);
123         EditorOperator editorOperator = new EditorOperator("TestDebugBean.java");
124         editorOperator.setCaretPosition(63, 1);
125         editorOperator.pushKey(KeyEvent.VK_F8, modifiers);
126     }
127     
128     public void startAppClient() {
129         MainWindowOperator.StatusTextTracer stt = MainWindowOperator.getDefault().getStatusTextTracer();
130         stt.start();
131         new Thread JavaDoc(new Runnable JavaDoc() {
132             public void run() {
133                 Properties JavaDoc env = new Properties JavaDoc();
134                 env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
135                 env.put(Context.PROVIDER_URL, "iiop://localhost:3700");
136                 try {
137                     Context JavaDoc initial = new InitialContext JavaDoc(env);
138                     Object JavaDoc objref = initial.lookup("ejb/TestDebugBean");
139                     TestDebugRemoteHome testDebugRH = (TestDebugRemoteHome)PortableRemoteObject.narrow(objref, TestDebugRemoteHome.class);
140                     TestDebugRemote testDebugRemote=testDebugRH.create();
141                     testDebugRemote.testMethod();
142                 } catch (javax.naming.NamingException JavaDoc ne) {
143                     fail("unable to find ejb/TestDebugBean");
144                 } catch (javax.ejb.CreateException JavaDoc ce) {
145                     fail();
146                 } catch (java.rmi.RemoteException JavaDoc re) {
147                     fail();
148                 }
149             };
150         }, "appserver client thread").start();
151         MainWindowOperator.getDefault().waitStatusText("Thread p: thread-pool-1; w: 2 stopped at TestDebugBean.java:63.");
152         MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F5, KeyEvent.SHIFT_MASK);
153         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
154     }
155     
156     public void debugEJBModule() {
157         ProjectsTabOperator projectTab=ProjectsTabOperator.invoke();
158         ProjectRootNode prn = projectTab.getProjectRootNode(EJB_PROJECT_NAME);
159         new org.netbeans.jemmy.EventTool().waitNoEvent(1000);
160         prn.performPopupAction(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjarproject.ui.Bundle", "LBL_DebugAction_Name"));
161         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
162         MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 300000);
163         MainWindowOperator.getDefault().waitStatusText(Bundle.getString("org.apache.tools.ant.module.run.Bundle", "FMT_finished_target_status", new String JavaDoc[] {"build.xml (debug)"}));
164     }
165     
166     public void deployEJBModule() {
167         System.err.println(EJB_PROJECT_PATH);
168         J2eeProjectSupport.openProject(EJB_PROJECT_PATH);
169         new org.netbeans.jemmy.EventTool().waitNoEvent(1000);
170         ProjectsTabOperator projectTab=ProjectsTabOperator.invoke();
171         ProjectRootNode prn = projectTab.getProjectRootNode(EJB_PROJECT_NAME);
172         new org.netbeans.jemmy.EventTool().waitNoEvent(1000);
173         prn.performPopupAction(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjarproject.ui.Bundle", "LBL_RedeployAction_Name"));
174         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
175         MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 300000);
176         MainWindowOperator.getDefault().waitStatusText(Bundle.getString("org.apache.tools.ant.module.run.Bundle", "FMT_finished_target_status", new String JavaDoc[] {"build.xml (run)"}));
177     }
178     
179     public void deployEAR() {
180         J2eeProjectSupport.openProject(EAR_PROJECT_PATH);
181         new org.netbeans.jemmy.EventTool().waitNoEvent(1000);
182         ProjectsTabOperator projectTab=ProjectsTabOperator.invoke();
183         ProjectRootNode prn = projectTab.getProjectRootNode(EAR_PROJECT_NAME);
184         new org.netbeans.jemmy.EventTool().waitNoEvent(1000);
185         prn.performPopupAction(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.earproject.ui.Bundle", "LBL_DeployAction_Name"));
186         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
187         MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 300000);
188         MainWindowOperator.getDefault().waitStatusText(Bundle.getString("org.apache.tools.ant.module.run.Bundle", "FMT_finished_target_status", new String JavaDoc[] {"build.xml (run-deploy)"}));
189     }
190     
191     
192     public void undeployEJBModule() {
193         RuntimeTabOperator runtimeTab = RuntimeTabOperator.invoke();
194         Node serverNode = new Node(runtimeTab.getRootNode(), Bundle.getStringTrimmed("org.netbeans.modules.j2ee.deployment.impl.ui.Bundle", "SERVER_REGISTRY_NODE")
195         +"|Application Server");
196         Node applicationsNode = new Node(serverNode, Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle", "LBL_Applications"));
197         Node ejbModulesNode = new Node(applicationsNode, Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle", "LBL_EjbModules"));
198         ejbModulesNode.performPopupAction(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.actions.Bundle", "LBL_RefreshAction"));
199         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
200         Node ejbModuleNode = new Node(ejbModulesNode, EJB_PROJECT_NAME);
201         ejbModuleNode.performPopupAction(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle", "LBL_Undeploy"));
202         new org.netbeans.jemmy.EventTool().waitNoEvent(10000);
203         if (ejbModulesNode.isChildPresent(EJB_PROJECT_NAME)) fail("Project is not undeployed");
204     }
205     
206     public void undeployEAR() {
207         RuntimeTabOperator runtimeTab = RuntimeTabOperator.invoke();
208         Node serverNode = new Node(runtimeTab.getRootNode(), Bundle.getStringTrimmed("org.netbeans.modules.j2ee.deployment.impl.ui.Bundle", "SERVER_REGISTRY_NODE")
209         +"|Application Server");
210         Node applicationsNode = new Node(serverNode, Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle", "LBL_Applications"));
211         Node earNode = new Node(applicationsNode, Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle", "LBL_AppModules"));
212         earNode.performPopupAction(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.actions.Bundle", "LBL_RefreshAction"));
213         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
214         Node projectNode = new Node(earNode, EAR_PROJECT_NAME);
215         projectNode.performPopupAction(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle", "LBL_Undeploy"));
216         new org.netbeans.jemmy.EventTool().waitNoEvent(10000);
217         if (earNode.isChildPresent(EAR_PROJECT_NAME)) fail("Project is not undeployed");
218     }
219     
220     /** Use for execution inside IDE */
221     public static void main(java.lang.String JavaDoc[] args) {
222         // run whole suite
223
TestRunner.run(suite());
224     }
225     
226 }
227
Popular Tags