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.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 38 public class AddMethodTest extends AddMethodBase { 39 40 protected String methodName; 41 protected String returnType; 42 protected String parameters[][]; 43 protected String exceptions[]; 44 protected Boolean remote; 45 protected Boolean local; 46 47 48 public AddMethodTest(String name) { 49 super(name); 50 } 51 52 53 public static void main(java.lang.String [] args) { 54 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 { 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 { 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 [][] {{"String", "a"}, {"int", "b"}}; 85 exceptions = new String [] { "Exception" }; 86 remote = Boolean.TRUE; 87 local = Boolean.FALSE; 88 saveFile = true; 89 addMethod(); 90 } 91 92 public void testAddBusinessMethod1InEB() throws IOException { 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 { 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 [][] {{"String", "a"}, {"boolean", "b"}}; 115 exceptions = new String [] { "Exception" }; 116 remote = Boolean.FALSE; 117 local = Boolean.TRUE; 118 saveFile = true; 119 addMethod(); 120 } 121 122 public void testAddCreateMethod1InEB() throws IOException { 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 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 { 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 returnType = null; 147 parameters = new String [][] {{"java.lang.String", "a"}, {"int", "b"}}; 148 exceptions = new String [] { "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 { 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 { 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 [][] {{"java.lang.String", "a"}, {"int", "b"}}; 180 exceptions = new String [] { "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 { 190 EditorOperator editor = new EditorWindowOperator().getEditor(beanName+"Bean.java"); 191 editor.select(11); 192 193 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 computeSeachString() { 219 StringBuffer text = new StringBuffer (); 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 |