KickJava   Java API By Example, From Geeks To Geeks.

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


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.test.j2ee.*;
29 import org.netbeans.test.j2ee.lib.Utils;
30
31 /**
32  *
33  * @author lm97939
34  */

35 public class CallEJBTest extends AddMethodBase {
36
37     private String JavaDoc calledBean;
38     private boolean referencedLocal = true;
39     private boolean convertExceptions = true;
40     private String JavaDoc referenceName;
41     
42     /** Creates a new instance of AddMethodTest */
43     public CallEJBTest(String JavaDoc name) {
44         super(name);
45     }
46     
47     /** Use for execution inside IDE */
48     public static void main(java.lang.String JavaDoc[] args) {
49         // run only selected test case
50
junit.textui.TestRunner.run(new CallEJBTest("testCallEJB2InSB"));
51     }
52     
53     public void setUp() {
54         System.out.println("######## "+getName()+" #######");
55     }
56     
57     public void testCallEJB1InSB() throws IOException JavaDoc{
58         beanName = "TestingSession";
59         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.Bundle", "LBL_EnterpriseActionGroup")
60                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.Bundle", "LBL_CallEjbAction");
61         calledBean = EJBValidation.EJB_PROJECT_NAME + "|TestingEntity";
62         toSearchInEditor = "TestingEntityLocalHome lookupTestingEntityBean()";
63         isDDModified = true;
64         saveFile = true;
65         addMethod();
66     }
67
68     public void testCallEJB2InSB() throws IOException JavaDoc{
69         beanName = "TestingSession";
70         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.Bundle", "LBL_EnterpriseActionGroup")
71                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.Bundle", "LBL_CallEjbAction");
72         calledBean = EJBValidation.EJB_PROJECT_NAME + "|TestingEntity";
73         toSearchInEditor = "TestingEntityRemoteHome lookupMyTestingEntityBean()";
74         referencedLocal = false;
75         convertExceptions = true;
76         referenceName = "ejb/MyTestingEntityBean";
77         isDDModified = true;
78         saveFile = true;
79         addMethod();
80     }
81     
82     public void testCallEJBInServlet() throws IOException JavaDoc{
83         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.Bundle", "LBL_EnterpriseActionGroup")
84                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.Bundle", "LBL_CallEjbAction");
85         calledBean = EJBValidation.EJB_PROJECT_NAME + "|TestingSession";
86         toSearchInEditor = "TestingSessionRemote lookupTestingSessionBean()";
87         referencedLocal = false;
88         isDDModified = true;
89         saveFile = true;
90         
91         Node openFile = new Node(new ProjectsTabOperator().getProjectRootNode(EJBValidation.WEB_PROJECT_NAME),
92                                  Bundle.getStringTrimmed("org.netbeans.modules.web.project.ui.Bundle", "LBL_Node_Sources")
93                                  +"|test|TestingServlet.java");
94         new OpenAction().performAPI(openFile);
95         EditorOperator editor = new EditorWindowOperator().getEditor("TestingServlet.java");
96         new org.netbeans.jemmy.EventTool().waitNoEvent(3000);
97         editor.select(30);
98
99         // invoke Add Business Method dialog
100
new ActionNoBlock(null,editorPopup).perform(editor);
101         CallEnterpriseBeanDialog dialog = new CallEnterpriseBeanDialog();
102
103         new Node(dialog.tree(),calledBean).select();
104         if (referencedLocal)
105             dialog.local();
106         else
107             dialog.remote();
108         dialog.checkConvertCheckedExceptionsToRuntimeException(convertExceptions);
109         if (referenceName != null)
110             dialog.setReferenceName(referenceName);
111         
112         dialog.ok();
113         
114         if (saveFile)
115             editor.save();
116         
117         waitForEditorText(editor, toSearchInEditor);
118         
119         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
120         Utils utils = new Utils(this);
121         utils.assertFiles(new File JavaDoc(EJBValidation.WEB_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "test"), new String JavaDoc[] {"TestingServlet.java"}, getName()+"_");
122         String JavaDoc ddNames[] = { "web.xml",
123                              "sun-web.xml"
124         };
125         utils.assertFiles(new File JavaDoc(EJBValidation.WEB_PROJECT_PATH + File.separator + "web" + File.separator + "WEB-INF"), ddNames, isDDModified?getName()+"_":"");
126
127         editor.closeDiscard();
128         
129     }
130
131     public void testCallEJBInWS() throws IOException JavaDoc{
132         editorPopup = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.Bundle", "LBL_EnterpriseActionGroup")
133                                +"|"+Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.Bundle", "LBL_CallEjbAction");
134         calledBean = WSValidation.EJB_SAMPLE_PROJECT_NAME + "|SampleSession";
135         toSearchInEditor = "sample.SampleSessionRemote lookupSampleSessionBean()";
136         referencedLocal = false;
137         isDDModified = true;
138         saveFile = true;
139         
140         Node openFile = new Node(new ProjectsTabOperator().getProjectRootNode(WSValidation.WEB_SAMPLE_PROJECT_NAME),
141                                  "Web Services|SampleWebService");
142         new OpenAction().performAPI(openFile);
143         EditorOperator editor = new EditorWindowOperator().getEditor("SampleWebServiceImpl.java");
144         new org.netbeans.jemmy.EventTool().waitNoEvent(3000);
145         editor.select(11);
146
147         // invoke Add Business Method dialog
148
new ActionNoBlock(null,editorPopup).perform(editor);
149         CallEnterpriseBeanDialog dialog = new CallEnterpriseBeanDialog();
150
151         new Node(dialog.tree(),calledBean).select();
152         if (referencedLocal)
153             dialog.local();
154         else
155             dialog.remote();
156         dialog.checkConvertCheckedExceptionsToRuntimeException(convertExceptions);
157         if (referenceName != null)
158             dialog.setReferenceName(referenceName);
159         
160         dialog.ok();
161         
162         new Utils(this).checkAndModify("SampleWebServiceImpl.java", 19, "// TODO implement operation", 20, "return null;", 20, true, "return lookupSampleSessionBean().sampleBusinessMethod();\n");
163         
164         if (saveFile)
165             editor.save();
166         
167         waitForEditorText(editor, toSearchInEditor);
168         
169         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
170         Utils utils = new Utils(this);
171         utils.assertFiles(new File JavaDoc(WSValidation.WEB_SAMPLE_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "sample"), new String JavaDoc[] {"SampleWebServiceImpl.java"}, getName()+"_");
172         String JavaDoc ddNames[] = { "web.xml",
173                              "sun-web.xml",
174                              "webservices.xml"
175         };
176         utils.assertFiles(new File JavaDoc(WSValidation.WEB_SAMPLE_PROJECT_PATH + File.separator + "web" + File.separator + "WEB-INF"), ddNames, isDDModified?getName()+"_":"");
177
178         editor.closeDiscard();
179     }
180         
181     protected void addMethod() throws IOException JavaDoc {
182         EditorOperator editor = new EditorWindowOperator().getEditor(beanName+"Bean.java");
183         editor.select(11);
184
185         // invoke Add Business Method dialog
186
new ActionNoBlock(null,editorPopup).perform(editor);
187         CallEnterpriseBeanDialog dialog = new CallEnterpriseBeanDialog();
188
189         new Node(dialog.tree(),calledBean).select();
190         if (referencedLocal)
191             dialog.local();
192         else
193             dialog.remote();
194         dialog.checkConvertCheckedExceptionsToRuntimeException(convertExceptions);
195         if (referenceName != null) {
196             dialog.clearReferenceName();
197             dialog.typeReferenceName(referenceName);
198         }
199         
200         dialog.ok();
201         
202         if (saveFile)
203             editor.save();
204         
205         waitForEditorText(editor, toSearchInEditor);
206         
207         compareFiles();
208     }
209     
210 }
211
Popular Tags