1 package xdoclet.modules.ojb.tests; 2 3 17 18 23 public class ReferenceTagClassRefAttributeTests extends OjbTestBase 24 { 25 public ReferenceTagClassRefAttributeTests(String name) 26 { 27 super(name); 28 } 29 30 public void testClassRef1() 32 { 33 addClass( 34 "test.A", 35 "package test;\n"+ 36 "/** @ojb.class */\n"+ 37 "public class A {\n"+ 38 "/** @ojb.field */\n"+ 39 " private int attrKey;\n"+ 40 "/** @ojb.reference foreignkey=\"attrKey\" */\n"+ 41 " private test.B attr;\n"+ 42 "}\n"); 43 addClass( 44 "test.B", 45 "package test;\n"+ 46 "/** @ojb.class */\n"+ 47 "public class B {\n"+ 48 "/** @ojb.field primarykey=\"true\" */\n"+ 49 " private int id;\n"+ 50 "}\n"); 51 52 assertEqualsOjbDescriptorFile( 53 "<class-descriptor\n"+ 54 " class=\"test.A\"\n"+ 55 " table=\"A\"\n"+ 56 ">\n"+ 57 " <field-descriptor\n"+ 58 " name=\"attrKey\"\n"+ 59 " column=\"attrKey\"\n"+ 60 " jdbc-type=\"INTEGER\"\n"+ 61 " >\n"+ 62 " </field-descriptor>\n"+ 63 " <reference-descriptor\n"+ 64 " name=\"attr\"\n"+ 65 " class-ref=\"test.B\"\n"+ 66 " >\n"+ 67 " <foreignkey field-ref=\"attrKey\"/>\n"+ 68 " </reference-descriptor>\n"+ 69 "</class-descriptor>\n"+ 70 "<class-descriptor\n"+ 71 " class=\"test.B\"\n"+ 72 " table=\"B\"\n"+ 73 ">\n"+ 74 " <field-descriptor\n"+ 75 " name=\"id\"\n"+ 76 " column=\"id\"\n"+ 77 " jdbc-type=\"INTEGER\"\n"+ 78 " primarykey=\"true\"\n"+ 79 " >\n"+ 80 " </field-descriptor>\n"+ 81 "</class-descriptor>", 82 runOjbXDoclet(OJB_DEST_FILE)); 83 assertEqualsTorqueSchemaFile( 84 "<database name=\"ojbtest\">\n"+ 85 " <table name=\"A\">\n"+ 86 " <column name=\"attrKey\"\n"+ 87 " javaName=\"attrKey\"\n"+ 88 " type=\"INTEGER\"\n"+ 89 " />\n"+ 90 " <foreign-key foreignTable=\"B\">\n"+ 91 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 92 " </foreign-key>\n"+ 93 " </table>\n"+ 94 " <table name=\"B\">\n"+ 95 " <column name=\"id\"\n"+ 96 " javaName=\"id\"\n"+ 97 " type=\"INTEGER\"\n"+ 98 " primaryKey=\"true\"\n"+ 99 " required=\"true\"\n"+ 100 " />\n"+ 101 " </table>\n"+ 102 "</database>", 103 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 104 } 105 106 public void testClassRef2() 108 { 109 addClass( 110 "test.A", 111 "package test;\n"+ 112 "/** @ojb.class */\n"+ 113 "public class A {\n"+ 114 "/** @ojb.field */\n"+ 115 " private int attrKey;\n"+ 116 "/** @ojb.reference foreignkey=\"attrKey\" */\n"+ 117 " private test.B attr;\n"+ 118 "}\n"); 119 addClass( 120 "test.B", 121 "package test;\n"+ 122 "/** @ojb.class generate-table-info=\"false\" */\n"+ 123 "public class B {\n"+ 124 "/** @ojb.field primarykey=\"true\" */\n"+ 125 " private int id;\n"+ 126 "}\n"); 127 128 assertEqualsOjbDescriptorFile( 129 "<class-descriptor\n"+ 130 " class=\"test.A\"\n"+ 131 " table=\"A\"\n"+ 132 ">\n"+ 133 " <field-descriptor\n"+ 134 " name=\"attrKey\"\n"+ 135 " column=\"attrKey\"\n"+ 136 " jdbc-type=\"INTEGER\"\n"+ 137 " >\n"+ 138 " </field-descriptor>\n"+ 139 " <reference-descriptor\n"+ 140 " name=\"attr\"\n"+ 141 " class-ref=\"test.B\"\n"+ 142 " >\n"+ 143 " <foreignkey field-ref=\"attrKey\"/>\n"+ 144 " </reference-descriptor>\n"+ 145 "</class-descriptor>\n"+ 146 "<class-descriptor\n"+ 147 " class=\"test.B\"\n"+ 148 ">\n"+ 149 " <field-descriptor\n"+ 150 " name=\"id\"\n"+ 151 " column=\"id\"\n"+ 152 " jdbc-type=\"INTEGER\"\n"+ 153 " primarykey=\"true\"\n"+ 154 " >\n"+ 155 " </field-descriptor>\n"+ 156 "</class-descriptor>", 157 runOjbXDoclet(OJB_DEST_FILE)); 158 assertEqualsTorqueSchemaFile( 159 "<database name=\"ojbtest\">\n"+ 160 " <table name=\"A\">\n"+ 161 " <column name=\"attrKey\"\n"+ 162 " javaName=\"attrKey\"\n"+ 163 " type=\"INTEGER\"\n"+ 164 " />\n"+ 165 " </table>\n"+ 166 "</database>", 167 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 168 } 169 170 public void testClassRef3() 172 { 173 addClass( 174 "test.A", 175 "package test;\n"+ 176 "/** @ojb.class */\n"+ 177 "public class A {\n"+ 178 "/** @ojb.field */\n"+ 179 " private int attrKey;\n"+ 180 "/** @ojb.reference foreignkey=\"attrKey\" */\n"+ 181 " private float attr;\n"+ 182 "}\n"); 183 184 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 185 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 186 } 187 188 public void testClassRef4() 190 { 191 addClass( 192 "test.A", 193 "package test;\n"+ 194 "/** @ojb.class */\n"+ 195 "public class A {\n"+ 196 "/** @ojb.field */\n"+ 197 " private int attrKey;\n"+ 198 "/** @ojb.reference foreignkey=\"attrKey\" */\n"+ 199 " private test.B attr;\n"+ 200 "}\n"); 201 addClass( 202 "test.B", 203 "package test;\n"+ 204 "public class B {}\n"); 205 206 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 207 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 208 } 209 210 public void testClassRef5() 212 { 213 addClass( 214 "test.A", 215 "package test;\n"+ 216 "/** @ojb.class */\n"+ 217 "public class A {\n"+ 218 "/** @ojb.field */\n"+ 219 " private int attrKey;\n"+ 220 "/** @ojb.reference foreignkey=\"attrKey\" */\n"+ 221 " private test.B attr;\n"+ 222 "}\n"); 223 addClass( 224 "test.B", 225 "package test;\n"+ 226 "public class B {\n"+ 227 "/** @ojb.field primarykey=\"true\" */\n"+ 228 " private int id;\n"+ 229 "}\n"); 230 addClass( 231 "test.C", 232 "package test;\n"+ 233 "/** @ojb.class */\n"+ 234 "public class C extends B {}\n"); 235 236 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 237 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 238 } 239 240 public void testClassRef6() 242 { 243 addClass( 244 "test.A", 245 "package test;\n"+ 246 "/** @ojb.class */\n"+ 247 "public class A {\n"+ 248 "/** @ojb.field */\n"+ 249 " private int attrKey;\n"+ 250 "/** @ojb.reference class-ref=\"test.B\"\n"+ 251 " * foreignkey=\"attrKey\"\n"+ 252 " */\n"+ 253 " private B attr;\n"+ 254 "}\n"); 255 addClass( 256 "test.B", 257 "package test;\n"+ 258 "/** @ojb.class */\n"+ 259 "public class B {\n"+ 260 "/** @ojb.field primarykey=\"true\" */\n"+ 261 " private int id;\n"+ 262 "}\n"); 263 264 assertEqualsOjbDescriptorFile( 265 "<class-descriptor\n"+ 266 " class=\"test.A\"\n"+ 267 " table=\"A\"\n"+ 268 ">\n"+ 269 " <field-descriptor\n"+ 270 " name=\"attrKey\"\n"+ 271 " column=\"attrKey\"\n"+ 272 " jdbc-type=\"INTEGER\"\n"+ 273 " >\n"+ 274 " </field-descriptor>\n"+ 275 " <reference-descriptor\n"+ 276 " name=\"attr\"\n"+ 277 " class-ref=\"test.B\"\n"+ 278 " >\n"+ 279 " <foreignkey field-ref=\"attrKey\"/>\n"+ 280 " </reference-descriptor>\n"+ 281 "</class-descriptor>\n"+ 282 "<class-descriptor\n"+ 283 " class=\"test.B\"\n"+ 284 " table=\"B\"\n"+ 285 ">\n"+ 286 " <field-descriptor\n"+ 287 " name=\"id\"\n"+ 288 " column=\"id\"\n"+ 289 " jdbc-type=\"INTEGER\"\n"+ 290 " primarykey=\"true\"\n"+ 291 " >\n"+ 292 " </field-descriptor>\n"+ 293 "</class-descriptor>", 294 runOjbXDoclet(OJB_DEST_FILE)); 295 assertEqualsTorqueSchemaFile( 296 "<database name=\"ojbtest\">\n"+ 297 " <table name=\"A\">\n"+ 298 " <column name=\"attrKey\"\n"+ 299 " javaName=\"attrKey\"\n"+ 300 " type=\"INTEGER\"\n"+ 301 " />\n"+ 302 " <foreign-key foreignTable=\"B\">\n"+ 303 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 304 " </foreign-key>\n"+ 305 " </table>\n"+ 306 " <table name=\"B\">\n"+ 307 " <column name=\"id\"\n"+ 308 " javaName=\"id\"\n"+ 309 " type=\"INTEGER\"\n"+ 310 " primaryKey=\"true\"\n"+ 311 " required=\"true\"\n"+ 312 " />\n"+ 313 " </table>\n"+ 314 "</database>", 315 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 316 } 317 318 public void testClassRef7() 320 { 321 addClass( 322 "test.A", 323 "package test;\n"+ 324 "/** @ojb.class */\n"+ 325 "public class A {\n"+ 326 "/** @ojb.field */\n"+ 327 " private int attrKey;\n"+ 328 "/** @ojb.reference class-ref=\"test.B\"\n"+ 329 " * foreignkey=\"attrKey\"\n"+ 330 " */\n"+ 331 " private Object attr;\n"+ 332 "}\n"); 333 addClass( 334 "test.B", 335 "package test;\n"+ 336 "/** @ojb.class */\n"+ 337 "public class B {\n"+ 338 "/** @ojb.field primarykey=\"true\" */\n"+ 339 " private int id;\n"+ 340 "}\n"); 341 342 assertEqualsOjbDescriptorFile( 343 "<class-descriptor\n"+ 344 " class=\"test.A\"\n"+ 345 " table=\"A\"\n"+ 346 ">\n"+ 347 " <field-descriptor\n"+ 348 " name=\"attrKey\"\n"+ 349 " column=\"attrKey\"\n"+ 350 " jdbc-type=\"INTEGER\"\n"+ 351 " >\n"+ 352 " </field-descriptor>\n"+ 353 " <reference-descriptor\n"+ 354 " name=\"attr\"\n"+ 355 " class-ref=\"test.B\"\n"+ 356 " >\n"+ 357 " <foreignkey field-ref=\"attrKey\"/>\n"+ 358 " </reference-descriptor>\n"+ 359 "</class-descriptor>\n"+ 360 "<class-descriptor\n"+ 361 " class=\"test.B\"\n"+ 362 " table=\"B\"\n"+ 363 ">\n"+ 364 " <field-descriptor\n"+ 365 " name=\"id\"\n"+ 366 " column=\"id\"\n"+ 367 " jdbc-type=\"INTEGER\"\n"+ 368 " primarykey=\"true\"\n"+ 369 " >\n"+ 370 " </field-descriptor>\n"+ 371 "</class-descriptor>", 372 runOjbXDoclet(OJB_DEST_FILE)); 373 assertEqualsTorqueSchemaFile( 374 "<database name=\"ojbtest\">\n"+ 375 " <table name=\"A\">\n"+ 376 " <column name=\"attrKey\"\n"+ 377 " javaName=\"attrKey\"\n"+ 378 " type=\"INTEGER\"\n"+ 379 " />\n"+ 380 " <foreign-key foreignTable=\"B\">\n"+ 381 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 382 " </foreign-key>\n"+ 383 " </table>\n"+ 384 " <table name=\"B\">\n"+ 385 " <column name=\"id\"\n"+ 386 " javaName=\"id\"\n"+ 387 " type=\"INTEGER\"\n"+ 388 " primaryKey=\"true\"\n"+ 389 " required=\"true\"\n"+ 390 " />\n"+ 391 " </table>\n"+ 392 "</database>", 393 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 394 } 395 396 public void testClassRef8() 398 { 399 addClass( 400 "test.A", 401 "package test;\n"+ 402 "/** @ojb.class */\n"+ 403 "public class A {\n"+ 404 "/** @ojb.field */\n"+ 405 " private int attrKey;\n"+ 406 "/** @ojb.reference class-ref=\"test.B\"\n"+ 407 " * foreignkey=\"attrKey\"\n"+ 408 " */\n"+ 409 " private Object attr;\n"+ 410 "}\n"); 411 addClass( 412 "test.B", 413 "package test;\n"+ 414 "/** @ojb.class generate-table-info=\"false\" */\n"+ 415 "public class B {\n"+ 416 " /** @ojb.field primarykey=\"true\" */\n"+ 417 " private int id;\n"+ 418 "}\n"); 419 420 assertEqualsOjbDescriptorFile( 421 "<class-descriptor\n"+ 422 " class=\"test.A\"\n"+ 423 " table=\"A\"\n"+ 424 ">\n"+ 425 " <field-descriptor\n"+ 426 " name=\"attrKey\"\n"+ 427 " column=\"attrKey\"\n"+ 428 " jdbc-type=\"INTEGER\"\n"+ 429 " >\n"+ 430 " </field-descriptor>\n"+ 431 " <reference-descriptor\n"+ 432 " name=\"attr\"\n"+ 433 " class-ref=\"test.B\"\n"+ 434 " >\n"+ 435 " <foreignkey field-ref=\"attrKey\"/>\n"+ 436 " </reference-descriptor>\n"+ 437 "</class-descriptor>\n"+ 438 "<class-descriptor\n"+ 439 " class=\"test.B\"\n"+ 440 ">\n"+ 441 " <field-descriptor\n"+ 442 " name=\"id\"\n"+ 443 " column=\"id\"\n"+ 444 " jdbc-type=\"INTEGER\"\n"+ 445 " primarykey=\"true\"\n"+ 446 " >\n"+ 447 " </field-descriptor>\n"+ 448 "</class-descriptor>", 449 runOjbXDoclet(OJB_DEST_FILE)); 450 assertEqualsTorqueSchemaFile( 451 "<database name=\"ojbtest\">\n"+ 452 " <table name=\"A\">\n"+ 453 " <column name=\"attrKey\"\n"+ 454 " javaName=\"attrKey\"\n"+ 455 " type=\"INTEGER\"\n"+ 456 " />\n"+ 457 " </table>\n"+ 458 "</database>", 459 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 460 } 461 462 public void testClassRef9() 464 { 465 addClass( 466 "test.A", 467 "package test;\n"+ 468 "/** @ojb.class */\n"+ 469 "public class A {\n"+ 470 "/** @ojb.field */\n"+ 471 " private int attrKey;\n"+ 472 "/** @ojb.reference class-ref=\"boolean\"\n"+ 473 " * foreignkey=\"attrKey\"\n"+ 474 " */\n"+ 475 " private Object attr;\n"+ 476 "}\n"); 477 478 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 479 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 480 } 481 482 public void testClassRef10() 484 { 485 addClass( 486 "test.A", 487 "package test;\n"+ 488 "/** @ojb.class */\n"+ 489 "public class A {\n"+ 490 "/** @ojb.field */\n"+ 491 " private int attrKey;\n"+ 492 "/** @ojb.reference class-ref=\"test.B\"\n"+ 493 " * foreignkey=\"attrKey\"\n"+ 494 " */\n"+ 495 " private Object attr;\n"+ 496 "}\n"); 497 addClass( 498 "test.B", 499 "package test;\n"+ 500 "public class B {}\n"); 501 502 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 503 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 504 } 505 506 public void testClassRef11() 508 { 509 addClass( 510 "test.A", 511 "package test;\n"+ 512 "/** @ojb.class */\n"+ 513 "public class A {\n"+ 514 "/** @ojb.field */\n"+ 515 " private int attrKey;\n"+ 516 "/** @ojb.reference class-ref=\"test.C\"\n"+ 517 " * foreignkey=\"attrKey\"\n"+ 518 " */\n"+ 519 " private test.B attr;\n"+ 520 "}\n"); 521 addClass( 522 "test.B", 523 "package test;\n"+ 524 "/** @ojb.class */\n"+ 525 "public class B {\n"+ 526 "/** @ojb.field primarykey=\"true\" */\n"+ 527 " private int id;\n"+ 528 "}\n"); 529 addClass( 530 "test.C", 531 "package test;\n"+ 532 "public class C extends test.B {}\n"); 533 534 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 535 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 536 } 537 538 public void testClassRef12() 540 { 541 addClass( 542 "test.A", 543 "package test;\n"+ 544 "/** @ojb.class */\n"+ 545 "public class A {\n"+ 546 "/** @ojb.field */\n"+ 547 " private int attrKey;\n"+ 548 "/** @ojb.reference class-ref=\"test.B\"\n"+ 549 " * foreignkey=\"attrKey\"\n"+ 550 " */\n"+ 551 " private Object attr;\n"+ 552 "}\n"); 553 addClass( 554 "test.B", 555 "package test;\n"+ 556 "public class B {}\n"); 557 addClass( 558 "test.C", 559 "package test;\n"+ 560 "/** @ojb.class */\n"+ 561 "public class C extends test.B {\n"+ 562 "/** @ojb.field primarykey=\"true\" */\n"+ 563 " private int id;\n"+ 564 "}\n"); 565 566 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 567 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 568 } 569 570 public void testClassRef13() 572 { 573 addClass( 574 "test.A", 575 "package test;\n"+ 576 "/** @ojb.class */\n"+ 577 "public class A {\n"+ 578 "/** @ojb.field */\n"+ 579 " private int attrKey;\n"+ 580 "/** @ojb.reference class-ref=\"test.C\"\n"+ 581 " * foreignkey=\"attrKey\"\n"+ 582 " */\n"+ 583 " private test.B attr;\n"+ 584 "}\n"); 585 addClass( 586 "test.B", 587 "package test;\n"+ 588 "/** @ojb.class */\n"+ 589 "public class B {\n"+ 590 "/** @ojb.field primarykey=\"true\" */\n"+ 591 " private int id;\n"+ 592 "}\n"); 593 addClass( 594 "test.C", 595 "package test;\n"+ 596 "/** @ojb.class */\n"+ 597 "public class C {\n"+ 598 "/** @ojb.field primarykey=\"true\" */\n"+ 599 " private int id;\n"+ 600 "}\n"); 601 602 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 603 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 604 } 605 606 public void testClassRef14() 608 { 609 addClass( 610 "test.A", 611 "package test;\n"+ 612 "/** @ojb.class */\n"+ 613 "public class A {\n"+ 614 "/** @ojb.field */\n"+ 615 " private int attrKey;\n"+ 616 "/** @ojb.reference class-ref=\"test.C\"\n"+ 617 " * foreignkey=\"attrKey\"\n"+ 618 " */\n"+ 619 " private test.B attr;\n"+ 620 "}\n"); 621 addClass( 622 "test.B", 623 "package test;\n"+ 624 "/** @ojb.class generate-table-info=\"false\" */\n"+ 625 "public interface B {}\n"); 626 addClass( 627 "test.C", 628 "package test;\n"+ 629 "/** @ojb.class */\n"+ 630 "public class C {\n"+ 631 "/** @ojb.field primarykey=\"true\" */\n"+ 632 " private int id;\n"+ 633 "}\n"); 634 635 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 636 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 637 } 638 639 public void testClassRef15() 641 { 642 addClass( 643 "test.A", 644 "package test;\n"+ 645 "/** @ojb.class */\n"+ 646 "public class A {\n"+ 647 "/** @ojb.field */\n"+ 648 " private int attrKey;\n"+ 649 "/** @ojb.reference class-ref=\"test.C\"\n"+ 650 " * foreignkey=\"attrKey\"\n"+ 651 " */\n"+ 652 " private test.B attr;\n"+ 653 "}\n"); 654 addClass( 655 "test.B", 656 "package test;\n"+ 657 "/** @ojb.class */\n"+ 658 "public class B {\n"+ 659 "/** @ojb.field primarykey=\"true\" */\n"+ 660 " private int id;\n"+ 661 "}\n"); 662 addClass( 663 "test.C", 664 "package test;\n"+ 665 "/** @ojb.class */\n"+ 666 "public class C extends B {}\n"); 667 668 assertEqualsOjbDescriptorFile( 669 "<class-descriptor\n"+ 670 " class=\"test.A\"\n"+ 671 " table=\"A\"\n"+ 672 ">\n"+ 673 " <field-descriptor\n"+ 674 " name=\"attrKey\"\n"+ 675 " column=\"attrKey\"\n"+ 676 " jdbc-type=\"INTEGER\"\n"+ 677 " >\n"+ 678 " </field-descriptor>\n"+ 679 " <reference-descriptor\n"+ 680 " name=\"attr\"\n"+ 681 " class-ref=\"test.C\"\n"+ 682 " >\n"+ 683 " <foreignkey field-ref=\"attrKey\"/>\n"+ 684 " </reference-descriptor>\n"+ 685 "</class-descriptor>\n"+ 686 "<class-descriptor\n"+ 687 " class=\"test.B\"\n"+ 688 " table=\"B\"\n"+ 689 ">\n"+ 690 " <extent-class class-ref=\"test.C\"/>\n"+ 691 " <field-descriptor\n"+ 692 " name=\"id\"\n"+ 693 " column=\"id\"\n"+ 694 " jdbc-type=\"INTEGER\"\n"+ 695 " primarykey=\"true\"\n"+ 696 " >\n"+ 697 " </field-descriptor>\n"+ 698 "</class-descriptor>\n"+ 699 "<class-descriptor\n"+ 700 " class=\"test.C\"\n"+ 701 " table=\"C\"\n"+ 702 ">\n"+ 703 " <field-descriptor\n"+ 704 " name=\"id\"\n"+ 705 " column=\"id\"\n"+ 706 " jdbc-type=\"INTEGER\"\n"+ 707 " primarykey=\"true\"\n"+ 708 " >\n"+ 709 " </field-descriptor>\n"+ 710 "</class-descriptor>", 711 runOjbXDoclet(OJB_DEST_FILE)); 712 assertEqualsTorqueSchemaFile( 713 "<database name=\"ojbtest\">\n"+ 714 " <table name=\"A\">\n"+ 715 " <column name=\"attrKey\"\n"+ 716 " javaName=\"attrKey\"\n"+ 717 " type=\"INTEGER\"\n"+ 718 " />\n"+ 719 " <foreign-key foreignTable=\"C\">\n"+ 720 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 721 " </foreign-key>\n"+ 722 " </table>\n"+ 723 " <table name=\"B\">\n"+ 724 " <column name=\"id\"\n"+ 725 " javaName=\"id\"\n"+ 726 " type=\"INTEGER\"\n"+ 727 " primaryKey=\"true\"\n"+ 728 " required=\"true\"\n"+ 729 " />\n"+ 730 " </table>\n"+ 731 " <table name=\"C\">\n"+ 732 " <column name=\"id\"\n"+ 733 " javaName=\"id\"\n"+ 734 " type=\"INTEGER\"\n"+ 735 " primaryKey=\"true\"\n"+ 736 " required=\"true\"\n"+ 737 " />\n"+ 738 " </table>\n"+ 739 "</database>", 740 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 741 } 742 743 public void testClassRef16() 745 { 746 addClass( 747 "test.A", 748 "package test;\n"+ 749 "/** @ojb.class */\n"+ 750 "public class A {\n"+ 751 "/** @ojb.field */\n"+ 752 " private int attrKey;\n"+ 753 "/** @ojb.reference class-ref=\"test.D\"\n"+ 754 " * foreignkey=\"attrKey\"\n"+ 755 " */\n"+ 756 " private test.B attr;\n"+ 757 "}\n"); 758 addClass( 759 "test.B", 760 "package test;\n"+ 761 "public interface B {}\n"); 762 addClass( 763 "test.C", 764 "package test;\n"+ 765 "public class C implements B {}\n"); 766 addClass( 767 "test.D", 768 "package test;\n"+ 769 "/** @ojb.class */\n"+ 770 "public class D extends C {\n"+ 771 "/** @ojb.field primarykey=\"true\" */\n"+ 772 " private int id;\n"+ 773 "}\n"); 774 775 assertEqualsOjbDescriptorFile( 776 "<class-descriptor\n"+ 777 " class=\"test.A\"\n"+ 778 " table=\"A\"\n"+ 779 ">\n"+ 780 " <field-descriptor\n"+ 781 " name=\"attrKey\"\n"+ 782 " column=\"attrKey\"\n"+ 783 " jdbc-type=\"INTEGER\"\n"+ 784 " >\n"+ 785 " </field-descriptor>\n"+ 786 " <reference-descriptor\n"+ 787 " name=\"attr\"\n"+ 788 " class-ref=\"test.D\"\n"+ 789 " >\n"+ 790 " <foreignkey field-ref=\"attrKey\"/>\n"+ 791 " </reference-descriptor>\n"+ 792 "</class-descriptor>\n"+ 793 "<class-descriptor\n"+ 794 " class=\"test.D\"\n"+ 795 " table=\"D\"\n"+ 796 ">\n"+ 797 " <field-descriptor\n"+ 798 " name=\"id\"\n"+ 799 " column=\"id\"\n"+ 800 " jdbc-type=\"INTEGER\"\n"+ 801 " primarykey=\"true\"\n"+ 802 " >\n"+ 803 " </field-descriptor>\n"+ 804 "</class-descriptor>", 805 runOjbXDoclet(OJB_DEST_FILE)); 806 assertEqualsTorqueSchemaFile( 807 "<database name=\"ojbtest\">\n"+ 808 " <table name=\"A\">\n"+ 809 " <column name=\"attrKey\"\n"+ 810 " javaName=\"attrKey\"\n"+ 811 " type=\"INTEGER\"\n"+ 812 " />\n"+ 813 " <foreign-key foreignTable=\"D\">\n"+ 814 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 815 " </foreign-key>\n"+ 816 " </table>\n"+ 817 " <table name=\"D\">\n"+ 818 " <column name=\"id\"\n"+ 819 " javaName=\"id\"\n"+ 820 " type=\"INTEGER\"\n"+ 821 " primaryKey=\"true\"\n"+ 822 " required=\"true\"\n"+ 823 " />\n"+ 824 " </table>\n"+ 825 "</database>", 826 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 827 } 828 829 public void testClassRef17() 831 { 832 addClass( 833 "test.A", 834 "package test;\n"+ 835 "/** @ojb.class\n"+ 836 " * @ojb.field name=\"attrKey\"\n"+ 837 " * jdbc-type=\"INTEGER\"\n"+ 838 " */\n"+ 839 "public class A {\n"+ 840 " /** @ojb.field primarykey=\"true\" */\n"+ 841 " private int id;\n"+ 842 " /** @ojb.reference foreignkey=\"attrKey\" */\n"+ 843 " private test.A attr;\n"+ 844 "}\n"); 845 846 assertEqualsOjbDescriptorFile( 847 "<class-descriptor\n"+ 848 " class=\"test.A\"\n"+ 849 " table=\"A\"\n"+ 850 ">\n"+ 851 " <field-descriptor\n"+ 852 " name=\"attrKey\"\n"+ 853 " column=\"attrKey\"\n"+ 854 " jdbc-type=\"INTEGER\"\n"+ 855 " access=\"anonymous\"\n"+ 856 " >\n"+ 857 " </field-descriptor>\n"+ 858 " <field-descriptor\n"+ 859 " name=\"id\"\n"+ 860 " column=\"id\"\n"+ 861 " jdbc-type=\"INTEGER\"\n"+ 862 " primarykey=\"true\"\n"+ 863 " >\n"+ 864 " </field-descriptor>\n"+ 865 " <reference-descriptor\n"+ 866 " name=\"attr\"\n"+ 867 " class-ref=\"test.A\"\n"+ 868 " >\n"+ 869 " <foreignkey field-ref=\"attrKey\"/>\n"+ 870 " </reference-descriptor>\n"+ 871 "</class-descriptor>", 872 runOjbXDoclet(OJB_DEST_FILE)); 873 assertEqualsTorqueSchemaFile( 874 "<database name=\"ojbtest\">\n"+ 875 " <table name=\"A\">\n"+ 876 " <column name=\"attrKey\"\n"+ 877 " javaName=\"attrKey\"\n"+ 878 " type=\"INTEGER\"\n"+ 879 " />\n"+ 880 " <column name=\"id\"\n"+ 881 " javaName=\"id\"\n"+ 882 " type=\"INTEGER\"\n"+ 883 " primaryKey=\"true\"\n"+ 884 " required=\"true\"\n"+ 885 " />\n"+ 886 " <foreign-key foreignTable=\"A\">\n"+ 887 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 888 " </foreign-key>\n"+ 889 " </table>\n"+ 890 "</database>", 891 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 892 } 893 894 public void testClassRef18() 896 { 897 addClass( 898 "test.A", 899 "package test;\n"+ 900 "/** @ojb.class table=\"A\" */\n"+ 901 "public interface A {\n"+ 902 " /** @ojb.field primarykey=\"true\" */\n"+ 903 " public Integer getId();\n"+ 904 " /** @ojb.field length=\"254\" */\n"+ 905 " public String getOjbConcreteClass();\n"+ 906 "}\n"); 907 addClass( 908 "test.B", 909 "package test;\n"+ 910 "/** @ojb.class table=\"A\" */\n"+ 911 "public abstract class B implements A {\n"+ 912 " private Integer id;\n"+ 913 " private String ojbConcreteClass;\n"+ 914 " public Integer getId() {\n"+ 915 " return id;\n"+ 916 " }\n"+ 917 " public String getOjbConcreteClass() {\n"+ 918 " return ojbConcreteClass;\n"+ 919 " }\n"+ 920 "}\n"); 921 addClass( 922 "test.C", 923 "package test;\n"+ 924 "/** @ojb.class table=\"A\" */\n"+ 925 "public class C extends B {\n"+ 926 " /** @ojb.field length=\"254\" */\n"+ 927 " private String value;\n"+ 928 "}\n"); 929 addClass( 930 "test.D", 931 "package test;\n"+ 932 "/** @ojb.class */\n"+ 933 "public class D {\n"+ 934 " /** @ojb.field primarykey=\"true\" */\n"+ 935 " private Integer id;\n"+ 936 " /** @ojb.field */\n"+ 937 " private Integer aid;\n"+ 938 " /** @ojb.reference foreignkey=\"aid\" */\n"+ 939 " private test.A attr;\n"+ 940 "}\n"); 941 942 assertEqualsOjbDescriptorFile( 943 "<class-descriptor\n"+ 944 " class=\"test.A\"\n"+ 945 " table=\"A\"\n"+ 946 ">\n"+ 947 " <extent-class class-ref=\"test.B\"/>\n"+ 948 " <field-descriptor\n"+ 949 " name=\"id\"\n"+ 950 " column=\"id\"\n"+ 951 " jdbc-type=\"INTEGER\"\n"+ 952 " primarykey=\"true\"\n"+ 953 " >\n"+ 954 " </field-descriptor>\n"+ 955 " <field-descriptor\n"+ 956 " name=\"ojbConcreteClass\"\n"+ 957 " column=\"ojbConcreteClass\"\n"+ 958 " jdbc-type=\"VARCHAR\"\n"+ 959 " length=\"254\"\n"+ 960 " >\n"+ 961 " </field-descriptor>\n"+ 962 "</class-descriptor>\n"+ 963 "<class-descriptor\n"+ 964 " class=\"test.B\"\n"+ 965 " table=\"A\"\n"+ 966 ">\n"+ 967 " <extent-class class-ref=\"test.C\"/>\n"+ 968 " <field-descriptor\n"+ 969 " name=\"id\"\n"+ 970 " column=\"id\"\n"+ 971 " jdbc-type=\"INTEGER\"\n"+ 972 " primarykey=\"true\"\n"+ 973 " >\n"+ 974 " </field-descriptor>\n"+ 975 " <field-descriptor\n"+ 976 " name=\"ojbConcreteClass\"\n"+ 977 " column=\"ojbConcreteClass\"\n"+ 978 " jdbc-type=\"VARCHAR\"\n"+ 979 " length=\"254\"\n"+ 980 " >\n"+ 981 " </field-descriptor>\n"+ 982 "</class-descriptor>\n"+ 983 "<class-descriptor\n"+ 984 " class=\"test.C\"\n"+ 985 " table=\"A\"\n"+ 986 ">\n"+ 987 " <field-descriptor\n"+ 988 " name=\"id\"\n"+ 989 " column=\"id\"\n"+ 990 " jdbc-type=\"INTEGER\"\n"+ 991 " primarykey=\"true\"\n"+ 992 " >\n"+ 993 " </field-descriptor>\n"+ 994 " <field-descriptor\n"+ 995 " name=\"ojbConcreteClass\"\n"+ 996 " column=\"ojbConcreteClass\"\n"+ 997 " jdbc-type=\"VARCHAR\"\n"+ 998 " length=\"254\"\n"+ 999 " >\n"+ 1000 " </field-descriptor>\n"+ 1001 " <field-descriptor\n"+ 1002 " name=\"value\"\n"+ 1003 " column=\"value\"\n"+ 1004 " jdbc-type=\"VARCHAR\"\n"+ 1005 " length=\"254\"\n"+ 1006 " >\n"+ 1007 " </field-descriptor>\n"+ 1008 "</class-descriptor>\n"+ 1009 "<class-descriptor\n"+ 1010 " class=\"test.D\"\n"+ 1011 " table=\"D\"\n"+ 1012 ">\n"+ 1013 " <field-descriptor\n"+ 1014 " name=\"id\"\n"+ 1015 " column=\"id\"\n"+ 1016 " jdbc-type=\"INTEGER\"\n"+ 1017 " primarykey=\"true\"\n"+ 1018 " >\n"+ 1019 " </field-descriptor>\n"+ 1020 " <field-descriptor\n"+ 1021 " name=\"aid\"\n"+ 1022 " column=\"aid\"\n"+ 1023 " jdbc-type=\"INTEGER\"\n"+ 1024 " >\n"+ 1025 " </field-descriptor>\n"+ 1026 " <reference-descriptor\n"+ 1027 " name=\"attr\"\n"+ 1028 " class-ref=\"test.A\"\n"+ 1029 " >\n"+ 1030 " <foreignkey field-ref=\"aid\"/>\n"+ 1031 " </reference-descriptor>\n"+ 1032 "</class-descriptor>", 1033 runOjbXDoclet(OJB_DEST_FILE)); 1034 assertEqualsTorqueSchemaFile( 1035 "<database name=\"ojbtest\">\n"+ 1036 " <table name=\"A\">\n"+ 1037 " <column name=\"id\"\n"+ 1038 " javaName=\"id\"\n"+ 1039 " type=\"INTEGER\"\n"+ 1040 " primaryKey=\"true\"\n"+ 1041 " required=\"true\"\n"+ 1042 " />\n"+ 1043 " <column name=\"ojbConcreteClass\"\n"+ 1044 " javaName=\"ojbConcreteClass\"\n"+ 1045 " type=\"VARCHAR\"\n"+ 1046 " size=\"254\"\n"+ 1047 " />\n"+ 1048 " <column name=\"value\"\n"+ 1049 " javaName=\"value\"\n"+ 1050 " type=\"VARCHAR\"\n"+ 1051 " size=\"254\"\n"+ 1052 " />\n"+ 1053 " </table>\n"+ 1054 " <table name=\"D\">\n"+ 1055 " <column name=\"id\"\n"+ 1056 " javaName=\"id\"\n"+ 1057 " type=\"INTEGER\"\n"+ 1058 " primaryKey=\"true\"\n"+ 1059 " required=\"true\"\n"+ 1060 " />\n"+ 1061 " <column name=\"aid\"\n"+ 1062 " javaName=\"aid\"\n"+ 1063 " type=\"INTEGER\"\n"+ 1064 " />\n"+ 1065 " <foreign-key foreignTable=\"A\">\n"+ 1066 " <reference local=\"aid\" foreign=\"id\"/>\n"+ 1067 " </foreign-key>\n"+ 1068 " </table>\n"+ 1069 "</database>", 1070 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1071 } 1072 1073 public void testClassRef19() 1075 { 1076 addClass( 1077 "test.A", 1078 "package test;\n"+ 1079 "/** @ojb.class */\n"+ 1080 "public class A {\n"+ 1081 "/** @ojb.field */\n"+ 1082 " private int attrKey;\n"+ 1083 "/** @ojb.reference foreignkey=\"attrKey\" */\n"+ 1084 " private test.B.Inner attr;\n"+ 1085 "}\n"); 1086 addClass( 1087 "test.B", 1088 "package test;\n"+ 1089 "public class B {\n"+ 1090 " /** @ojb.class */\n"+ 1091 " public static class Inner {\n"+ 1092 " /** @ojb.field primarykey=\"true\" */\n"+ 1093 " private int id;\n"+ 1094 " }\n"+ 1095 "}\n"); 1096 1097 assertEqualsOjbDescriptorFile( 1098 "<class-descriptor\n"+ 1099 " class=\"test.A\"\n"+ 1100 " table=\"A\"\n"+ 1101 ">\n"+ 1102 " <field-descriptor\n"+ 1103 " name=\"attrKey\"\n"+ 1104 " column=\"attrKey\"\n"+ 1105 " jdbc-type=\"INTEGER\"\n"+ 1106 " >\n"+ 1107 " </field-descriptor>\n"+ 1108 " <reference-descriptor\n"+ 1109 " name=\"attr\"\n"+ 1110 " class-ref=\"test.B$Inner\"\n"+ 1111 " >\n"+ 1112 " <foreignkey field-ref=\"attrKey\"/>\n"+ 1113 " </reference-descriptor>\n"+ 1114 "</class-descriptor>\n"+ 1115 "<class-descriptor\n"+ 1116 " class=\"test.B$Inner\"\n"+ 1117 " table=\"Inner\"\n"+ 1118 ">\n"+ 1119 " <field-descriptor\n"+ 1120 " name=\"id\"\n"+ 1121 " column=\"id\"\n"+ 1122 " jdbc-type=\"INTEGER\"\n"+ 1123 " primarykey=\"true\"\n"+ 1124 " >\n"+ 1125 " </field-descriptor>\n"+ 1126 "</class-descriptor>", 1127 runOjbXDoclet(OJB_DEST_FILE)); 1128 assertEqualsTorqueSchemaFile( 1129 "<database name=\"ojbtest\">\n"+ 1130 " <table name=\"A\">\n"+ 1131 " <column name=\"attrKey\"\n"+ 1132 " javaName=\"attrKey\"\n"+ 1133 " type=\"INTEGER\"\n"+ 1134 " />\n"+ 1135 " <foreign-key foreignTable=\"Inner\">\n"+ 1136 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 1137 " </foreign-key>\n"+ 1138 " </table>\n"+ 1139 " <table name=\"Inner\">\n"+ 1140 " <column name=\"id\"\n"+ 1141 " javaName=\"id\"\n"+ 1142 " type=\"INTEGER\"\n"+ 1143 " primaryKey=\"true\"\n"+ 1144 " required=\"true\"\n"+ 1145 " />\n"+ 1146 " </table>\n"+ 1147 "</database>", 1148 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1149 } 1150 1151 public void testClassRef20() 1153 { 1154 addClass( 1155 "test.A", 1156 "package test;\n"+ 1157 "/** @ojb.class */\n"+ 1158 "public class A {\n"+ 1159 " /** @ojb.class */\n"+ 1160 " public class Inner {\n"+ 1161 " /** @ojb.field primarykey=\"true\" */\n"+ 1162 " private int id;\n"+ 1163 " }\n"+ 1164 " /** @ojb.field */\n"+ 1165 " private int attrKey;\n"+ 1166 " /** @ojb.reference foreignkey=\"attrKey\"\n"+ 1167 " * class-ref=\"test.A$Inner\"\n"+ 1168 " */\n"+ 1169 " private Object attr;\n"+ 1170 "}\n"); 1171 1172 assertEqualsOjbDescriptorFile( 1173 "<class-descriptor\n"+ 1174 " class=\"test.A\"\n"+ 1175 " table=\"A\"\n"+ 1176 ">\n"+ 1177 " <field-descriptor\n"+ 1178 " name=\"attrKey\"\n"+ 1179 " column=\"attrKey\"\n"+ 1180 " jdbc-type=\"INTEGER\"\n"+ 1181 " >\n"+ 1182 " </field-descriptor>\n"+ 1183 " <reference-descriptor\n"+ 1184 " name=\"attr\"\n"+ 1185 " class-ref=\"test.A$Inner\"\n"+ 1186 " >\n"+ 1187 " <foreignkey field-ref=\"attrKey\"/>\n"+ 1188 " </reference-descriptor>\n"+ 1189 "</class-descriptor>\n"+ 1190 "<class-descriptor\n"+ 1191 " class=\"test.A$Inner\"\n"+ 1192 " table=\"Inner\"\n"+ 1193 ">\n"+ 1194 " <field-descriptor\n"+ 1195 " name=\"id\"\n"+ 1196 " column=\"id\"\n"+ 1197 " jdbc-type=\"INTEGER\"\n"+ 1198 " primarykey=\"true\"\n"+ 1199 " >\n"+ 1200 " </field-descriptor>\n"+ 1201 "</class-descriptor>", 1202 runOjbXDoclet(OJB_DEST_FILE)); 1203 assertEqualsTorqueSchemaFile( 1204 "<database name=\"ojbtest\">\n"+ 1205 " <table name=\"A\">\n"+ 1206 " <column name=\"attrKey\"\n"+ 1207 " javaName=\"attrKey\"\n"+ 1208 " type=\"INTEGER\"\n"+ 1209 " />\n"+ 1210 " <foreign-key foreignTable=\"Inner\">\n"+ 1211 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 1212 " </foreign-key>\n"+ 1213 " </table>\n"+ 1214 " <table name=\"Inner\">\n"+ 1215 " <column name=\"id\"\n"+ 1216 " javaName=\"id\"\n"+ 1217 " type=\"INTEGER\"\n"+ 1218 " primaryKey=\"true\"\n"+ 1219 " required=\"true\"\n"+ 1220 " />\n"+ 1221 " </table>\n"+ 1222 "</database>", 1223 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1224 } 1225 1226 public void testClassRef21() 1229 { 1230 addClass( 1231 "test.A", 1232 "package test;\n"+ 1233 "/** @ojb.class */\n"+ 1234 "public class A {\n"+ 1235 " /** @ojb.field primarykey=\"true\" */\n"+ 1236 " private Integer id;\n"+ 1237 "}\n"); 1238 addClass( 1239 "test.B", 1240 "package test;\n"+ 1241 "/** @ojb.class */\n"+ 1242 "public class B {\n"+ 1243 " /** @ojb.field */\n"+ 1244 " private Integer aid;\n"+ 1245 " /** @ojb.reference foreignkey=\"aid\"\n"+ 1246 " * class-ref=\"test.A\"\n"+ 1247 " */\n"+ 1248 " private T attr;\n"+ 1249 "}\n"); 1250 1251 assertEqualsOjbDescriptorFile( 1253 "<class-descriptor\n"+ 1254 " class=\"test.A\"\n"+ 1255 " table=\"A\"\n"+ 1256 ">\n"+ 1257 " <field-descriptor\n"+ 1258 " name=\"id\"\n"+ 1259 " column=\"id\"\n"+ 1260 " jdbc-type=\"INTEGER\"\n"+ 1261 " primarykey=\"true\"\n"+ 1262 " >\n"+ 1263 " </field-descriptor>\n"+ 1264 "</class-descriptor>\n"+ 1265 "<class-descriptor\n"+ 1266 " class=\"test.B\"\n"+ 1267 " table=\"B\"\n"+ 1268 ">\n"+ 1269 " <field-descriptor\n"+ 1270 " name=\"aid\"\n"+ 1271 " column=\"aid\"\n"+ 1272 " jdbc-type=\"INTEGER\"\n"+ 1273 " >\n"+ 1274 " </field-descriptor>\n"+ 1275 " <reference-descriptor\n"+ 1276 " name=\"attr\"\n"+ 1277 " class-ref=\"test.A\"\n"+ 1278 " >\n"+ 1279 " <foreignkey field-ref=\"aid\"/>\n"+ 1280 " </reference-descriptor>\n"+ 1281 "</class-descriptor>", 1282 runOjbXDoclet(OJB_DEST_FILE)); 1283 assertEqualsTorqueSchemaFile( 1284 "<database name=\"ojbtest\">\n"+ 1285 " <table name=\"A\">\n"+ 1286 " <column name=\"id\"\n"+ 1287 " javaName=\"id\"\n"+ 1288 " type=\"INTEGER\"\n"+ 1289 " primaryKey=\"true\"\n"+ 1290 " required=\"true\"\n"+ 1291 " />\n"+ 1292 " </table>\n"+ 1293 " <table name=\"B\">\n"+ 1294 " <column name=\"aid\"\n"+ 1295 " javaName=\"aid\"\n"+ 1296 " type=\"INTEGER\"\n"+ 1297 " />\n"+ 1298 " <foreign-key foreignTable=\"A\">\n"+ 1299 " <reference local=\"aid\" foreign=\"id\"/>\n"+ 1300 " </foreign-key>\n"+ 1301 " </table>\n"+ 1302 "</database>", 1303 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1304 } 1305} 1306 | Popular Tags |