1 19 20 package org.netbeans.test.j2ee.addmethod; 21 22 import java.io.File ; 23 import java.io.IOException ; 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 35 public class CallEJBTest extends AddMethodBase { 36 37 private String calledBean; 38 private boolean referencedLocal = true; 39 private boolean convertExceptions = true; 40 private String referenceName; 41 42 43 public CallEJBTest(String name) { 44 super(name); 45 } 46 47 48 public static void main(java.lang.String [] args) { 49 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 { 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 { 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 { 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 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 (EJBValidation.WEB_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "test"), new String [] {"TestingServlet.java"}, getName()+"_"); 122 String ddNames[] = { "web.xml", 123 "sun-web.xml" 124 }; 125 utils.assertFiles(new File (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 { 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 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 (WSValidation.WEB_SAMPLE_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "sample"), new String [] {"SampleWebServiceImpl.java"}, getName()+"_"); 172 String ddNames[] = { "web.xml", 173 "sun-web.xml", 174 "webservices.xml" 175 }; 176 utils.assertFiles(new File (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 { 182 EditorOperator editor = new EditorWindowOperator().getEditor(beanName+"Bean.java"); 183 editor.select(11); 184 185 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 |