KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.test.j2ee;
21 import java.io.File JavaDoc;
22 import java.io.FilenameFilter JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Arrays JavaDoc;
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 /**
39  * EJBValidation suite for J2EE.
40  *
41  *
42  * @author libor.martinek@sun.com
43  */

44 public class EJBValidation extends JellyTestCase {
45     
46     public static final String JavaDoc EAR_PROJECT_NAME = "TestingEntApp";
47     public static final String JavaDoc WEB_PROJECT_NAME = EAR_PROJECT_NAME + "-WebModule";
48     public static final String JavaDoc EJB_PROJECT_NAME = EAR_PROJECT_NAME + "-EJBModule";
49     
50     public static final String JavaDoc EAR_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_PROJECT_NAME;
51     public static final String JavaDoc EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_PROJECT_NAME + File.separator + EAR_PROJECT_NAME + "-ejb";
52     public static final String JavaDoc WEB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_PROJECT_NAME + File.separator + EAR_PROJECT_NAME + "-war";
53
54     
55     /** Need to be defined because of JUnit */
56     public EJBValidation(String JavaDoc 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 EJBValidation("prepareDatabase"));
84
//suite.addTest(new UseDatabaseTest("testUseDatabase1InSB"));
85
suite.addTest(new SendMessageTest("testSendMessage1InSB"));
86         //suite.addTest(new EJBValidation("testStartServer"));
87
//suite.addTest(new EJBValidation("testDeployment"));
88
//suite.addTest(new EJBValidation("testUndeploy"));
89
//suite.addTest(new CreateCMPBeansFromDB("testCreateCMPBeansFromDB"));
90
suite.addTest(new EJBValidation("testDeleteEntityBean"));
91
92         //suite.addTest(new EJBValidation("testStopServer"));
93
suite.addTest(new EJBValidation("closeProjects"));
94         return suite;
95     }
96     
97     /** Use for execution inside IDE */
98     public static void main(java.lang.String JavaDoc[] args) {
99         // run whole suite
100
TestRunner.run(suite());
101
102         /*
103         NbTestSuite suite = new NbTestSuite();
104         suite.addTest(new GUIValidation("openProjects"));
105         suite.addTest(new GUIValidation("prepareDatabase"));
106         suite.addTest(new CreateCMPBeansFromDB("testCreateCMPBeansFromDB"));
107         TestRunner.run(suite);
108         */

109         // run only selected test case
110
//junit.textui.TestRunner.run(new GUIValidation("testDeleteWSinWeb"));
111
}
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         //TEMPORARY HACK
129
try { new NbDialogOperator("Open Project").ok(); }
130         catch (TimeoutExpiredException e) {}
131
132         new org.netbeans.jemmy.EventTool().waitNoEvent(5000);
133         
134         String JavaDoc 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 JavaDoc {
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 JavaDoc ddNames[] = { "ejb-jar.xml",
169                              "sun-ejb-jar.xml"};
170         utils.assertFiles(new File JavaDoc(EJBValidation.EJB_PROJECT_PATH + File.separator + "src" + File.separator + "conf"), ddNames, getName()+"_");
171
172         File JavaDoc dir = new File JavaDoc(EJBValidation.EJB_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "test");
173         String JavaDoc deletedFiles[] = dir.list(new FilenameFilter JavaDoc () {
174             public boolean accept(File JavaDoc dir, String JavaDoc 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 JavaDoc {
184         Utils.startStopServer(true);
185         String JavaDoc url = "http://localhost:8080/";
186         String JavaDoc page = Utils.loadFromURL(url);
187         log(page);
188         String JavaDoc 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 JavaDoc {
193         final String JavaDoc 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 JavaDoc 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 JavaDoc url = "http://localhost:8080/";
224         try {
225             String JavaDoc 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 JavaDoc e) {}
229     }
230       
231 }
232
Popular Tags