1 package xdoclet.modules.ojb.tests; 2 3 17 18 23 public class UpdateProcedureTagTests extends OjbTestBase 24 { 25 public UpdateProcedureTagTests(String name) 26 { 27 super(name); 28 } 29 30 public void testNoAttributes() 32 { 33 addClass( 34 "test.A", 35 "package test;\n"+ 36 "/** @ojb.class\n"+ 37 " * @ojb.update-procedure name=\"update-proc\"\n"+ 38 " */\n"+ 39 "public class A {}\n"); 40 41 assertEqualsOjbDescriptorFile( 42 "<class-descriptor\n"+ 43 " class=\"test.A\"\n"+ 44 " table=\"A\"\n"+ 45 ">\n"+ 46 " <update-procedure\n"+ 47 " name=\"update-proc\"" + 48 " >\n"+ 49 " </update-procedure>\n"+ 50 "</class-descriptor>", 51 runOjbXDoclet(OJB_DEST_FILE)); 52 assertEqualsTorqueSchemaFile( 53 "<database name=\"ojbtest\">\n"+ 54 " <table name=\"A\">\n"+ 55 " </table>\n"+ 56 "</database>", 57 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 58 } 59 60 public void testNoName() 62 { 63 addClass( 64 "test.A", 65 "package test;\n"+ 66 "/** @ojb.class\n"+ 67 " * @ojb.update-procedure\n"+ 68 " */\n"+ 69 "public class A {}\n"); 70 71 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 72 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 73 } 74 75 public void testValidFieldRef() 77 { 78 addClass( 79 "test.A", 80 "package test;\n"+ 81 "/** @ojb.class\n"+ 82 " * @ojb.update-procedure name=\"update-proc\"\n" + 83 " * return-field-ref=\"attr\"\n"+ 84 " */\n"+ 85 "public class A {\n"+ 86 " /** @ojb.field */\n"+ 87 " private int attr;\n"+ 88 "}\n"); 89 90 assertEqualsOjbDescriptorFile( 91 "<class-descriptor\n"+ 92 " class=\"test.A\"\n"+ 93 " table=\"A\"\n"+ 94 ">\n"+ 95 " <field-descriptor\n"+ 96 " name=\"attr\"\n"+ 97 " column=\"attr\"\n"+ 98 " jdbc-type=\"INTEGER\"\n"+ 99 " >\n"+ 100 " </field-descriptor>\n"+ 101 " <update-procedure\n"+ 102 " name=\"update-proc\"" + 103 " return-field-ref=\"attr\"" + 104 " >\n"+ 105 " </update-procedure>\n"+ 106 "</class-descriptor>", 107 runOjbXDoclet(OJB_DEST_FILE)); 108 assertEqualsTorqueSchemaFile( 109 "<database name=\"ojbtest\">\n"+ 110 " <table name=\"A\">\n"+ 111 " <column name=\"attr\"\n"+ 112 " javaName=\"attr\"\n"+ 113 " type=\"INTEGER\"\n"+ 114 " />\n"+ 115 " </table>\n"+ 116 "</database>", 117 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 118 } 119 120 public void testValidInheritedFieldRef() 122 { 123 addClass( 124 "test.A", 125 "package test;\n"+ 126 "/** @ojb.class */\n"+ 127 "public class A {\n"+ 128 " /** @ojb.field */\n"+ 129 " private int attr;\n"+ 130 "}\n"); 131 addClass( 132 "test.B", 133 "package test;\n"+ 134 "/** @ojb.class\n"+ 135 " * @ojb.update-procedure name=\"update-proc\"\n" + 136 " * return-field-ref=\"attr\"\n"+ 137 " */\n"+ 138 "public class B extends A {}\n"); 139 140 assertEqualsOjbDescriptorFile( 141 "<class-descriptor\n"+ 142 " class=\"test.A\"\n"+ 143 " table=\"A\"\n"+ 144 ">\n"+ 145 " <extent-class class-ref=\"test.B\"/>\n"+ 146 " <field-descriptor\n"+ 147 " name=\"attr\"\n"+ 148 " column=\"attr\"\n"+ 149 " jdbc-type=\"INTEGER\"\n"+ 150 " >\n"+ 151 " </field-descriptor>\n"+ 152 "</class-descriptor>\n"+ 153 "<class-descriptor\n"+ 154 " class=\"test.B\"\n"+ 155 " table=\"B\"\n"+ 156 ">\n"+ 157 " <field-descriptor\n"+ 158 " name=\"attr\"\n"+ 159 " column=\"attr\"\n"+ 160 " jdbc-type=\"INTEGER\"\n"+ 161 " >\n"+ 162 " </field-descriptor>\n"+ 163 " <update-procedure\n"+ 164 " name=\"update-proc\"\n" + 165 " return-field-ref=\"attr\"\n" + 166 " >\n"+ 167 " </update-procedure>\n"+ 168 "</class-descriptor>", 169 runOjbXDoclet(OJB_DEST_FILE)); 170 assertEqualsTorqueSchemaFile( 171 "<database name=\"ojbtest\">\n"+ 172 " <table name=\"A\">\n"+ 173 " <column name=\"attr\"\n"+ 174 " javaName=\"attr\"\n"+ 175 " type=\"INTEGER\"\n"+ 176 " />\n"+ 177 " </table>\n"+ 178 " <table name=\"B\">\n"+ 179 " <column name=\"attr\"\n"+ 180 " javaName=\"attr\"\n"+ 181 " type=\"INTEGER\"\n"+ 182 " />\n"+ 183 " </table>\n"+ 184 "</database>", 185 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 186 } 187 188 public void testValidNestedFieldRef() 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 attr;\n"+ 198 "}\n"); 199 addClass( 200 "test.B", 201 "package test;\n"+ 202 "/** @ojb.class\n"+ 203 " * @ojb.update-procedure name=\"update-proc\"\n" + 204 " * return-field-ref=\"attr::attr\"\n"+ 205 " */\n"+ 206 "public class B {\n"+ 207 " /** @ojb.nested */\n"+ 208 " private A attr;\n"+ 209 "}\n"); 210 211 assertEqualsOjbDescriptorFile( 212 "<class-descriptor\n"+ 213 " class=\"test.A\"\n"+ 214 " table=\"A\"\n"+ 215 ">\n"+ 216 " <field-descriptor\n"+ 217 " name=\"attr\"\n"+ 218 " column=\"attr\"\n"+ 219 " jdbc-type=\"INTEGER\"\n"+ 220 " >\n"+ 221 " </field-descriptor>\n"+ 222 "</class-descriptor>\n"+ 223 "<class-descriptor\n"+ 224 " class=\"test.B\"\n"+ 225 " table=\"B\"\n"+ 226 ">\n"+ 227 " <field-descriptor\n"+ 228 " name=\"attr::attr\"\n"+ 229 " column=\"attr_attr\"\n"+ 230 " jdbc-type=\"INTEGER\"\n"+ 231 " >\n"+ 232 " </field-descriptor>\n"+ 233 " <update-procedure\n"+ 234 " name=\"update-proc\"\n" + 235 " return-field-ref=\"attr::attr\"\n" + 236 " >\n"+ 237 " </update-procedure>\n"+ 238 "</class-descriptor>", 239 runOjbXDoclet(OJB_DEST_FILE)); 240 assertEqualsTorqueSchemaFile( 241 "<database name=\"ojbtest\">\n"+ 242 " <table name=\"A\">\n"+ 243 " <column name=\"attr\"\n"+ 244 " javaName=\"attr\"\n"+ 245 " type=\"INTEGER\"\n"+ 246 " />\n"+ 247 " </table>\n"+ 248 " <table name=\"B\">\n"+ 249 " <column name=\"attr_attr\"\n"+ 250 " type=\"INTEGER\"\n"+ 251 " />\n"+ 252 " </table>\n"+ 253 "</database>", 254 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 255 } 256 257 public void testUnknownFieldRef() 259 { 260 addClass( 261 "test.A", 262 "package test;\n"+ 263 "/** @ojb.class\n"+ 264 " * @ojb.update-procedure name=\"update-proc\"\n" + 265 " * return-field-ref=\"id\"\n"+ 266 " */\n"+ 267 "public class A {\n"+ 268 " /** @ojb.field */\n"+ 269 " private int attr;\n"+ 270 "}\n"); 271 272 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 273 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 274 } 275 276 public void testNonpersistentFieldRef() 278 { 279 addClass( 280 "test.A", 281 "package test;\n"+ 282 "/** @ojb.class\n"+ 283 " * @ojb.update-procedure name=\"update-proc\"\n" + 284 " * return-field-ref=\"attr\"\n"+ 285 " */\n"+ 286 "public class A {\n"+ 287 " private int attr;\n"+ 288 "}\n"); 289 290 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 291 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 292 } 293 294 public void testOneRuntimeArgument() 296 { 297 addClass( 298 "test.A", 299 "package test;\n"+ 300 "/** @ojb.class\n"+ 301 " * @ojb.update-procedure name=\"update-proc\"\n"+ 302 " * arguments=\"arg1\"\n"+ 303 " * @ojb.runtime-argument name=\"arg1\"\n"+ 304 " * field-ref=\"attr\"\n"+ 305 " */\n"+ 306 "public class A {\n"+ 307 " /** @ojb.field */\n"+ 308 " private int attr;\n"+ 309 "}\n"); 310 311 assertEqualsOjbDescriptorFile( 312 "<class-descriptor\n"+ 313 " class=\"test.A\"\n"+ 314 " table=\"A\"\n"+ 315 ">\n"+ 316 " <field-descriptor\n"+ 317 " name=\"attr\"\n"+ 318 " column=\"attr\"\n"+ 319 " jdbc-type=\"INTEGER\"\n"+ 320 " >\n"+ 321 " </field-descriptor>\n"+ 322 " <update-procedure\n"+ 323 " name=\"update-proc\""+ 324 " >\n"+ 325 " <runtime-argument\n"+ 326 " field-ref=\"attr\"\n"+ 327 " >\n"+ 328 " </runtime-argument>\n"+ 329 " </update-procedure>\n"+ 330 "</class-descriptor>", 331 runOjbXDoclet(OJB_DEST_FILE)); 332 assertEqualsTorqueSchemaFile( 333 "<database name=\"ojbtest\">\n"+ 334 " <table name=\"A\">\n"+ 335 " <column name=\"attr\"\n"+ 336 " javaName=\"attr\"\n"+ 337 " type=\"INTEGER\"\n"+ 338 " />\n"+ 339 " </table>\n"+ 340 "</database>", 341 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 342 } 343 344 public void testOneConstantArgument() 346 { 347 addClass( 348 "test.A", 349 "package test;\n"+ 350 "/** @ojb.class\n"+ 351 " * @ojb.update-procedure name=\"update-proc\"\n"+ 352 " * arguments=\"arg1\"\n"+ 353 " * @ojb.constant-argument name=\"arg1\"\n"+ 354 " * value=\"0\"\n"+ 355 " */\n"+ 356 "public class A {\n"+ 357 " /** @ojb.field */\n"+ 358 " private int attr;\n"+ 359 "}\n"); 360 361 assertEqualsOjbDescriptorFile( 362 "<class-descriptor\n"+ 363 " class=\"test.A\"\n"+ 364 " table=\"A\"\n"+ 365 ">\n"+ 366 " <field-descriptor\n"+ 367 " name=\"attr\"\n"+ 368 " column=\"attr\"\n"+ 369 " jdbc-type=\"INTEGER\"\n"+ 370 " >\n"+ 371 " </field-descriptor>\n"+ 372 " <update-procedure\n"+ 373 " name=\"update-proc\"\n"+ 374 " >\n"+ 375 " <constant-argument\n"+ 376 " value=\"0\"\n"+ 377 " >\n"+ 378 " </constant-argument>\n"+ 379 " </update-procedure>\n"+ 380 "</class-descriptor>", 381 runOjbXDoclet(OJB_DEST_FILE)); 382 assertEqualsTorqueSchemaFile( 383 "<database name=\"ojbtest\">\n"+ 384 " <table name=\"A\">\n"+ 385 " <column name=\"attr\"\n"+ 386 " javaName=\"attr\"\n"+ 387 " type=\"INTEGER\"\n"+ 388 " />\n"+ 389 " </table>\n"+ 390 "</database>", 391 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 392 } 393 394 public void testMultipleArguments() 396 { 397 addClass( 398 "test.A", 399 "package test;\n"+ 400 "/** @ojb.class\n"+ 401 " * @ojb.constant-argument name=\"arg2\"\n"+ 402 " * value=\"0\"\n"+ 403 " * @ojb.update-procedure name=\"update-proc\"\n"+ 404 " * arguments=\"arg3,arg1,arg2\"\n"+ 405 " * @ojb.runtime-argument name=\"arg1\"\n"+ 406 " * field-ref=\"attr\"\n"+ 407 " * @ojb.constant-argument name=\"arg3\"\n"+ 408 " * value=\"abc\"\n"+ 409 " */\n"+ 410 "public class A {\n"+ 411 " /** @ojb.field */\n"+ 412 " private int attr;\n"+ 413 "}\n"); 414 415 assertEqualsOjbDescriptorFile( 416 "<class-descriptor\n"+ 417 " class=\"test.A\"\n"+ 418 " table=\"A\"\n"+ 419 ">\n"+ 420 " <field-descriptor\n"+ 421 " name=\"attr\"\n"+ 422 " column=\"attr\"\n"+ 423 " jdbc-type=\"INTEGER\"\n"+ 424 " >\n"+ 425 " </field-descriptor>\n"+ 426 " <update-procedure\n"+ 427 " name=\"update-proc\"\n"+ 428 " >\n"+ 429 " <constant-argument\n"+ 430 " value=\"abc\"\n"+ 431 " >\n"+ 432 " </constant-argument>\n"+ 433 " <runtime-argument\n"+ 434 " field-ref=\"attr\"\n"+ 435 " >\n"+ 436 " </runtime-argument>\n"+ 437 " <constant-argument\n"+ 438 " value=\"0\"\n"+ 439 " >\n"+ 440 " </constant-argument>\n"+ 441 " </update-procedure>\n"+ 442 "</class-descriptor>", 443 runOjbXDoclet(OJB_DEST_FILE)); 444 assertEqualsTorqueSchemaFile( 445 "<database name=\"ojbtest\">\n"+ 446 " <table name=\"A\">\n"+ 447 " <column name=\"attr\"\n"+ 448 " javaName=\"attr\"\n"+ 449 " type=\"INTEGER\"\n"+ 450 " />\n"+ 451 " </table>\n"+ 452 "</database>", 453 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 454 } 455 456 public void testUndefinedArgument1() 458 { 459 addClass( 460 "test.A", 461 "package test;\n"+ 462 "/** @ojb.class\n"+ 463 " * @ojb.update-procedure name=\"update-proc\"\n"+ 464 " * arguments=\"arg1\"\n"+ 465 " */\n"+ 466 "public class A {}\n"); 467 468 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 469 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 470 } 471 472 public void testUndefinedArgument2() 474 { 475 addClass( 476 "test.A", 477 "package test;\n"+ 478 "/** @ojb.class\n"+ 479 " * @ojb.update-procedure name=\"update-proc\"\n"+ 480 " * arguments=\"arg3,arg1,arg2\"\n"+ 481 " * @ojb.runtime-argument name=\"arg1\"\n"+ 482 " * field-ref=\"attr\"\n"+ 483 " * @ojb.constant-argument name=\"arg3\"\n"+ 484 " * value=\"abc\"\n"+ 485 " */\n"+ 486 "public class A {\n"+ 487 " /** @ojb.field */\n"+ 488 " private int attr;\n"+ 489 "}\n"); 490 491 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 492 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 493 } 494 495 public void testIncludeAllFields1() 497 { 498 addClass( 499 "test.A", 500 "package test;\n"+ 501 "/** @ojb.class\n"+ 502 " * @ojb.update-procedure name=\"update-proc\"\n"+ 503 " * arguments=\"arg3,arg1,arg2\"\n"+ 504 " * include-all-fields=\"true\"\n"+ 505 " * @ojb.runtime-argument name=\"arg1\"\n"+ 506 " * field-ref=\"attr\"\n"+ 507 " * @ojb.constant-argument name=\"arg2\"\n"+ 508 " * value=\"0\"\n"+ 509 " * @ojb.constant-argument name=\"arg3\"\n"+ 510 " * value=\"abc\"\n"+ 511 " */\n"+ 512 "public class A {\n"+ 513 " /** @ojb.field */\n"+ 514 " private int attr;\n"+ 515 "}\n"); 516 517 assertEqualsOjbDescriptorFile( 518 "<class-descriptor\n"+ 519 " class=\"test.A\"\n"+ 520 " table=\"A\"\n"+ 521 ">\n"+ 522 " <field-descriptor\n"+ 523 " name=\"attr\"\n"+ 524 " column=\"attr\"\n"+ 525 " jdbc-type=\"INTEGER\"\n"+ 526 " >\n"+ 527 " </field-descriptor>\n"+ 528 " <update-procedure\n"+ 529 " name=\"update-proc\"\n"+ 530 " include-all-fields=\"true\"\n"+ 531 " >\n"+ 532 " </update-procedure>\n"+ 533 "</class-descriptor>", 534 runOjbXDoclet(OJB_DEST_FILE)); 535 assertEqualsTorqueSchemaFile( 536 "<database name=\"ojbtest\">\n"+ 537 " <table name=\"A\">\n"+ 538 " <column name=\"attr\"\n"+ 539 " javaName=\"attr\"\n"+ 540 " type=\"INTEGER\"\n"+ 541 " />\n"+ 542 " </table>\n"+ 543 "</database>", 544 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 545 } 546 547 public void testIncludeAllFields2() 549 { 550 addClass( 551 "test.A", 552 "package test;\n"+ 553 "/** @ojb.class\n"+ 554 " * @ojb.update-procedure name=\"update-proc\"\n"+ 555 " * arguments=\"arg3,arg1,arg2\"\n"+ 556 " * include-all-fields=\"no\"\n"+ 557 " * @ojb.runtime-argument name=\"arg1\"\n"+ 558 " * field-ref=\"attr\"\n"+ 559 " * @ojb.constant-argument name=\"arg2\"\n"+ 560 " * value=\"0\"\n"+ 561 " * @ojb.constant-argument name=\"arg3\"\n"+ 562 " * value=\"abc\"\n"+ 563 " */\n"+ 564 "public class A {\n"+ 565 " /** @ojb.field */\n"+ 566 " private int attr;\n"+ 567 "}\n"); 568 569 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 570 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 571 } 572 } 573 | Popular Tags |