KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > addmethod > AddMethodTest


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.addmethod;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import org.netbeans.jellytools.*;
25 import org.netbeans.jellytools.actions.ActionNoBlock;
26 import org.netbeans.jellytools.actions.OpenAction;
27 import org.netbeans.jellytools.nodes.Node;
28 import org.netbeans.jemmy.JemmyException;
29 import org.netbeans.jemmy.Waitable;
30 import org.netbeans.jemmy.Waiter;
31 import org.netbeans.jemmy.operators.*;
32 import org.netbeans.test.j2ee.*;
33
34 /**
35  *
36  * @author lm97939
37  */

38 public class AddMethodTest extends AddMethodBase {
39
40     protected String JavaDoc methodName;
41     protected String JavaDoc returnType;
42     protected String JavaDoc parameters[][];
43     protected String JavaDoc exceptions[];
44     protected Boolean JavaDoc remote;
45     protected Boolean JavaDoc local;
46     
47     /** Creates a new instance of AddMethodTest */
48     public AddMethodTest(String JavaDoc name) {
49         super(name);
50     }
51     
52     /** Use for execution inside IDE */
53     public static void main(java.lang.String JavaDoc[] args) {
54         // run only selected test case
55
junit.textui.TestRunner.run(new AddMethodTest("testAddBusinessMethodInSB"));
56     }
57     
58     public void setUp() {
59         System.out.println("######## "+getName()+" #######");
60     }
61
62     public void testAddBusinessMethod1InSB() throws IOException JavaDoc{
63         beanName = "TestingSession";
64         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_EJBActionGroup")
65                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddBusinessMethodAction");
66         dialogTitle = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddBusinessMethodAction");
67         methodName = "testBusinessMethod1";
68         returnType = "String";
69         parameters = null;
70         exceptions = null;
71         remote = Boolean.TRUE;
72         local = Boolean.TRUE;
73         saveFile = true;
74         addMethod();
75     }
76
77     public void testAddBusinessMethod2InSB() throws IOException JavaDoc{
78         beanName = "TestingSession";
79         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_EJBActionGroup")
80                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddBusinessMethodAction");
81         dialogTitle = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddBusinessMethodAction");
82         methodName = "testBusinessMethod2";
83         returnType = "String";
84         parameters = new String JavaDoc[][] {{"String", "a"}, {"int", "b"}};
85         exceptions = new String JavaDoc[] { "Exception" };
86         remote = Boolean.TRUE;
87         local = Boolean.FALSE;
88         saveFile = true;
89         addMethod();
90     }
91     
92     public void testAddBusinessMethod1InEB() throws IOException JavaDoc{
93         beanName = "TestingEntity";
94         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_EJBActionGroup")
95                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddBusinessMethodAction");
96         dialogTitle = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddBusinessMethodAction");
97         methodName = "testBusinessMethod1";
98         returnType = "String";
99         parameters = null;
100         exceptions = null;
101         remote = Boolean.TRUE;
102         local = Boolean.TRUE;
103         saveFile = true;
104         addMethod();
105     }
106
107     public void testAddBusinessMethod2InEB() throws IOException JavaDoc{
108         beanName = "TestingEntity";
109         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_EJBActionGroup")
110                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddBusinessMethodAction");
111         dialogTitle = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddBusinessMethodAction");
112         methodName = "testBusinessMethod2";
113         returnType = "String";
114         parameters = new String JavaDoc[][] {{"String", "a"}, {"boolean", "b"}};
115         exceptions = new String JavaDoc[] { "Exception" };
116         remote = Boolean.FALSE;
117         local = Boolean.TRUE;
118         saveFile = true;
119         addMethod();
120     }
121   
122    public void testAddCreateMethod1InEB() throws IOException JavaDoc {
123         beanName = "TestingEntity";
124         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_EJBActionGroup")
125                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddCreateMethodAction");
126         dialogTitle = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddCreateMethodAction");
127         methodName = "createTest1";
128         // Create Method has no return type!!!
129
returnType = null;
130         parameters = null;
131         exceptions = null;
132         remote = Boolean.FALSE;
133         local = Boolean.TRUE;
134         toSearchInEditor = "public String ejbCreateTest1() throws CreateException";
135         saveFile = true;
136         addMethod();
137     }
138    
139     public void testAddCreateMethod2InEB() throws IOException JavaDoc {
140         beanName = "TestingEntity";
141         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_EJBActionGroup")
142                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddCreateMethodAction");
143         dialogTitle = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddCreateMethodAction");
144         methodName = "createTest2";
145         // Create Method has no return type!!!
146
returnType = null;
147         parameters = new String JavaDoc[][] {{"java.lang.String", "a"}, {"int", "b"}};
148         exceptions = new String JavaDoc[] { "java.io.IOException" };
149         remote = Boolean.TRUE;
150         local = Boolean.TRUE;
151         toSearchInEditor = "public String ejbCreateTest2(String a, int b) throws CreateException, IOException";
152         saveFile = true;
153         addMethod();
154     }
155     
156     public void testAddHomeMethod1InEB() throws IOException JavaDoc{
157         beanName = "TestingEntity";
158         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_EJBActionGroup")
159                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddHomeMethodAction");
160         dialogTitle = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddHomeMethodAction");
161         methodName = "homeTestMethod1";
162         returnType = "String";
163         parameters = null;
164         exceptions = null;
165         remote = Boolean.TRUE;
166         local = Boolean.TRUE;
167         toSearchInEditor = "public String ejbHomeHomeTestMethod1()" ;
168         saveFile = true;
169         addMethod();
170     }
171
172     public void testAddHomeMethod2InEB() throws IOException JavaDoc{
173         beanName = "TestingEntity";
174         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_EJBActionGroup")
175                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddHomeMethodAction");
176         dialogTitle = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddHomeMethodAction");
177         methodName = "homeTestMethod2";
178         returnType = "String";
179         parameters = new String JavaDoc[][] {{"java.lang.String", "a"}, {"int", "b"}};
180         exceptions = new String JavaDoc[] { "java.lang.Exception" };
181         remote = Boolean.FALSE;
182         local = Boolean.TRUE;
183         toSearchInEditor = "public String ejbHomeHomeTestMethod2(String a, int b) throws Exception";
184         saveFile = true;
185         addMethod();
186     }
187     
188     
189     protected void addMethod() throws IOException JavaDoc {
190         EditorOperator editor = new EditorWindowOperator().getEditor(beanName+"Bean.java");
191         editor.select(11);
192
193         // invoke Add Business Method dialog
194
new ActionNoBlock(null,editorPopup).perform(editor);
195         NbDialogOperator dialog = new NbDialogOperator(dialogTitle);
196         
197         new JTextFieldOperator(dialog).setText(methodName);
198         if (returnType != null) {
199             new JTextFieldOperator(dialog,1).setText(returnType);
200         }
201         fillParameters(dialog);
202         fillExceptions(dialog);
203         
204         setRemoteLocalCheckBox(dialog);
205         
206         dialog.ok();
207         if (saveFile) {
208             editor.save();
209         }
210         if (toSearchInEditor == null) {
211             toSearchInEditor = computeSeachString();
212         }
213         waitForEditorText(editor, toSearchInEditor);
214
215         compareFiles();
216     }
217     
218     private String JavaDoc computeSeachString() {
219         StringBuffer JavaDoc text = new StringBuffer JavaDoc();
220         text.append("public ");
221         if (returnType == null)
222             text.append("void");
223         else
224             text.append(returnType);
225         text.append(" "); text.append(methodName);
226         text.append("(");
227         if (parameters != null) {
228             for (int i=0; i<parameters.length; i++) {
229                 if (i>0)
230                     text.append(", ");
231                 text.append(parameters[i][0]); text.append(" "); text.append(parameters[i][1]);
232             }
233         }
234         text.append(")");
235         return text.toString();
236     }
237     
238     protected void fillParameters(NbDialogOperator dialog) {
239         if (parameters != null) {
240             new JTabbedPaneOperator(dialog).selectPage("Parameters");
241             for (int i=0; i<parameters.length; i++) {
242                 new JButtonOperator(dialog,"Add").push();
243                 NbDialogOperator parameterDialog = new NbDialogOperator("Enter Method Parameter");
244                 new JTextFieldOperator(parameterDialog,1).setText(parameters[i][0]);
245                 new JTextFieldOperator(parameterDialog,0).setText(parameters[i][1]);
246                 parameterDialog.ok();
247             }
248         }
249     }
250     
251     protected void fillExceptions(NbDialogOperator dialog) {
252         if (exceptions != null) {
253             new JTabbedPaneOperator(dialog).selectPage("Exceptions");
254             for (int i=0; i<exceptions.length; i++) {
255                 new JButtonOperator(dialog,"Add").push();
256                 NbDialogOperator exceptionDialog = new NbDialogOperator("Enter Exception");
257                 new JTextFieldOperator(exceptionDialog).setText(exceptions[i]);
258                 exceptionDialog.ok();
259             }
260         }
261     }
262     
263     protected void setRemoteLocalCheckBox(NbDialogOperator dialog) {
264         if (remote != null) {
265             new JCheckBoxOperator(dialog, "Remote").setSelected(remote.booleanValue());
266         }
267         if (local != null) {
268             new JCheckBoxOperator(dialog, "Local").setSelected(local.booleanValue());
269         }
270     }
271     
272 }
273
Popular Tags