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