1 package xdoclet.modules.ojb.tests; 2 3 17 18 import java.util.HashMap ; 19 20 25 public class ModifyInheritedTagCollectionClassAttributeTests extends OjbTestBase 26 { 27 public ModifyInheritedTagCollectionClassAttributeTests(String name) 28 { 29 super(name); 30 } 31 32 public void testCollectionClass1() 34 { 35 addClass( 36 "test.A", 37 "package test;\n"+ 38 "/** @ojb.class */\n" + 39 "public class A {\n"+ 40 " /** @ojb.field primarykey=\"true\" */\n"+ 41 " private int id;\n"+ 42 " /** @ojb.collection element-class-ref=\"test.D\"\n"+ 43 " * foreignkey=\"aid\"\n"+ 44 " * collection-class=\"org.apache.ojb.odmg.collections.DListImpl\"\n"+ 45 " * database-foreignkey=\"false\"\n"+ 46 " */\n"+ 47 " private java.util.List attr;\n"+ 48 "}"); 49 addClass( 50 "test.B", 51 "package test;\n"+ 52 "/** @ojb.class */\n" + 53 "public class B extends A {}"); 54 addClass( 55 "test.C", 56 "package test;\n"+ 57 "/** @ojb.class\n"+ 58 " * @ojb.modify-inherited name=\"attr\"\n"+ 59 " * collection-class=\"\"\n"+ 60 " */\n" + 61 "public class C extends B {}"); 62 addClass( 63 "test.D", 64 "package test;\n"+ 65 "/** @ojb.class */\n"+ 66 "public class D {\n"+ 67 " /** @ojb.field */\n"+ 68 " private int aid;\n"+ 69 "}\n"); 70 71 assertEqualsOjbDescriptorFile( 72 "<class-descriptor\n"+ 73 " class=\"test.A\"\n"+ 74 " table=\"A\"\n"+ 75 ">\n"+ 76 " <extent-class class-ref=\"test.B\"/>\n"+ 77 " <field-descriptor\n"+ 78 " name=\"id\"\n"+ 79 " column=\"id\"\n"+ 80 " jdbc-type=\"INTEGER\"\n"+ 81 " primarykey=\"true\"\n"+ 82 " >\n"+ 83 " </field-descriptor>\n"+ 84 " <collection-descriptor\n"+ 85 " name=\"attr\"\n"+ 86 " collection-class=\"org.apache.ojb.odmg.collections.DListImpl\"\n"+ 87 " element-class-ref=\"test.D\"\n"+ 88 " >\n"+ 89 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 90 " </collection-descriptor>\n"+ 91 "</class-descriptor>\n"+ 92 "<class-descriptor\n"+ 93 " class=\"test.B\"\n"+ 94 " table=\"B\"\n"+ 95 ">\n"+ 96 " <extent-class class-ref=\"test.C\"/>\n"+ 97 " <field-descriptor\n"+ 98 " name=\"id\"\n"+ 99 " column=\"id\"\n"+ 100 " jdbc-type=\"INTEGER\"\n"+ 101 " primarykey=\"true\"\n"+ 102 " >\n"+ 103 " </field-descriptor>\n"+ 104 " <collection-descriptor\n"+ 105 " name=\"attr\"\n"+ 106 " collection-class=\"org.apache.ojb.odmg.collections.DListImpl\"\n"+ 107 " element-class-ref=\"test.D\"\n"+ 108 " >\n"+ 109 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 110 " </collection-descriptor>\n"+ 111 "</class-descriptor>\n"+ 112 "<class-descriptor\n"+ 113 " class=\"test.C\"\n"+ 114 " table=\"C\"\n"+ 115 ">\n"+ 116 " <field-descriptor\n"+ 117 " name=\"id\"\n"+ 118 " column=\"id\"\n"+ 119 " jdbc-type=\"INTEGER\"\n"+ 120 " primarykey=\"true\"\n"+ 121 " >\n"+ 122 " </field-descriptor>\n"+ 123 " <collection-descriptor\n"+ 124 " name=\"attr\"\n"+ 125 " element-class-ref=\"test.D\"\n"+ 126 " >\n"+ 127 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 128 " </collection-descriptor>\n"+ 129 "</class-descriptor>\n"+ 130 "<class-descriptor\n"+ 131 " class=\"test.D\"\n"+ 132 " table=\"D\"\n"+ 133 ">\n"+ 134 " <field-descriptor\n"+ 135 " name=\"aid\"\n"+ 136 " column=\"aid\"\n"+ 137 " jdbc-type=\"INTEGER\"\n"+ 138 " >\n"+ 139 " </field-descriptor>\n"+ 140 "</class-descriptor>", 141 runOjbXDoclet(OJB_DEST_FILE)); 142 assertEqualsTorqueSchemaFile( 143 "<database name=\"ojbtest\">\n"+ 144 " <table name=\"A\">\n"+ 145 " <column name=\"id\"\n"+ 146 " javaName=\"id\"\n"+ 147 " type=\"INTEGER\"\n"+ 148 " primaryKey=\"true\"\n"+ 149 " required=\"true\"\n"+ 150 " />\n"+ 151 " </table>\n"+ 152 " <table name=\"B\">\n"+ 153 " <column name=\"id\"\n"+ 154 " javaName=\"id\"\n"+ 155 " type=\"INTEGER\"\n"+ 156 " primaryKey=\"true\"\n"+ 157 " required=\"true\"\n"+ 158 " />\n"+ 159 " </table>\n"+ 160 " <table name=\"C\">\n"+ 161 " <column name=\"id\"\n"+ 162 " javaName=\"id\"\n"+ 163 " type=\"INTEGER\"\n"+ 164 " primaryKey=\"true\"\n"+ 165 " required=\"true\"\n"+ 166 " />\n"+ 167 " </table>\n"+ 168 " <table name=\"D\">\n"+ 169 " <column name=\"aid\"\n"+ 170 " javaName=\"aid\"\n"+ 171 " type=\"INTEGER\"\n"+ 172 " />\n"+ 173 " </table>\n"+ 174 "</database>", 175 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 176 } 177 178 public void testCollectionClass2() 180 { 181 addClass( 182 "test.A", 183 "package test;\n"+ 184 "/** @ojb.class */\n" + 185 "public class A {\n"+ 186 " /** @ojb.field primarykey=\"true\" */\n"+ 187 " private int id;\n"+ 188 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 189 " * foreignkey=\"aid\"\n"+ 190 " * collection-class=\"org.apache.ojb.broker.util.collections.ManageableHashMap\"\n"+ 191 " */\n"+ 192 " private java.util.Map attr;\n"+ 193 "}"); 194 addClass( 195 "test.B", 196 "package test;\n"+ 197 "/** @ojb.class\n"+ 198 " * @ojb.modify-inherited name=\"attr\"\n"+ 199 " * collection-class=\"\"\n"+ 200 " */\n" + 201 "public class B extends A {}"); 202 addClass( 203 "test.C", 204 "package test;\n"+ 205 "/** @ojb.class */\n"+ 206 "public class C {\n"+ 207 " /** @ojb.field */\n"+ 208 " private int aid;\n"+ 209 "}\n"); 210 211 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 212 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 213 } 214 215 public void testCollectionClass3() 217 { 218 addClass( 219 "test.A", 220 "package test;\n"+ 221 "/** @ojb.class */\n" + 222 "public class A {\n"+ 223 " /** @ojb.field primarykey=\"true\" */\n"+ 224 " private int id;\n"+ 225 " /** @ojb.collection element-class-ref=\"test.D\"\n"+ 226 " * foreignkey=\"aid\"\n"+ 227 " * database-foreignkey=\"false\"\n"+ 228 " */\n"+ 229 " private java.util.List attr;\n"+ 230 "}"); 231 addClass( 232 "test.B", 233 "package test;\n"+ 234 "/** @ojb.class\n"+ 235 " * @ojb.modify-inherited name=\"attr\"\n"+ 236 " * collection-class=\"org.apache.ojb.odmg.collections.DListImpl\"\n"+ 237 " */\n" + 238 "public class B extends A {}"); 239 addClass( 240 "test.C", 241 "package test;\n"+ 242 "/** @ojb.class */\n" + 243 "public class C extends B {}"); 244 addClass( 245 "test.D", 246 "package test;\n"+ 247 "/** @ojb.class */\n"+ 248 "public class D {\n"+ 249 " /** @ojb.field */\n"+ 250 " private int aid;\n"+ 251 "}\n"); 252 253 assertEqualsOjbDescriptorFile( 254 "<class-descriptor\n"+ 255 " class=\"test.A\"\n"+ 256 " table=\"A\"\n"+ 257 ">\n"+ 258 " <extent-class class-ref=\"test.B\"/>\n"+ 259 " <field-descriptor\n"+ 260 " name=\"id\"\n"+ 261 " column=\"id\"\n"+ 262 " jdbc-type=\"INTEGER\"\n"+ 263 " primarykey=\"true\"\n"+ 264 " >\n"+ 265 " </field-descriptor>\n"+ 266 " <collection-descriptor\n"+ 267 " name=\"attr\"\n"+ 268 " element-class-ref=\"test.D\"\n"+ 269 " >\n"+ 270 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 271 " </collection-descriptor>\n"+ 272 "</class-descriptor>\n"+ 273 "<class-descriptor\n"+ 274 " class=\"test.B\"\n"+ 275 " table=\"B\"\n"+ 276 ">\n"+ 277 " <extent-class class-ref=\"test.C\"/>\n"+ 278 " <field-descriptor\n"+ 279 " name=\"id\"\n"+ 280 " column=\"id\"\n"+ 281 " jdbc-type=\"INTEGER\"\n"+ 282 " primarykey=\"true\"\n"+ 283 " >\n"+ 284 " </field-descriptor>\n"+ 285 " <collection-descriptor\n"+ 286 " name=\"attr\"\n"+ 287 " collection-class=\"org.apache.ojb.odmg.collections.DListImpl\"\n"+ 288 " element-class-ref=\"test.D\"\n"+ 289 " >\n"+ 290 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 291 " </collection-descriptor>\n"+ 292 "</class-descriptor>\n"+ 293 "<class-descriptor\n"+ 294 " class=\"test.C\"\n"+ 295 " table=\"C\"\n"+ 296 ">\n"+ 297 " <field-descriptor\n"+ 298 " name=\"id\"\n"+ 299 " column=\"id\"\n"+ 300 " jdbc-type=\"INTEGER\"\n"+ 301 " primarykey=\"true\"\n"+ 302 " >\n"+ 303 " </field-descriptor>\n"+ 304 " <collection-descriptor\n"+ 305 " name=\"attr\"\n"+ 306 " collection-class=\"org.apache.ojb.odmg.collections.DListImpl\"\n"+ 307 " element-class-ref=\"test.D\"\n"+ 308 " >\n"+ 309 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 310 " </collection-descriptor>\n"+ 311 "</class-descriptor>\n"+ 312 "<class-descriptor\n"+ 313 " class=\"test.D\"\n"+ 314 " table=\"D\"\n"+ 315 ">\n"+ 316 " <field-descriptor\n"+ 317 " name=\"aid\"\n"+ 318 " column=\"aid\"\n"+ 319 " jdbc-type=\"INTEGER\"\n"+ 320 " >\n"+ 321 " </field-descriptor>\n"+ 322 "</class-descriptor>", 323 runOjbXDoclet(OJB_DEST_FILE)); 324 assertEqualsTorqueSchemaFile( 325 "<database name=\"ojbtest\">\n"+ 326 " <table name=\"A\">\n"+ 327 " <column name=\"id\"\n"+ 328 " javaName=\"id\"\n"+ 329 " type=\"INTEGER\"\n"+ 330 " primaryKey=\"true\"\n"+ 331 " required=\"true\"\n"+ 332 " />\n"+ 333 " </table>\n"+ 334 " <table name=\"B\">\n"+ 335 " <column name=\"id\"\n"+ 336 " javaName=\"id\"\n"+ 337 " type=\"INTEGER\"\n"+ 338 " primaryKey=\"true\"\n"+ 339 " required=\"true\"\n"+ 340 " />\n"+ 341 " </table>\n"+ 342 " <table name=\"C\">\n"+ 343 " <column name=\"id\"\n"+ 344 " javaName=\"id\"\n"+ 345 " type=\"INTEGER\"\n"+ 346 " primaryKey=\"true\"\n"+ 347 " required=\"true\"\n"+ 348 " />\n"+ 349 " </table>\n"+ 350 " <table name=\"D\">\n"+ 351 " <column name=\"aid\"\n"+ 352 " javaName=\"aid\"\n"+ 353 " type=\"INTEGER\"\n"+ 354 " />\n"+ 355 " </table>\n"+ 356 "</database>", 357 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 358 } 359 360 public void testCollectionClass4() 362 { 363 addClass( 364 "test.A", 365 "package test;\n"+ 366 "/** @ojb.class */\n" + 367 "public class A {\n"+ 368 " /** @ojb.field primarykey=\"true\" */\n"+ 369 " private int id;\n"+ 370 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 371 " * foreignkey=\"aid\"\n"+ 372 " * database-foreignkey=\"false\"\n"+ 373 " */\n"+ 374 " private java.util.List attr;\n"+ 375 "}"); 376 addClass( 377 "test.B", 378 "package test;\n"+ 379 "/** @ojb.class\n"+ 380 " * @ojb.modify-inherited name=\"attr\"\n"+ 381 " * collection-class=\""+TestCollectionClass.class.getName()+"\"\n"+ 382 " */\n" + 383 "public class B extends A {}"); 384 addClass( 385 "test.C", 386 "package test;\n"+ 387 "/** @ojb.class */\n"+ 388 "public class C {\n"+ 389 " /** @ojb.field */\n"+ 390 " private int aid;\n"+ 391 "}\n"); 392 393 assertEqualsOjbDescriptorFile( 394 "<class-descriptor\n"+ 395 " class=\"test.A\"\n"+ 396 " table=\"A\"\n"+ 397 ">\n"+ 398 " <extent-class class-ref=\"test.B\"/>\n"+ 399 " <field-descriptor\n"+ 400 " name=\"id\"\n"+ 401 " column=\"id\"\n"+ 402 " jdbc-type=\"INTEGER\"\n"+ 403 " primarykey=\"true\"\n"+ 404 " >\n"+ 405 " </field-descriptor>\n"+ 406 " <collection-descriptor\n"+ 407 " name=\"attr\"\n"+ 408 " element-class-ref=\"test.C\"\n"+ 409 " >\n"+ 410 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 411 " </collection-descriptor>\n"+ 412 "</class-descriptor>\n"+ 413 "<class-descriptor\n"+ 414 " class=\"test.B\"\n"+ 415 " table=\"B\"\n"+ 416 ">\n"+ 417 " <field-descriptor\n"+ 418 " name=\"id\"\n"+ 419 " column=\"id\"\n"+ 420 " jdbc-type=\"INTEGER\"\n"+ 421 " primarykey=\"true\"\n"+ 422 " >\n"+ 423 " </field-descriptor>\n"+ 424 " <collection-descriptor\n"+ 425 " name=\"attr\"\n"+ 426 " collection-class=\""+TestCollectionClass.class.getName()+"\"\n"+ 427 " element-class-ref=\"test.C\"\n"+ 428 " >\n"+ 429 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 430 " </collection-descriptor>\n"+ 431 "</class-descriptor>\n"+ 432 "<class-descriptor\n"+ 433 " class=\"test.C\"\n"+ 434 " table=\"C\"\n"+ 435 ">\n"+ 436 " <field-descriptor\n"+ 437 " name=\"aid\"\n"+ 438 " column=\"aid\"\n"+ 439 " jdbc-type=\"INTEGER\"\n"+ 440 " >\n"+ 441 " </field-descriptor>\n"+ 442 "</class-descriptor>", 443 runOjbXDoclet(OJB_DEST_FILE)); 444 assertEqualsTorqueSchemaFile( 445 "<database name=\"ojbtest\">\n"+ 446 " <table name=\"A\">\n"+ 447 " <column name=\"id\"\n"+ 448 " javaName=\"id\"\n"+ 449 " type=\"INTEGER\"\n"+ 450 " primaryKey=\"true\"\n"+ 451 " required=\"true\"\n"+ 452 " />\n"+ 453 " </table>\n"+ 454 " <table name=\"B\">\n"+ 455 " <column name=\"id\"\n"+ 456 " javaName=\"id\"\n"+ 457 " type=\"INTEGER\"\n"+ 458 " primaryKey=\"true\"\n"+ 459 " required=\"true\"\n"+ 460 " />\n"+ 461 " </table>\n"+ 462 " <table name=\"C\">\n"+ 463 " <column name=\"aid\"\n"+ 464 " javaName=\"aid\"\n"+ 465 " type=\"INTEGER\"\n"+ 466 " />\n"+ 467 " </table>\n"+ 468 "</database>", 469 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 470 } 471 472 public void testCollectionClass5() 474 { 475 addClass( 476 "test.A", 477 "package test;\n"+ 478 "/** @ojb.class */\n" + 479 "public class A {\n"+ 480 " /** @ojb.field primarykey=\"true\" */\n"+ 481 " private int id;\n"+ 482 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 483 " * foreignkey=\"aid\"\n"+ 484 " */\n"+ 485 " private java.util.List attr;\n"+ 486 "}"); 487 addClass( 488 "test.B", 489 "package test;\n"+ 490 "/** @ojb.class\n"+ 491 " * @ojb.modify-inherited name=\"attr\"\n"+ 492 " * collection-class=\"java.lang.String\"\n"+ 493 " */\n" + 494 "public class B extends A {}"); 495 addClass( 496 "test.C", 497 "package test;\n"+ 498 "/** @ojb.class */\n"+ 499 "public class C {\n"+ 500 " /** @ojb.field */\n"+ 501 " private int aid;\n"+ 502 "}\n"); 503 504 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 505 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 506 } 507 508 public void testCollectionClass6() 510 { 511 addClass( 512 "test.List", 513 "package test;\n"+ 514 "public class List {}"); 515 addClass( 516 "test.A", 517 "package test;\n"+ 518 "/** @ojb.class */\n" + 519 "public class A {\n"+ 520 " /** @ojb.field primarykey=\"true\" */\n"+ 521 " private int id;\n"+ 522 " /** @ojb.collection foreignkey=\"aid\" */\n"+ 523 " private C[] attr;\n"+ 524 "}"); 525 addClass( 526 "test.B", 527 "package test;\n"+ 528 "/** @ojb.class\n"+ 529 " * @ojb.modify-inherited name=\"attr\"\n"+ 530 " * collection-class=\"test.List\"\n"+ 531 " */\n" + 532 "public class B extends A {}"); 533 addClass( 534 "test.C", 535 "package test;\n"+ 536 "/** @ojb.class */\n"+ 537 "public class C {\n"+ 538 " /** @ojb.field */\n"+ 539 " private int aid;\n"+ 540 "}\n"); 541 542 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 543 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 544 } 545 546 public void testCollectionClass7() 548 { 549 addClass( 550 "test.A", 551 "package test;\n"+ 552 "/** @ojb.class */\n" + 553 "public class A {\n"+ 554 " /** @ojb.field primarykey=\"true\" */\n"+ 555 " private int id;\n"+ 556 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 557 " * foreignkey=\"aid\"\n"+ 558 " * collection-class=\"org.apache.ojb.broker.util.collections.ManageableArrayList\"\n"+ 559 " * database-foreignkey=\"false\"\n"+ 560 " */\n"+ 561 " private java.util.List attr;\n"+ 562 "}"); 563 addClass( 564 "test.B", 565 "package test;\n"+ 566 "/** @ojb.class\n"+ 567 " * @ojb.modify-inherited name=\"attr\"\n"+ 568 " * collection-class=\""+TestCollectionClass.class.getName()+"\"\n"+ 569 " */\n" + 570 "public class B extends A {}"); 571 addClass( 572 "test.C", 573 "package test;\n"+ 574 "/** @ojb.class */\n"+ 575 "public class C {\n"+ 576 " /** @ojb.field */\n"+ 577 " private int aid;\n"+ 578 "}\n"); 579 580 assertEqualsOjbDescriptorFile( 581 "<class-descriptor\n"+ 582 " class=\"test.A\"\n"+ 583 " table=\"A\"\n"+ 584 ">\n"+ 585 " <extent-class class-ref=\"test.B\"/>\n"+ 586 " <field-descriptor\n"+ 587 " name=\"id\"\n"+ 588 " column=\"id\"\n"+ 589 " jdbc-type=\"INTEGER\"\n"+ 590 " primarykey=\"true\"\n"+ 591 " >\n"+ 592 " </field-descriptor>\n"+ 593 " <collection-descriptor\n"+ 594 " name=\"attr\"\n"+ 595 " collection-class=\"org.apache.ojb.broker.util.collections.ManageableArrayList\"\n"+ 596 " element-class-ref=\"test.C\"\n"+ 597 " >\n"+ 598 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 599 " </collection-descriptor>\n"+ 600 "</class-descriptor>\n"+ 601 "<class-descriptor\n"+ 602 " class=\"test.B\"\n"+ 603 " table=\"B\"\n"+ 604 ">\n"+ 605 " <field-descriptor\n"+ 606 " name=\"id\"\n"+ 607 " column=\"id\"\n"+ 608 " jdbc-type=\"INTEGER\"\n"+ 609 " primarykey=\"true\"\n"+ 610 " >\n"+ 611 " </field-descriptor>\n"+ 612 " <collection-descriptor\n"+ 613 " name=\"attr\"\n"+ 614 " collection-class=\""+TestCollectionClass.class.getName()+"\"\n"+ 615 " element-class-ref=\"test.C\"\n"+ 616 " >\n"+ 617 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 618 " </collection-descriptor>\n"+ 619 "</class-descriptor>\n"+ 620 "<class-descriptor\n"+ 621 " class=\"test.C\"\n"+ 622 " table=\"C\"\n"+ 623 ">\n"+ 624 " <field-descriptor\n"+ 625 " name=\"aid\"\n"+ 626 " column=\"aid\"\n"+ 627 " jdbc-type=\"INTEGER\"\n"+ 628 " >\n"+ 629 " </field-descriptor>\n"+ 630 "</class-descriptor>", 631 runOjbXDoclet(OJB_DEST_FILE)); 632 assertEqualsTorqueSchemaFile( 633 "<database name=\"ojbtest\">\n"+ 634 " <table name=\"A\">\n"+ 635 " <column name=\"id\"\n"+ 636 " javaName=\"id\"\n"+ 637 " type=\"INTEGER\"\n"+ 638 " primaryKey=\"true\"\n"+ 639 " required=\"true\"\n"+ 640 " />\n"+ 641 " </table>\n"+ 642 " <table name=\"B\">\n"+ 643 " <column name=\"id\"\n"+ 644 " javaName=\"id\"\n"+ 645 " type=\"INTEGER\"\n"+ 646 " primaryKey=\"true\"\n"+ 647 " required=\"true\"\n"+ 648 " />\n"+ 649 " </table>\n"+ 650 " <table name=\"C\">\n"+ 651 " <column name=\"aid\"\n"+ 652 " javaName=\"aid\"\n"+ 653 " type=\"INTEGER\"\n"+ 654 " />\n"+ 655 " </table>\n"+ 656 "</database>", 657 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 658 } 659 660 public void testCollectionClass8() 662 { 663 addClass( 664 "test.A", 665 "package test;\n"+ 666 "/** @ojb.class */\n" + 667 "public class A {\n"+ 668 " /** @ojb.field primarykey=\"true\" */\n"+ 669 " private int id;\n"+ 670 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 671 " * foreignkey=\"aid\"\n"+ 672 " * collection-class=\"org.apache.ojb.broker.util.collections.ManageableHashMap\"\n"+ 673 " */\n"+ 674 " private java.util.Map attr;\n"+ 675 "}"); 676 addClass( 677 "test.B", 678 "package test;\n"+ 679 "/** @ojb.class\n"+ 680 " * @ojb.modify-inherited name=\"attr\"\n"+ 681 " * collection-class=\"org.apache.ojb.broker.util.collections.ManageableArrayList\"\n"+ 682 " */\n" + 683 "public class B extends A {}"); 684 addClass( 685 "test.C", 686 "package test;\n"+ 687 "/** @ojb.class */\n"+ 688 "public class C {\n"+ 689 " /** @ojb.field */\n"+ 690 " private int aid;\n"+ 691 "}\n"); 692 693 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 694 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 695 } 696 697 public void testCollectionClass9() 699 { 700 addClass( 701 "test.A", 702 "package test;\n"+ 703 "/** @ojb.class */\n" + 704 "public class A {\n"+ 705 " /** @ojb.field primarykey=\"true\" */\n"+ 706 " private int id;\n"+ 707 " /** @ojb.collection element-class-ref=\"test.D\"\n"+ 708 " * foreignkey=\"aid\"\n"+ 709 " * database-foreignkey=\"false\"\n"+ 710 " */\n"+ 711 " private java.util.List attr;\n"+ 712 "}"); 713 addClass( 714 "test.B", 715 "package test;\n"+ 716 "/** @ojb.class\n"+ 717 " * @ojb.modify-inherited name=\"attr\"\n"+ 718 " * collection-class=\"java.lang.String\"\n"+ 719 " */\n" + 720 "public class B extends A {}"); 721 addClass( 722 "test.C", 723 "package test;\n"+ 724 "/** @ojb.class */\n" + 725 "public class C extends B {}"); 726 addClass( 727 "test.D", 728 "package test;\n"+ 729 "/** @ojb.class */\n"+ 730 "public class D {\n"+ 731 " /** @ojb.field */\n"+ 732 " private int aid;\n"+ 733 "}\n"); 734 735 HashMap taskProps = new HashMap (); 736 HashMap torqueSubTaskProps = new HashMap (); 737 738 taskProps.put(PROPERTY_CHECKS, "basic"); 739 torqueSubTaskProps.put(PROPERTY_DATABASENAME, "ojbtest"); 740 741 assertEqualsOjbDescriptorFile( 742 "<class-descriptor\n"+ 743 " class=\"test.A\"\n"+ 744 " table=\"A\"\n"+ 745 ">\n"+ 746 " <extent-class class-ref=\"test.B\"/>\n"+ 747 " <field-descriptor\n"+ 748 " name=\"id\"\n"+ 749 " column=\"id\"\n"+ 750 " jdbc-type=\"INTEGER\"\n"+ 751 " primarykey=\"true\"\n"+ 752 " >\n"+ 753 " </field-descriptor>\n"+ 754 " <collection-descriptor\n"+ 755 " name=\"attr\"\n"+ 756 " element-class-ref=\"test.D\"\n"+ 757 " >\n"+ 758 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 759 " </collection-descriptor>\n"+ 760 "</class-descriptor>\n"+ 761 "<class-descriptor\n"+ 762 " class=\"test.B\"\n"+ 763 " table=\"B\"\n"+ 764 ">\n"+ 765 " <extent-class class-ref=\"test.C\"/>\n"+ 766 " <field-descriptor\n"+ 767 " name=\"id\"\n"+ 768 " column=\"id\"\n"+ 769 " jdbc-type=\"INTEGER\"\n"+ 770 " primarykey=\"true\"\n"+ 771 " >\n"+ 772 " </field-descriptor>\n"+ 773 " <collection-descriptor\n"+ 774 " name=\"attr\"\n"+ 775 " collection-class=\"java.lang.String\"\n"+ 776 " element-class-ref=\"test.D\"\n"+ 777 " >\n"+ 778 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 779 " </collection-descriptor>\n"+ 780 "</class-descriptor>\n"+ 781 "<class-descriptor\n"+ 782 " class=\"test.C\"\n"+ 783 " table=\"C\"\n"+ 784 ">\n"+ 785 " <field-descriptor\n"+ 786 " name=\"id\"\n"+ 787 " column=\"id\"\n"+ 788 " jdbc-type=\"INTEGER\"\n"+ 789 " primarykey=\"true\"\n"+ 790 " >\n"+ 791 " </field-descriptor>\n"+ 792 " <collection-descriptor\n"+ 793 " name=\"attr\"\n"+ 794 " collection-class=\"java.lang.String\"\n"+ 795 " element-class-ref=\"test.D\"\n"+ 796 " >\n"+ 797 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 798 " </collection-descriptor>\n"+ 799 "</class-descriptor>\n"+ 800 "<class-descriptor\n"+ 801 " class=\"test.D\"\n"+ 802 " table=\"D\"\n"+ 803 ">\n"+ 804 " <field-descriptor\n"+ 805 " name=\"aid\"\n"+ 806 " column=\"aid\"\n"+ 807 " jdbc-type=\"INTEGER\"\n"+ 808 " >\n"+ 809 " </field-descriptor>\n"+ 810 "</class-descriptor>", 811 runOjbXDoclet(OJB_DEST_FILE, taskProps, null)); 812 assertEqualsTorqueSchemaFile( 813 "<database name=\"ojbtest\">\n"+ 814 " <table name=\"A\">\n"+ 815 " <column name=\"id\"\n"+ 816 " javaName=\"id\"\n"+ 817 " type=\"INTEGER\"\n"+ 818 " primaryKey=\"true\"\n"+ 819 " required=\"true\"\n"+ 820 " />\n"+ 821 " </table>\n"+ 822 " <table name=\"B\">\n"+ 823 " <column name=\"id\"\n"+ 824 " javaName=\"id\"\n"+ 825 " type=\"INTEGER\"\n"+ 826 " primaryKey=\"true\"\n"+ 827 " required=\"true\"\n"+ 828 " />\n"+ 829 " </table>\n"+ 830 " <table name=\"C\">\n"+ 831 " <column name=\"id\"\n"+ 832 " javaName=\"id\"\n"+ 833 " type=\"INTEGER\"\n"+ 834 " primaryKey=\"true\"\n"+ 835 " required=\"true\"\n"+ 836 " />\n"+ 837 " </table>\n"+ 838 " <table name=\"D\">\n"+ 839 " <column name=\"aid\"\n"+ 840 " javaName=\"aid\"\n"+ 841 " type=\"INTEGER\"\n"+ 842 " />\n"+ 843 " </table>\n"+ 844 "</database>", 845 runTorqueXDoclet(TORQUE_DEST_FILE, taskProps, torqueSubTaskProps)); 846 } 847 } 848 | Popular Tags |