1 19 20 package org.netbeans.test.j2ee.multiview; 21 22 import java.io.File ; 23 import java.lang.reflect.Modifier ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.LinkedList ; 27 import java.util.List ; 28 import junit.framework.AssertionFailedError; 29 import junit.textui.TestRunner; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.jellytools.JellyTestCase; 32 import junit.framework.Test; 33 import org.netbeans.jmi.javamodel.JavaClass; 34 import org.netbeans.jmi.javamodel.Method; 35 import org.netbeans.junit.NbTestSuite; 36 import org.netbeans.modules.j2ee.common.JMIUtils; 37 import org.netbeans.modules.j2ee.dd.api.ejb.CmpField; 38 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 39 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; 40 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 41 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; 42 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 43 import org.netbeans.modules.j2ee.dd.api.ejb.Query; 44 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarMultiViewDataObject; 45 import org.netbeans.modules.j2ee.ddloaders.multiview.EntityHelper; 46 import org.netbeans.modules.j2ee.ddloaders.multiview.EntityNode; 47 import org.netbeans.modules.j2ee.ddloaders.multiview.FinderMethodsNode; 48 import org.netbeans.modules.j2ee.ddloaders.multiview.FinderMethodsTableModel; 49 import org.netbeans.modules.j2ee.ddloaders.multiview.QueryMethodHelper; 50 import org.netbeans.modules.j2ee.ddloaders.multiview.SelectMethodsNode; 51 import org.netbeans.modules.j2ee.ddloaders.multiview.SelectMethodsTableModel; 52 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.EntityMethodController; 53 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 54 import org.netbeans.test.j2ee.lib.J2eeProjectSupport; 55 import org.openide.cookies.EditCookie; 56 import org.openide.cookies.SaveCookie; 57 import org.openide.filesystems.FileObject; 58 import org.openide.loaders.DataObject; 59 import org.openide.nodes.Node; 60 61 65 public class EBCMPFinderAndSelectMethodsTest extends JellyTestCase{ 66 67 public static final String EJB_PROJECT_NAME = "TestCMP"; 68 public static final String EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EJB_PROJECT_NAME; 69 70 private static Project project; 71 private static FileObject ddFo; 72 private static EjbJar ejbJar; 73 private static EjbJarMultiViewDataObject ddObj; 74 private static Entity bean; 75 private static CmpField[] cmpFields; 76 private static Query[] query; 77 78 79 public EBCMPFinderAndSelectMethodsTest(String testName) { 80 super(testName); 81 } 82 83 protected void setUp() throws Exception { 84 super.setUp(); 85 } 86 87 protected void tearDown() throws Exception { 88 } 89 90 public static Test suite() { 91 NbTestSuite suite = new NbTestSuite(); 92 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testOpenProject")); 93 94 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testAddCMPSelectMethod")); 96 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testExistingCMPSelectMethods")); 97 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testModifyReturnTypeCMPSelectMethod")); 99 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testModifyQueryCMPSelectMethod")); 100 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testModifyDescriptionCMPSelectMethod")); 101 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testRemoveCMPSelectMethod")); 102 103 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testExistingCMPFinderMethod")); 105 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testAddCMPFinderMethod")); 106 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testEditReturnCMPFinderMethod")); 107 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testEditQueryCMPFinderMethod")); 108 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testEditDescriptionCMPFinderMethod")); 109 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testRemoveCMPFinderMethod")); 110 111 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testAddRemoteFinderMethod")); 112 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testTransferRemote2LocalFinderMethod")); 113 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testTransferLocal2RemoteFinderMethod")); 114 suite.addTest(new EBCMPFinderAndSelectMethodsTest("testBothInterfacesFinderMetohd")); 115 return suite; 116 } 117 118 public void testOpenProject() throws Exception { 119 File projectDir = new File (EJB_PROJECT_PATH); 120 project = (Project)J2eeProjectSupport.openProject(projectDir); 121 assertNotNull("Project is null.", project); 122 Thread.sleep(1000); 123 124 EjbJarProject ejbJarProject = (EjbJarProject)project; 125 ddFo = ejbJarProject.getAPIEjbJar().getDeploymentDescriptor(); assertNotNull("ejb-jar.xml FileObject is null.", ddFo); 127 128 ejbJar = DDProvider.getDefault().getDDRoot(ddFo); 129 130 ddObj = (EjbJarMultiViewDataObject)DataObject.find(ddFo); assertNotNull("MultiViewDO is null.",ddObj); 132 133 EditCookie edit = (EditCookie)ddObj.getCookie(EditCookie.class); 134 edit.edit(); 135 Thread.sleep(1000); 136 137 EnterpriseBeans beans = DDProvider.getDefault().getDDRoot(ddFo).getEnterpriseBeans(); 139 bean = (Entity)beans.findBeanByName(EnterpriseBeans.ENTITY, 140 Ejb.EJB_NAME ,"CustomerBean"); 141 142 cmpFields = bean.getCmpField(); 143 144 ddObj.showElement(bean); Utils.waitForAWTDispatchThread(); 146 } 147 148 public static void main(java.lang.String [] args) { 149 TestRunner.run(suite()); 151 } 152 153 public void testExistingCMPFinderMethod() throws Exception { 154 String [] methodsNames = {"findById","findByLastName","findByFirstName"}; 156 String [] methodsQuerys = {"SELECT OBJECT(c) FROM Customer AS c WHERE c.id = ?1", 157 "SELECT OBJECT(c) FROM Customer AS c WHERE c.lastName = ?1", 158 "SELECT OBJECT(c) FROM Customer AS c WHERE c.firstName = ?1"}; 159 String description = "auto generated method"; 160 FinderMethodsNode fmn = getFinderMethodNode(ddObj); 161 fmn.getSectionNodePanel().open(); EntityHelper entHelper = ddObj.getEntityHelper(bean); 163 FinderMethodsTableModel tableModel = entHelper.queries.getFinderMethodsTableModel(); 164 assertTrue("FinderMethod table has unexpected number of rows",tableModel.getRowCount()==3); 165 for(int i=0;i<tableModel.getRowCount();i++) { assertEquals("Methods names do not match in "+i+". row",methodsNames[i],(String )tableModel.getValueAt(i,0)); 167 assertTrue("Return Collection is not set corectlly in "+i+". row",((Boolean )tableModel.getValueAt(i,1)).booleanValue()); 168 assertEquals("Result interfaces do not match in "+i+". row","local",(String )tableModel.getValueAt(i,2)); 169 assertEquals("Querys do not match in "+i+". row",methodsQuerys[i],(String )tableModel.getValueAt(i,3)); 170 assertEquals("Descriptions do not match in "+i+". row",description,(String )tableModel.getValueAt(i,4)); 171 } 172 } 173 174 public void testAddCMPFinderMethod() throws Exception { 175 String methodName = "findByField" ; 176 Method method = JMIUtils.createMethod(JMIUtils.findClass("cmp.CustomerBean")); 177 method.setName(methodName); 178 method.setType(JMIUtils.resolveType("java.util.Collection")); 179 JMIUtils.addException(method, "javax.ejb.FinderException"); 180 EntityHelper entityHelper = new EntityHelper(ddObj, bean); 181 EntityMethodController emc = entityHelper.getEntityMethodController(); 182 emc.addMethod(method,true,false); 183 emc.addEjbQl(method,"SELECT OBJECT(o) FROM Customer o",ddFo); 184 Thread.currentThread().sleep(500); 185 getRowNumberByName(methodName); 186 Utils utils = new Utils(this); 187 utils.checkInXML(ddObj,"<method-name>"+methodName+"</method-name>"); 188 utils.checkInXML(ddObj,"<ejb-ql>SELECT OBJECT(o) FROM Customer o</ejb-ql>"); 189 utils.checkFiles("testAddCMPFinderMethod", null, new String []{"CustomerLocalHome.java"}); 190 } 191 192 public void testEditReturnCMPFinderMethod() throws Exception { 193 EntityHelper entHelper = ddObj.getEntityHelper(bean); 194 FinderMethodsTableModel tableModel = entHelper.queries.getFinderMethodsTableModel(); 195 Utils utils = new Utils(this); 196 int row = getRowNumberByName("findByField"); 197 tableModel.setValueAt(new Boolean (false),row,1); 198 Thread.currentThread().sleep(500); 199 QueryMethodHelper qmh = getQueryMethodHelperByName("findByField"); 200 assertEquals("Model not updated","cmp.CustomerLocal",qmh.getReturnType()); 201 utils.checkFiles("testEditReturnCMPFinderMethod",null,new String []{"CustomerLocalHome.java"}); 202 } 203 204 public void testEditQueryCMPFinderMethod() throws Exception { 205 EntityHelper entHelper = ddObj.getEntityHelper(bean); 206 QueryMethodHelper helper = getQueryMethodHelperByName("findByField"); 207 Utils utils = new Utils(this); 208 int rowIndex = getRowNumberByName("findByField"); 209 boolean publishToLocal = helper.localMethod != null; 210 boolean publishToRemote = helper.remoteMethod != null; 211 boolean returnsCollection = helper.returnsCollection(); 212 Method method = helper.getPrototypeMethod(); 213 Query query = (Query) entHelper.queries.getFinderMethod(rowIndex).clone(); 214 query.setEjbQl("XXXX"); 215 helper.updateFinderMethod(method, query, !returnsCollection, publishToLocal, publishToRemote); 216 Thread.currentThread().sleep(500); 217 SaveCookie saveCookie = (SaveCookie)ddObj.getCookie(SaveCookie.class); 218 assertNotNull("Save cookie is null, Data object isn't changed!", saveCookie); 219 saveCookie.save(); 220 utils.checkInXML(ddObj,"<ejb-ql>XXXX</ejb-ql>"); 221 assertEquals("Table model not updated","XXXX",entHelper.queries.getFinderMethodsTableModel().getValueAt(rowIndex,3)); 222 assertEquals("Model not updated","XXXX",helper.getEjbQl()); 223 } 224 225 public void testEditDescriptionCMPFinderMethod() throws Exception { 226 EntityHelper entHelper = ddObj.getEntityHelper(bean); 227 FinderMethodsTableModel tableModel = entHelper.queries.getFinderMethodsTableModel(); 228 Utils utils = new Utils(this); 229 int rowIndex = getRowNumberByName("findByField"); 230 tableModel.setValueAt("Modified description",rowIndex,4); 231 Thread.currentThread().sleep(500); 232 QueryMethodHelper helper = getQueryMethodHelperByName("findByField"); 233 SaveCookie saveCookie = (SaveCookie)ddObj.getCookie(SaveCookie.class); 234 assertNotNull("Save cookie is null, Data object isn't changed!", saveCookie); 235 saveCookie.save(); 236 utils.checkInXML(ddObj,"<description>Modified description</description>"); 237 assertEquals("Table model not updated","Modified description",entHelper.queries.getFinderMethodsTableModel().getValueAt(rowIndex,4)); 238 assertEquals("Model not updated","Modified description",helper.getDefaultDescription()); 239 } 240 241 public void testEditNameCMPFinderMethod() throws Exception { 242 } 244 245 public void testRemoveCMPFinderMethod() throws Exception { 246 EntityHelper entHelper = ddObj.getEntityHelper(bean); 247 EntityMethodController emc = entHelper.getEntityMethodController(); 248 int row = getRowNumberByName("findByField"); 249 entHelper.queries.getFinderMethodsTableModel().removeRow(row); 250 delayAndSave(ddObj); 251 Utils utils = new Utils(this); 252 utils.checkFiles("testRemoveCMPFinderMethod",null,new String []{"CustomerLocalHome.java"}); 253 try { 254 utils.checkInXML(ddObj,"<method-name>findByName</method-name>"); 255 } catch (AssertionFailedError aef) { 256 return; 258 } 259 fail("Method not removed from dd"); 260 return; 261 } 262 263 public void testAddCMPSelectMethod() throws Exception { 264 SelectMethodsNode smn = getSelectMethodNode(ddObj); 265 smn.getSectionNodePanel().open(); 266 Method method = JMIUtils.createMethod(JMIUtils.findClass("cmp.CustomerBean")); 267 method.setName("ejbSelectBy"); 268 method.setType(JMIUtils.resolveType("int")); 269 method.setModifiers(Modifier.PUBLIC|Modifier.ABSTRACT); 270 JMIUtils.addException(method, "javax.ejb.FinderException"); 271 EntityHelper entityHelper = new EntityHelper(ddObj, bean); 272 EntityMethodController emc = entityHelper.getEntityMethodController(); 273 emc.addSelectMethod(method,"SELECT COUNT(o) FROM Customer o",ddFo); 274 Utils utils = new Utils(this); 275 utils.checkFiles("testAddCMPSelectMethod",null,new String []{"CustomerBean.java"}); 276 utils.checkInXML(ddObj,"<method-name>ejbSelectBy</method-name>"); 277 278 } 279 280 public void testExistingCMPSelectMethods() throws Exception { 281 EntityHelper entHelper = ddObj.getEntityHelper(bean); 282 SelectMethodsTableModel tableModel = entHelper.queries.getSelectMethodsTableModel(); 283 assertTrue("Wrong number of select methods",tableModel.getRowCount()==1); 284 assertEquals("Unexpected Select method name","ejbSelectBy",tableModel.getValueAt(0,0)); 285 assertEquals("Unexpected Select method return type","int",tableModel.getValueAt(0,1)); 286 assertEquals("Unexpected Select method query","SELECT COUNT(o) FROM Customer o",tableModel.getValueAt(0,2)); 287 assertEquals("Unexpected Select method description",null,tableModel.getValueAt(0,3)); 288 } 289 290 291 public void testModifyNameCMPSelectMethod() throws Exception { 292 EntityHelper entHelper = ddObj.getEntityHelper(bean); 293 SelectMethodsTableModel tableModel = entHelper.queries.getSelectMethodsTableModel(); 294 Query query = (Query) entHelper.queries.getSelecMethod(0).clone(); 295 QueryMethodHelper helper = tableModel.getQueryMethodHelper(0); 296 Method method = helper.getPrototypeMethod(); 297 method.setType(JMIUtils.resolveType(method.getTypeName().getName())); 298 method.setName("ejbSelectByMod"); 299 helper.updateSelectMethod(method,query); 300 } 301 302 public void testModifyReturnTypeCMPSelectMethod() throws Exception { 303 EntityHelper entHelper = ddObj.getEntityHelper(bean); 304 SelectMethodsTableModel tableModel = entHelper.queries.getSelectMethodsTableModel(); 305 Query query = (Query) entHelper.queries.getSelecMethod(0).clone(); 306 QueryMethodHelper helper = tableModel.getQueryMethodHelper(0); 307 Method method = helper.getPrototypeMethod(); 308 method.setType(JMIUtils.resolveType("char")); 309 helper.updateSelectMethod(method,query); 310 Utils utils = new Utils(this); 311 utils.checkFiles("testModifyReturnTypeCMPSelectMethod",null,new String []{"CustomerBean.java"}); 312 } 313 314 public void testModifyQueryCMPSelectMethod() throws Exception { 315 EntityHelper entHelper = ddObj.getEntityHelper(bean); 316 SelectMethodsTableModel tableModel = entHelper.queries.getSelectMethodsTableModel(); 317 Query query = (Query) entHelper.queries.getSelecMethod(0).clone(); 318 QueryMethodHelper helper = tableModel.getQueryMethodHelper(0); 319 Method method = helper.getPrototypeMethod(); 320 query.setEjbQl("XXXX"); 321 helper.updateSelectMethod(method,query); 322 delayAndSave(ddObj); 323 Utils utils = new Utils(this); 324 utils.checkInXML(ddObj,"<ejb-ql>XXXX</ejb-ql>"); 325 } 326 327 public void testModifyDescriptionCMPSelectMethod() throws Exception { 328 EntityHelper entHelper = ddObj.getEntityHelper(bean); 329 SelectMethodsTableModel tableModel = entHelper.queries.getSelectMethodsTableModel(); 330 tableModel.setValueAt("New description",0,3); 331 delayAndSave(ddObj); 332 Utils utils = new Utils(this); 333 utils.checkInXML(ddObj,"<description>New description</description>"); 334 } 335 public void testRemoveCMPSelectMethod() throws Exception { 336 EntityHelper entHelper = ddObj.getEntityHelper(bean); 337 EntityMethodController emc = entHelper.getEntityMethodController(); 338 entHelper.queries.getSelectMethodsTableModel().removeRow(0); 339 delayAndSave(ddObj); 340 Utils utils = new Utils(this); 341 utils.checkFiles("testRemoveCMPSelectMethod",null,new String []{"CustomerBean.java"}); 342 try { 343 utils.checkInXML(ddObj,"<method-name>ejbSelectBy</method-name>"); 344 } catch (AssertionFailedError aef) { 345 return; 347 } 348 fail("Method not removed from dd"); 349 return; 350 } 351 352 public void testAddRemoteFinderMethod() throws Exception { 353 ddObj.getEntityHelper(bean).addInterfaces(false); String methodName = "findByAux" ; 355 String queryString ="SELECT OBJECT(o) FROM Customer AUX"; 356 Method method = JMIUtils.createMethod(JMIUtils.findClass("cmp.CustomerBean")); 357 method.setName(methodName); 358 method.setType(JMIUtils.resolveType("java.util.Collection")); 359 JMIUtils.addException(method, "javax.ejb.FinderException"); 360 EntityHelper entityHelper = new EntityHelper(ddObj, bean); 362 EntityMethodController emc = entityHelper.getEntityMethodController(); 363 emc.addMethod(method,false,false); emc.addEjbQl(method,queryString,ddFo); 365 delayAndSave(ddObj); 366 int row = getRowNumberByName(methodName); 368 FinderMethodsTableModel tableModel = entityHelper.queries.getFinderMethodsTableModel(); 369 assertEquals("Wrong Result Interface description",tableModel.getValueAt(row,2),"remote"); 370 Utils utils = new Utils(this); 371 utils.checkInXML(ddObj,"<method-name>"+methodName+"</method-name>"); 373 utils.checkInXML(ddObj,"<ejb-ql>"+queryString+"</ejb-ql>"); 374 JavaClass remoteHome = entityHelper.getHomeInterfaceClass(); 376 Method findMethod = getMethodByName(remoteHome,methodName); 377 assertNotNull("Method not found",findMethod); 378 assertEquals("Wrong return type","java.util.Collection",findMethod.getType().getName()); 379 assertEquals("Wrong modifiers",(Modifier.ABSTRACT | Modifier.PUBLIC),findMethod.getModifiers()); 380 List expectedEx = new ArrayList (); 381 expectedEx.add("javax.ejb.FinderException"); 382 expectedEx.add("java.rmi.RemoteException"); 383 throwsExceptions(expectedEx,findMethod.getExceptions()); 384 } 385 386 public void testTransferRemote2LocalFinderMethod() throws Exception { 387 String methodName = "findByAux" ; 388 EntityHelper entHelper = ddObj.getEntityHelper(bean); 389 QueryMethodHelper helper = getQueryMethodHelperByName(methodName); 390 Utils utils = new Utils(this); 391 int rowIndex = getRowNumberByName(methodName); 392 FinderMethodsTableModel tableModel = entHelper.queries.getFinderMethodsTableModel(); 393 boolean publishToLocal = true; 394 boolean publishToRemote = false; 395 boolean returnsCollection = helper.returnsCollection(); 396 Method method = helper.getPrototypeMethod(); 397 Query query = (Query) entHelper.queries.getFinderMethod(rowIndex).clone(); 398 JMIUtils.addException(method, "javax.ejb.FinderException"); 399 helper.updateFinderMethod(method, query, !returnsCollection, publishToLocal, publishToRemote); 400 assertEquals("Wrong Result Interface description",tableModel.getValueAt(rowIndex,2),"local"); 402 JavaClass remoteHome = entHelper.getHomeInterfaceClass(); 404 JavaClass localHome = entHelper.getLocalHomeInterfaceClass(); 405 Method finder = getMethodByName(remoteHome,methodName); 406 assertNull("Method not deleted from remote interface",finder); 407 finder = getMethodByName(localHome,methodName); 408 assertNotNull("Method not found in local interface",finder); 409 assertEquals("Wrong return type","java.util.Collection",finder.getType().getName()); 410 List expectedEx = new ArrayList (); 411 expectedEx.add("javax.ejb.FinderException"); 412 throwsExceptions(expectedEx,finder.getExceptions()); 413 } 414 415 public void testTransferLocal2RemoteFinderMethod() throws Exception { 416 String methodName = "findByFirstName" ; 417 EntityHelper entHelper = ddObj.getEntityHelper(bean); 418 QueryMethodHelper helper = getQueryMethodHelperByName(methodName); 419 FinderMethodsTableModel tableModel = entHelper.queries.getFinderMethodsTableModel(); 420 Utils utils = new Utils(this); 421 int rowIndex = getRowNumberByName(methodName); 422 boolean publishToLocal = false; 423 boolean publishToRemote = true; 424 boolean returnsCollection = helper.returnsCollection(); 425 Method method = helper.getPrototypeMethod(); 426 Query query = (Query) entHelper.queries.getFinderMethod(rowIndex).clone(); 427 JMIUtils.addException(method, "javax.ejb.FinderException"); 428 helper.updateFinderMethod(method, query, !returnsCollection, publishToLocal, publishToRemote); 429 assertEquals("Wrong Result Interface description",tableModel.getValueAt(rowIndex,2),"remote"); 431 JavaClass remoteHome = entHelper.getHomeInterfaceClass(); 433 JavaClass localHome = entHelper.getLocalHomeInterfaceClass(); 434 Method finder = getMethodByName(localHome,methodName); 435 assertNull("Method not deleted from local interface",finder); 436 finder = getMethodByName(remoteHome,methodName); 437 assertNotNull("Method not found in remote interface",finder); 438 assertEquals("Wrong return type","java.util.Collection",finder.getType().getName()); 439 List expectedEx = new ArrayList (); 440 expectedEx.add("javax.ejb.FinderException"); 441 expectedEx.add("java.rmi.RemoteException"); 442 throwsExceptions(expectedEx,finder.getExceptions()); 443 } 444 445 public void testBothInterfacesFinderMetohd() throws Exception { 446 String methodName = "findByFirstName" ; 447 EntityHelper entHelper = ddObj.getEntityHelper(bean); 448 QueryMethodHelper helper = getQueryMethodHelperByName(methodName); 449 FinderMethodsTableModel tableModel = entHelper.queries.getFinderMethodsTableModel(); 450 Utils utils = new Utils(this); 451 int rowIndex = getRowNumberByName(methodName); 452 boolean publishToLocal = true; 453 boolean publishToRemote = true; 454 boolean returnsCollection = helper.returnsCollection(); 455 Method method = helper.getPrototypeMethod(); 456 Query query = (Query) entHelper.queries.getFinderMethod(rowIndex).clone(); 457 helper.updateFinderMethod(method, query, !returnsCollection, publishToLocal, publishToRemote); 458 delayAndSave(ddObj); 459 assertEquals("Wrong Result Interface description",tableModel.getValueAt(rowIndex,2),"local+remote"); 461 } 462 463 private QueryMethodHelper getQueryMethodHelperByName(String name) { 464 EntityHelper entHelper = ddObj.getEntityHelper(bean); 465 Query[] queries = entHelper.queries.getQuery(); 466 for (int i = 0; i < queries.length; i++) { 467 if(queries[i].getQueryMethod().getMethodName().equals(name)) return entHelper.queries.getQueryMethodHelper(queries[i]); 468 } 469 assertTrue("Querymethod "+name+" not found",false); 470 return null; 471 } 472 473 private int getRowNumberByName(String name) { 474 EntityHelper entityHelper = new EntityHelper(ddObj, bean); 475 FinderMethodsTableModel tableModel = entityHelper.queries.getFinderMethodsTableModel(); 476 int i; 477 for(i=0;i<tableModel.getRowCount();i++) { 478 if(tableModel.getValueAt(i,0).equals(name)) break; 479 } 480 assertTrue("Method "+name+" is not added to table model",i!=tableModel.getRowCount()); 481 return i; 482 } 483 484 private FinderMethodsNode getFinderMethodNode(EjbJarMultiViewDataObject ddObj) { 485 EntityNode entityNode = Utils.getEntityNode(ddObj); 486 assertNotNull("No Entitynode found",entityNode); 487 Node[] nodes = Utils.getChildrenNodes(entityNode); 488 for (int i = 0; i < nodes.length; i++) { 489 if(nodes[i] instanceof FinderMethodsNode) return (FinderMethodsNode)nodes[i]; 490 } 491 fail("No FinderMethodsNode found"); 492 return null; 493 } 494 495 private SelectMethodsNode getSelectMethodNode(EjbJarMultiViewDataObject ddObj) { 496 EntityNode entityNode = Utils.getEntityNode(ddObj); 497 assertNotNull("No Entitynode found",entityNode); 498 Node[] nodes = Utils.getChildrenNodes(entityNode); 499 for (int i = 0; i < nodes.length; i++) { 500 if(nodes[i] instanceof SelectMethodsNode) return (SelectMethodsNode)nodes[i]; 501 } 502 fail("No SelectMethodsNode found"); 503 return null; 504 } 505 506 private void delayAndSave(EjbJarMultiViewDataObject obj) throws Exception { 507 new StepIterator() { 508 SaveCookie saveCookie; 509 public boolean step() throws Exception { 510 saveCookie = (SaveCookie) ddObj.getCookie(SaveCookie.class); 511 return saveCookie!=null; 512 } 513 }; 514 SaveCookie saveCookie = (SaveCookie) ddObj.getCookie(SaveCookie.class); 515 assertNotNull("Document was not modified",saveCookie); 516 saveCookie.save(); 517 } 518 519 private Method getMethodByName(JavaClass jc,String name) { 520 Method[] methods = JMIUtils.getMethods(jc); 521 for(int i=0;i<methods.length;i++) if(methods[i].getName().equals(name)) return methods[i]; 522 return null; 523 } 524 525 private boolean throwsExceptions(List expected,List currentlyThrown) throws Exception { 526 String temp; 527 List exNames = new LinkedList (); 529 Iterator it = currentlyThrown.iterator(); 530 while(it.hasNext()) { 531 temp = ((JavaClass)it.next()).getName(); 532 assertTrue("Unexpected exception "+temp+" is declared to be thrown",expected.contains(temp)); 533 exNames.add(temp); 534 } 535 it = expected.iterator(); 536 while(it.hasNext()) { 537 temp = (String )it.next(); 538 assertTrue("Expected exception "+temp+" is not declared to be thrown",exNames.contains(temp)); 539 } 540 return true; 541 } 542 543 } 544 | Popular Tags |