1 package xdoclet.modules.ojb.tests; 2 3 17 18 23 public class ModifyInheritedTagPrimarykeyAttributeTests extends OjbTestBase 24 { 25 public ModifyInheritedTagPrimarykeyAttributeTests(String name) 26 { 27 super(name); 28 } 29 30 public void testPrimarykey1() 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 attr;\n"+ 40 "}"); 41 addClass( 42 "test.B", 43 "package test;\n"+ 44 "/** @ojb.class\n" + 45 " * @ojb.modify-inherited name=\"attr\"\n"+ 46 " * primarykey=\"true\"\n"+ 47 " */\n"+ 48 "public class B extends A {}\n"); 49 50 assertEqualsOjbDescriptorFile( 51 "<class-descriptor\n"+ 52 " class=\"test.A\"\n"+ 53 " table=\"A\"\n"+ 54 ">\n"+ 55 " <extent-class class-ref=\"test.B\"/>\n"+ 56 " <field-descriptor\n"+ 57 " name=\"attr\"\n"+ 58 " column=\"attr\"\n"+ 59 " jdbc-type=\"INTEGER\"\n"+ 60 " >\n"+ 61 " </field-descriptor>\n"+ 62 "</class-descriptor>\n"+ 63 "<class-descriptor\n"+ 64 " class=\"test.B\"\n"+ 65 " table=\"B\"\n"+ 66 ">\n"+ 67 " <field-descriptor\n"+ 68 " name=\"attr\"\n"+ 69 " column=\"attr\"\n"+ 70 " jdbc-type=\"INTEGER\"\n"+ 71 " primarykey=\"true\"\n"+ 72 " >\n"+ 73 " </field-descriptor>\n"+ 74 "</class-descriptor>", 75 runOjbXDoclet(OJB_DEST_FILE)); 76 assertEqualsTorqueSchemaFile( 77 "<database name=\"ojbtest\">\n"+ 78 " <table name=\"A\">\n"+ 79 " <column name=\"attr\"\n"+ 80 " javaName=\"attr\"\n"+ 81 " type=\"INTEGER\"\n"+ 82 " />\n"+ 83 " </table>\n"+ 84 " <table name=\"B\">\n"+ 85 " <column name=\"attr\"\n"+ 86 " javaName=\"attr\"\n"+ 87 " type=\"INTEGER\"\n"+ 88 " primaryKey=\"true\"\n"+ 89 " required=\"true\"\n"+ 90 " />\n"+ 91 " </table>\n"+ 92 "</database>", 93 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 94 } 95 96 public void testPrimarykey2() 98 { 99 addClass( 100 "test.A", 101 "package test;\n"+ 102 "/** @ojb.class */\n" + 103 "public class A {\n"+ 104 " /** @ojb.field */\n"+ 105 " private int bid;\n"+ 106 " /** @ojb.reference foreignkey=\"bid\" */\n"+ 107 " private B b;\n"+ 108 "}"); 109 addClass( 110 "test.B", 111 "package test;\n"+ 112 "/** @ojb.class */\n" + 113 "public class B {\n"+ 114 " /** @ojb.field primarykey=\"true\" */\n"+ 115 " private int id;\n"+ 116 "}"); 117 addClass( 118 "test.C", 119 "package test;\n"+ 120 "/** @ojb.class\n" + 121 " * @ojb.modify-inherited name=\"b\"\n"+ 122 " * primarykey=\"false\"\n"+ 123 " */\n"+ 124 "public class C extends A {}\n"); 125 126 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 127 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 128 } 129 130 public void testPrimarykey3() 132 { 133 addClass( 134 "test.A", 135 "package test;\n"+ 136 "/** @ojb.class */\n" + 137 "public class A {\n"+ 138 " /** @ojb.field primarykey=\"true\" */\n"+ 139 " private int id;\n"+ 140 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 141 " * foreignkey=\"aid\"\n"+ 142 " */\n"+ 143 " private java.util.Collection bs;\n"+ 144 "}"); 145 addClass( 146 "test.B", 147 "package test;\n"+ 148 "/** @ojb.class */\n" + 149 "public class B {\n"+ 150 " /** @ojb.field */\n"+ 151 " private int aid;\n"+ 152 "}"); 153 addClass( 154 "test.C", 155 "package test;\n"+ 156 "/** @ojb.class\n" + 157 " * @ojb.modify-inherited name=\"bs\"\n"+ 158 " * primarykey=\"true\"\n"+ 159 " */\n"+ 160 "public class C extends A {}\n"); 161 162 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 163 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 164 } 165 166 public void testPrimarykey4() 168 { 169 addClass( 170 "test.A", 171 "package test;\n"+ 172 "/** @ojb.class\n"+ 173 " * @ojb.field name=\"attr\"\n"+ 174 " * jdbc-type=\"INTEGER\"\n"+ 175 " * primarykey=\"true\"\n"+ 176 " */\n" + 177 "public class A {}"); 178 addClass( 179 "test.B", 180 "package test;\n"+ 181 "/** @ojb.class\n" + 182 " * @ojb.modify-inherited name=\"attr\"\n"+ 183 " * primarykey=\"false\"\n"+ 184 " */\n"+ 185 "public class B extends A {}\n"); 186 187 assertEqualsOjbDescriptorFile( 188 "<class-descriptor\n"+ 189 " class=\"test.A\"\n"+ 190 " table=\"A\"\n"+ 191 ">\n"+ 192 " <extent-class class-ref=\"test.B\"/>\n"+ 193 " <field-descriptor\n"+ 194 " name=\"attr\"\n"+ 195 " column=\"attr\"\n"+ 196 " jdbc-type=\"INTEGER\"\n"+ 197 " primarykey=\"true\"\n"+ 198 " access=\"anonymous\"\n"+ 199 " >\n"+ 200 " </field-descriptor>\n"+ 201 "</class-descriptor>\n"+ 202 "<class-descriptor\n"+ 203 " class=\"test.B\"\n"+ 204 " table=\"B\"\n"+ 205 ">\n"+ 206 " <field-descriptor\n"+ 207 " name=\"attr\"\n"+ 208 " column=\"attr\"\n"+ 209 " jdbc-type=\"INTEGER\"\n"+ 210 " primarykey=\"false\"\n"+ 211 " access=\"anonymous\"\n"+ 212 " >\n"+ 213 " </field-descriptor>\n"+ 214 "</class-descriptor>", 215 runOjbXDoclet(OJB_DEST_FILE)); 216 assertEqualsTorqueSchemaFile( 217 "<database name=\"ojbtest\">\n"+ 218 " <table name=\"A\">\n"+ 219 " <column name=\"attr\"\n"+ 220 " javaName=\"attr\"\n"+ 221 " type=\"INTEGER\"\n"+ 222 " primaryKey=\"true\"\n"+ 223 " required=\"true\"\n"+ 224 " />\n"+ 225 " </table>\n"+ 226 " <table name=\"B\">\n"+ 227 " <column name=\"attr\"\n"+ 228 " javaName=\"attr\"\n"+ 229 " type=\"INTEGER\"\n"+ 230 " />\n"+ 231 " </table>\n"+ 232 "</database>", 233 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 234 } 235 236 public void testPrimarykey5() 238 { 239 addClass( 240 "test.A", 241 "package test;\n"+ 242 "/** @ojb.class\n"+ 243 " * @ojb.reference name=\"b\"\n"+ 244 " * class-ref=\"test.B\"\n"+ 245 " * foreignkey=\"bid\"\n"+ 246 " */\n" + 247 "public class A {\n"+ 248 " /** @ojb.field */\n"+ 249 " private int bid;\n"+ 250 "}"); 251 addClass( 252 "test.B", 253 "package test;\n"+ 254 "/** @ojb.class */\n" + 255 "public class B {\n"+ 256 " /** @ojb.field primarykey=\"true\" */\n"+ 257 " private int id;\n"+ 258 "}"); 259 addClass( 260 "test.C", 261 "package test;\n"+ 262 "/** @ojb.class\n" + 263 " * @ojb.modify-inherited name=\"b\"\n"+ 264 " * primarykey=\"false\"\n"+ 265 " */\n"+ 266 "public class C extends A {}\n"); 267 268 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 269 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 270 } 271 272 public void testPrimarykey6() 274 { 275 addClass( 276 "test.A", 277 "package test;\n"+ 278 "/** @ojb.class */\n" + 279 "public class A {\n"+ 280 " /** @ojb.field */\n"+ 281 " private int attr;\n"+ 282 "}"); 283 addClass( 284 "test.B", 285 "package test;\n"+ 286 "/** @ojb.class\n" + 287 " * @ojb.modify-inherited name=\"attr\"\n"+ 288 " * primarykey=\"yes\"\n"+ 289 " */\n"+ 290 "public class B extends A {}\n"); 291 292 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 293 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 294 } 295 296 public void testPrimarykey7() 298 { 299 addClass( 300 "test.A", 301 "package test;\n"+ 302 "/** @ojb.class */\n" + 303 "public class A {\n"+ 304 " /** @ojb.field */\n"+ 305 " private int bid;\n"+ 306 " /** @ojb.reference foreignkey=\"bid\" */\n"+ 307 " private B b;\n"+ 308 "}"); 309 addClass( 310 "test.B", 311 "package test;\n"+ 312 "/** @ojb.class */\n" + 313 "public class B {\n"+ 314 " /** @ojb.field primarykey=\"true\" */\n"+ 315 " private int id;\n"+ 316 "}"); 317 addClass( 318 "test.C", 319 "package test;\n"+ 320 "/** @ojb.class\n" + 321 " * @ojb.modify-inherited name=\"id\"\n"+ 322 " * primarykey=\"false\"\n"+ 323 " */\n"+ 324 "public class C extends B {}\n"); 325 326 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 327 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 328 } 329 330 public void testPrimarykey8() 332 { 333 addClass( 334 "test.A", 335 "package test;\n"+ 336 "/** @ojb.class */\n"+ 337 "public class A {\n"+ 338 " /** @ojb.field */\n"+ 339 " private int attrKey1;\n"+ 340 " /** @ojb.field */\n"+ 341 " private String attrKey2;\n"+ 342 " /** @ojb.reference foreignkey=\"attrKey2,attrKey1\" */\n"+ 343 " private test.B attr;\n"+ 344 "}\n"); 345 addClass( 346 "test.B", 347 "package test;\n"+ 348 "/** @ojb.class generate-table-info=\"false\" */\n"+ 349 "public abstract class B {}\n"); 350 addClass( 351 "test.C", 352 "package test;\n"+ 353 "/** @ojb.class */\n"+ 354 "public class C extends B {\n"+ 355 " /** @ojb.field primarykey=\"true\" */\n"+ 356 " private String id1;\n"+ 357 " /** @ojb.field primarykey=\"true\" */\n"+ 358 " private int id2;\n"+ 359 "}\n"); 360 addClass( 361 "test.D", 362 "package test;\n"+ 363 "/** @ojb.class\n"+ 364 " * @ojb.modify-inherited name=\"id2\"\n"+ 365 " * primarykey=\"false\"\n"+ 366 " */\n"+ 367 "public class D extends C {}\n"); 368 369 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 370 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 371 } 372 373 public void testPrimarykey9() 375 { 376 addClass( 377 "test.A", 378 "package test;\n"+ 379 "/** @ojb.class */\n" + 380 "public class A {\n"+ 381 " /** @ojb.field primarykey=\"true\" */\n"+ 382 " private int id;\n"+ 383 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 384 " * foreignkey=\"aid\"\n"+ 385 " */\n"+ 386 " private java.util.Collection bs;\n"+ 387 "}"); 388 addClass( 389 "test.B", 390 "package test;\n"+ 391 "/** @ojb.class */\n" + 392 "public class B {\n"+ 393 " /** @ojb.field */\n"+ 394 " private int aid;\n"+ 395 "}"); 396 addClass( 397 "test.C", 398 "package test;\n"+ 399 "/** @ojb.class\n" + 400 " * @ojb.modify-inherited name=\"id\"\n"+ 401 " * primarykey=\"false\"\n"+ 402 " */\n"+ 403 "public class C extends A {}\n"); 404 405 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 406 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 407 } 408 409 public void testPrimarykey10() 411 { 412 addClass( 413 "test.A", 414 "package test;\n"+ 415 "/** @ojb.class */\n"+ 416 "public class A {\n"+ 417 " /** @ojb.field */\n"+ 418 " private int attrKey;\n"+ 419 " /** @ojb.reference foreignkey=\"attrKey\" */\n"+ 420 " private test.B attr;\n"+ 421 "}\n"); 422 addClass( 423 "test.B", 424 "package test;\n"+ 425 "/** @ojb.class */\n"+ 426 "public class B {\n"+ 427 " /** @ojb.field primarykey=\"true\" */\n"+ 428 " private int id;\n"+ 429 "}\n"); 430 addClass( 431 "test.C", 432 "package test;\n"+ 433 "/** @ojb.class\n"+ 434 " * @ojb.modify-inherited name=\"id\"\n"+ 435 " * primarykey=\"false\"\n"+ 436 " */\n"+ 437 "public class C extends B {}\n"); 438 439 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 440 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 441 } 442 443 public void testPrimarykey11() 445 { 446 addClass( 447 "test.A", 448 "package test;\n"+ 449 "/** @ojb.class */\n" + 450 "public class A {\n"+ 451 " /** @ojb.field primarykey=\"true\" */\n"+ 452 " private int id;\n"+ 453 " /** @ojb.field */\n"+ 454 " private String id2;\n"+ 455 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 456 " * foreignkey=\"aid\"\n"+ 457 " */\n"+ 458 " private java.util.List attr;\n"+ 459 "}"); 460 addClass( 461 "test.B", 462 "package test;\n"+ 463 "/** @ojb.class */\n"+ 464 "public class B {\n"+ 465 " /** @ojb.field */\n"+ 466 " private int aid;\n"+ 467 "}\n"); 468 addClass( 469 "test.C", 470 "package test;\n"+ 471 "/** @ojb.class\n"+ 472 " * @ojb.modify-inherited name=\"id\"\n"+ 473 " * primarykey=\"false\"\n"+ 474 " * @ojb.modify-inherited name=\"id2\"\n"+ 475 " * primarykey=\"true\"\n"+ 476 " */\n" + 477 "public class C extends A {}"); 478 479 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 480 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 481 } 482 483 public void testPrimarykey12() 485 { 486 addClass( 487 "test.A", 488 "package test;\n"+ 489 "/** @ojb.class */\n" + 490 "public class A {\n"+ 491 " /** @ojb.field primarykey=\"true\" */\n"+ 492 " private int id;\n"+ 493 " /** @ojb.collection foreignkey=\"AID\"\n"+ 494 " * indirection-table=\"A_B\"\n"+ 495 " */\n"+ 496 " private B[] bs;\n"+ 497 "}"); 498 addClass( 499 "test.B", 500 "package test;\n"+ 501 "/** @ojb.class */\n"+ 502 "public class B {\n"+ 503 " /** @ojb.field primarykey=\"true\" */\n"+ 504 " private int id;\n"+ 505 " /** @ojb.collection element-class-ref=\"test.A\"\n"+ 506 " * foreignkey=\"BID\"\n"+ 507 " * indirection-table=\"A_B\"\n"+ 508 " */\n"+ 509 " private java.util.List as;\n"+ 510 "}\n"); 511 addClass( 512 "test.C", 513 "package test;\n"+ 514 "/** @ojb.class\n"+ 515 " * @ojb.modify-inherited name=\"id\"\n"+ 516 " * primarykey=\"false\"\n"+ 517 " */\n"+ 518 "public class C extends B {}\n"); 519 520 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 521 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 522 } 523 } 524 | Popular Tags |