1 19 20 package org.netbeans.test.j2ee; 21 import java.io.File ; 22 import java.io.FilenameFilter ; 23 import java.io.IOException ; 24 import java.util.Arrays ; 25 import junit.textui.TestRunner; 26 import org.netbeans.jellytools.*; 27 import org.netbeans.jellytools.actions.DeleteAction; 28 import org.netbeans.jellytools.actions.OpenAction; 29 import org.netbeans.jellytools.nodes.Node; 30 import org.netbeans.jemmy.TimeoutExpiredException; 31 import org.netbeans.jemmy.operators.*; 32 import org.netbeans.junit.NbTestSuite; 33 import org.netbeans.junit.ide.ProjectSupport; 34 import org.netbeans.test.j2ee.addmethod.*; 35 import org.netbeans.test.j2ee.lib.Utils; 36 37 38 44 public class EJBValidation extends JellyTestCase { 45 46 public static final String EAR_PROJECT_NAME = "TestingEntApp"; 47 public static final String WEB_PROJECT_NAME = EAR_PROJECT_NAME + "-WebModule"; 48 public static final String EJB_PROJECT_NAME = EAR_PROJECT_NAME + "-EJBModule"; 49 50 public static final String EAR_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_PROJECT_NAME; 51 public static final String EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_PROJECT_NAME + File.separator + EAR_PROJECT_NAME + "-ejb"; 52 public static final String WEB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_PROJECT_NAME + File.separator + EAR_PROJECT_NAME + "-war"; 53 54 55 56 public EJBValidation(String name) { 57 super(name); 58 } 59 60 public static NbTestSuite suite() { 61 NbTestSuite suite = new NbTestSuite(); 62 63 suite.addTest(new EJBValidation("openProjects")); 64 suite.addTest(new AddMethodTest("testAddBusinessMethod1InSB")); 65 suite.addTest(new AddMethodTest("testAddBusinessMethod2InSB")); 66 suite.addTest(new AddMethodTest("testAddBusinessMethod1InEB")); 67 suite.addTest(new AddMethodTest("testAddBusinessMethod2InEB")); 68 suite.addTest(new AddMethodTest("testAddCreateMethod1InEB")); 69 suite.addTest(new AddMethodTest("testAddCreateMethod2InEB")); 70 suite.addTest(new AddMethodTest("testAddHomeMethod1InEB")); 71 suite.addTest(new AddMethodTest("testAddHomeMethod2InEB")); 72 suite.addTest(new GenerateDTOTest("testGenerateDTO")); 73 suite.addTest(new GenerateDTOTest("testDeleteDTO")); 74 suite.addTest(new AddFinderMethodTest("testAddFinderMethod1InEB")); 75 suite.addTest(new AddFinderMethodTest("testAddFinderMethod2InEB")); 76 suite.addTest(new AddSelectMethodTest("testAddSelectMethod1InEB")); 77 suite.addTest(new AddSelectMethodTest("testAddSelectMethod2InEB")); 78 suite.addTest(new AddCMPFieldTest("testAddCMPField1InEB")); 79 suite.addTest(new AddCMPFieldTest("testAddCMPField2InEB")); 80 suite.addTest(new CallEJBTest("testCallEJBInServlet")); 81 suite.addTest(new CallEJBTest("testCallEJB1InSB")); 82 suite.addTest(new CallEJBTest("testCallEJB2InSB")); 83 suite.addTest(new SendMessageTest("testSendMessage1InSB")); 86 suite.addTest(new EJBValidation("testDeleteEntityBean")); 91 92 suite.addTest(new EJBValidation("closeProjects")); 94 return suite; 95 } 96 97 98 public static void main(java.lang.String [] args) { 99 TestRunner.run(suite()); 101 102 109 } 112 113 public void setUp() { 114 System.out.println("######## "+getName()+" #######"); 115 } 116 117 public void tearDown() { 118 } 119 120 public void openProjects() { 121 ProjectSupport.openProject(EAR_PROJECT_PATH); 122 ProjectSupport.waitScanFinished(); 123 ProjectSupport.openProject(EJB_PROJECT_PATH); 124 ProjectSupport.waitScanFinished(); 125 ProjectSupport.openProject(WEB_PROJECT_PATH); 126 ProjectSupport.waitScanFinished(); 127 128 try { new NbDialogOperator("Open Project").ok(); } 130 catch (TimeoutExpiredException e) {} 131 132 new org.netbeans.jemmy.EventTool().waitNoEvent(5000); 133 134 String files[] = { "TestingSession", "TestingEntity" }; 135 for (int i=0; i<files.length; i++) { 136 Node openFile = new Node(new ProjectsTabOperator().getProjectRootNode(EJBValidation.EJB_PROJECT_NAME), 137 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node") 138 +"|"+files[i]); 139 new OpenAction().performAPI(openFile); 140 EditorOperator editor = new EditorWindowOperator().getEditor(files[i]+"Bean.java"); 141 } 142 new org.netbeans.jemmy.EventTool().waitNoEvent(2000); 143 } 144 145 public void closeProjects() { 146 new EditorWindowOperator().getEditor().closeDiscardAll(); 147 ProjectSupport.closeProject(EAR_PROJECT_NAME); 148 ProjectSupport.closeProject(EJB_PROJECT_NAME); 149 ProjectSupport.closeProject(WEB_PROJECT_NAME); 150 } 151 152 public void prepareDatabase() { 153 Utils.prepareDatabase(); 154 new org.netbeans.jemmy.EventTool().waitNoEvent(2000); 155 } 156 157 public void testDeleteEntityBean() throws IOException { 158 Node node = new Node(new ProjectsTabOperator().getProjectRootNode(EJBValidation.EJB_PROJECT_NAME), 159 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node") 160 +"|TestingEntityEB"); 161 new DeleteAction().performAPI(node); 162 NbDialogOperator dialog = new NbDialogOperator(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "MSG_ConfirmDeleteObjectTitle")); 163 new JCheckBoxOperator(dialog).changeSelection(true); 164 dialog.yes(); 165 166 new org.netbeans.jemmy.EventTool().waitNoEvent(2000); 167 Utils utils = new Utils(this); 168 String ddNames[] = { "ejb-jar.xml", 169 "sun-ejb-jar.xml"}; 170 utils.assertFiles(new File (EJBValidation.EJB_PROJECT_PATH + File.separator + "src" + File.separator + "conf"), ddNames, getName()+"_"); 171 172 File dir = new File (EJBValidation.EJB_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "test"); 173 String deletedFiles[] = dir.list(new FilenameFilter () { 174 public boolean accept(File dir, String name) { 175 return name.endsWith(".java") && name.startsWith("TestingEntity") && !name.equals("TestingEntityDTO.java"); 176 } 177 }); 178 if (deletedFiles != null && deletedFiles.length > 0) { 179 fail("Bean files was not deleted from directory "+dir.getAbsolutePath()+". I found "+Arrays.asList(deletedFiles)); 180 } 181 } 182 183 public void testStartServer() throws IOException { 184 Utils.startStopServer(true); 185 String url = "http://localhost:8080/"; 186 String page = Utils.loadFromURL(url); 187 log(page); 188 String text = "Your server is up and running"; 189 assertTrue("AppServer start page doesn't contain text '"+text+"'. See log for page content.", page.indexOf(text)>=0); 190 } 191 192 public void testDeployment() throws IOException { 193 final String CONTROL_TEXT = "ControlTextABC"; 194 Utils utils = new Utils(this); 195 196 Node openFile = new Node(new ProjectsTabOperator().getProjectRootNode(EJBValidation.EJB_PROJECT_NAME), 197 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node") 198 +"|TestingSession"); 199 new OpenAction().performAPI(openFile); 200 utils.checkAndModify("TestingSessionBean.java", 61, "public String testBusinessMethod1()", 63, "return null;", 63, true, "return \""+CONTROL_TEXT+"\";\n"); 201 utils.checkAndModify("TestingSessionBean.java", 103, "// javax.jms.TextMessage tm = session.createTextMessage();", 0, null, 103, true, "javax.jms.TextMessage tm = session.createTextMessage();\n"); 202 utils.checkAndModify("TestingSessionBean.java", 104, "// tm.setText(messageData.toString());", 0, null, 104, true, "tm.setText(messageData.toString());\n"); 203 utils.checkAndModify("TestingSessionBean.java", 105, "// return tm;", 0, null, 105, true, "return tm;\n"); 204 205 openFile = new Node(new ProjectsTabOperator().getProjectRootNode(EJBValidation.WEB_PROJECT_NAME), 206 Bundle.getStringTrimmed("org.netbeans.modules.web.project.ui.Bundle", "LBL_Node_Sources") 207 +"|test|TestingServlet"); 208 new OpenAction().performAPI(openFile); 209 utils.checkAndModify("TestingServlet.java", 36, "out.println(\"</body>\");", 0, null, 36, false, "out.println(lookupTestingSessionBean().testBusinessMethod1());\n"); 210 211 String page = Utils.deploy(EAR_PROJECT_NAME, "http://localhost:8080/TestingEntApp-WebModule/TestingServlet"); 212 log(page); 213 assertTrue("TestingServlet doesn't contain expected text '"+CONTROL_TEXT+"'. See log for page content.", page.indexOf(CONTROL_TEXT)>=0); 214 } 215 216 public void testUndeploy() { 217 Utils.undeploy(EAR_PROJECT_NAME); 218 } 219 220 221 public void testStopServer() { 222 Utils.startStopServer(false); 223 String url = "http://localhost:8080/"; 224 try { 225 String page = Utils.loadFromURL(url); 226 log(page); 227 fail("AppServer should not be running, but start page is available. See log for page content."); 228 } catch (IOException e) {} 229 } 230 231 } 232 | Popular Tags |