1 19 20 21 package org.netbeans.test.j2ee; 22 23 import java.io.File ; 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 ; 37 import java.util.Hashtable ; 38 import java.util.Properties ; 39 import javax.naming.Context ; 40 import javax.naming.InitialContext ; 41 import javax.rmi.PortableRemoteObject ; 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 56 public class AppserverValidation extends JellyTestCase { 57 58 public static final String EAR_PROJECT_NAME = "TestDebugEAR"; 59 public static final String EJB_PROJECT_NAME = EAR_PROJECT_NAME + "-EJBModule"; 60 61 public static final String EAR_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_PROJECT_NAME; 62 public static final String 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 openSourceAction = Bundle.getStringTrimmed("org.openide.actions.Bundle", "Open"); 69 70 71 public AppserverValidation(String 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 (new Runnable () { 132 public void run() { 133 Properties env = new Properties (); 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 initial = new InitialContext (env); 138 Object 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 ne) { 143 fail("unable to find ejb/TestDebugBean"); 144 } catch (javax.ejb.CreateException ce) { 145 fail(); 146 } catch (java.rmi.RemoteException 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 [] {"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 [] {"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 [] {"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 221 public static void main(java.lang.String [] args) { 222 TestRunner.run(suite()); 224 } 225 226 } 227 | Popular Tags |