1 package xdoclet.modules.ojb.tests; 2 3 17 18 23 public class ModifyNestedTagSimpleTests extends OjbTestBase 24 { 25 public ModifyNestedTagSimpleTests(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 "public class A {\n"+ 38 " /** @ojb.nested\n"+ 39 " * @ojb.modify-nested name=\"id\"\n"+ 40 " * column=\"ID\"\n"+ 41 " */\n"+ 42 " private B attr;\n"+ 43 "}\n"); 44 addClass( 45 "test.B", 46 "package test;\n"+ 47 "public class B {\n"+ 48 " /** @ojb.field */\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=\"attr::id\"\n"+ 59 " column=\"ID\"\n"+ 60 " jdbc-type=\"INTEGER\"\n"+ 61 " >\n"+ 62 " </field-descriptor>\n"+ 63 "</class-descriptor>", 64 runOjbXDoclet(OJB_DEST_FILE)); 65 assertEqualsTorqueSchemaFile( 66 "<database name=\"ojbtest\">\n"+ 67 " <table name=\"A\">\n"+ 68 " <column name=\"ID\"\n"+ 69 " type=\"INTEGER\"\n"+ 70 " />\n"+ 71 " </table>\n"+ 72 "</database>", 73 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 74 } 75 76 public void testSimple2() 78 { 79 addClass( 80 "test.A", 81 "package test;\n"+ 82 "/** @ojb.class */\n"+ 83 "public class A {\n"+ 84 " /** @ojb.nested\n"+ 85 " * @ojb.modify-nested name=\"cobj\"\n"+ 86 " * auto-delete=\"true\"\n"+ 87 " */\n"+ 88 " private B attr;\n"+ 89 "}\n"); 90 addClass( 91 "test.B", 92 "package test;\n"+ 93 "/** @ojb.class */\n"+ 94 "public class B {\n"+ 95 " /** @ojb.field */\n"+ 96 " private int cid;\n"+ 97 " /** @ojb.reference foreignkey=\"cid\" */\n"+ 98 " private C cobj;\n"+ 99 "}\n"); 100 addClass( 101 "test.C", 102 "package test;\n"+ 103 "/** @ojb.class */\n"+ 104 "public class C {\n"+ 105 " /** @ojb.field primarykey=\"true\" */\n"+ 106 " private int id;\n"+ 107 "}\n"); 108 109 assertEqualsOjbDescriptorFile( 110 "<class-descriptor\n"+ 111 " class=\"test.A\"\n"+ 112 " table=\"A\"\n"+ 113 ">\n"+ 114 " <field-descriptor\n"+ 115 " name=\"attr::cid\"\n"+ 116 " column=\"attr_cid\"\n"+ 117 " jdbc-type=\"INTEGER\"\n"+ 118 " >\n"+ 119 " </field-descriptor>\n"+ 120 " <reference-descriptor\n"+ 121 " name=\"attr::cobj\"\n"+ 122 " class-ref=\"test.C\"\n"+ 123 " auto-delete=\"true\"\n"+ 124 " >\n"+ 125 " <foreignkey field-ref=\"attr::cid\"/>\n"+ 126 " </reference-descriptor>\n"+ 127 "</class-descriptor>\n"+ 128 "<class-descriptor\n"+ 129 " class=\"test.B\"\n"+ 130 " table=\"B\"\n"+ 131 ">\n"+ 132 " <field-descriptor\n"+ 133 " name=\"cid\"\n"+ 134 " column=\"cid\"\n"+ 135 " jdbc-type=\"INTEGER\"\n"+ 136 " >\n"+ 137 " </field-descriptor>\n"+ 138 " <reference-descriptor\n"+ 139 " name=\"cobj\"\n"+ 140 " class-ref=\"test.C\"\n"+ 141 " >\n"+ 142 " <foreignkey field-ref=\"cid\"/>\n"+ 143 " </reference-descriptor>\n"+ 144 "</class-descriptor>\n"+ 145 "<class-descriptor\n"+ 146 " class=\"test.C\"\n"+ 147 " table=\"C\"\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=\"attr_cid\"\n"+ 162 " type=\"INTEGER\"\n"+ 163 " />\n"+ 164 " <foreign-key foreignTable=\"C\">\n"+ 165 " <reference local=\"attr_cid\" foreign=\"id\"/>\n"+ 166 " </foreign-key>\n"+ 167 " </table>\n"+ 168 " <table name=\"B\">\n"+ 169 " <column name=\"cid\"\n"+ 170 " javaName=\"cid\"\n"+ 171 " type=\"INTEGER\"\n"+ 172 " />\n"+ 173 " <foreign-key foreignTable=\"C\">\n"+ 174 " <reference local=\"cid\" foreign=\"id\"/>\n"+ 175 " </foreign-key>\n"+ 176 " </table>\n"+ 177 " <table name=\"C\">\n"+ 178 " <column name=\"id\"\n"+ 179 " javaName=\"id\"\n"+ 180 " type=\"INTEGER\"\n"+ 181 " primaryKey=\"true\"\n"+ 182 " required=\"true\"\n"+ 183 " />\n"+ 184 " </table>\n"+ 185 "</database>", 186 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 187 } 188 189 public void testSimple3() 191 { 192 addClass( 193 "test.A", 194 "package test;\n"+ 195 "/** @ojb.class */\n"+ 196 "public class A {\n"+ 197 " /** @ojb.nested\n"+ 198 " * @ojb.modify-nested name=\"cobjs\"\n"+ 199 " * collection-class=\"\"\n"+ 200 " */\n"+ 201 " private B attr;\n"+ 202 "}\n"); 203 addClass( 204 "test.B", 205 "package test;\n"+ 206 "/** @ojb.class */\n"+ 207 "public class B {\n"+ 208 " /** @ojb.field primarykey=\"true\" */\n"+ 209 " private int id;\n"+ 210 " /** @ojb.collection foreignkey=\"bid\"\n"+ 211 " * element-class-ref=\"test.C\"\n"+ 212 " * collection-class=\"org.apache.ojb.odmg.collections.DListImpl\"\n"+ 213 " * database-foreignkey=\"false\"\n"+ 214 " */\n"+ 215 " private java.util.List cobjs;\n"+ 216 "}\n"); 217 addClass( 218 "test.C", 219 "package test;\n"+ 220 "/** @ojb.class */\n"+ 221 "public class C {\n"+ 222 " /** @ojb.field */\n"+ 223 " private int bid;\n"+ 224 "}\n"); 225 226 assertEqualsOjbDescriptorFile( 227 "<class-descriptor\n"+ 228 " class=\"test.A\"\n"+ 229 " table=\"A\"\n"+ 230 ">\n"+ 231 " <field-descriptor\n"+ 232 " name=\"attr::id\"\n"+ 233 " column=\"attr_id\"\n"+ 234 " jdbc-type=\"INTEGER\"\n"+ 235 " primarykey=\"true\"\n"+ 236 " >\n"+ 237 " </field-descriptor>\n"+ 238 " <collection-descriptor\n"+ 239 " name=\"attr::cobjs\"\n"+ 240 " element-class-ref=\"test.C\"\n"+ 241 " >\n"+ 242 " <inverse-foreignkey field-ref=\"bid\"/>\n"+ 243 " </collection-descriptor>\n"+ 244 "</class-descriptor>\n"+ 245 "<class-descriptor\n"+ 246 " class=\"test.B\"\n"+ 247 " table=\"B\"\n"+ 248 ">\n"+ 249 " <field-descriptor\n"+ 250 " name=\"id\"\n"+ 251 " column=\"id\"\n"+ 252 " jdbc-type=\"INTEGER\"\n"+ 253 " primarykey=\"true\"\n"+ 254 " >\n"+ 255 " </field-descriptor>\n"+ 256 " <collection-descriptor\n"+ 257 " name=\"cobjs\"\n"+ 258 " collection-class=\"org.apache.ojb.odmg.collections.DListImpl\"\n"+ 259 " element-class-ref=\"test.C\"\n"+ 260 " >\n"+ 261 " <inverse-foreignkey field-ref=\"bid\"/>\n"+ 262 " </collection-descriptor>\n"+ 263 "</class-descriptor>\n"+ 264 "<class-descriptor\n"+ 265 " class=\"test.C\"\n"+ 266 " table=\"C\"\n"+ 267 ">\n"+ 268 " <field-descriptor\n"+ 269 " name=\"bid\"\n"+ 270 " column=\"bid\"\n"+ 271 " jdbc-type=\"INTEGER\"\n"+ 272 " >\n"+ 273 " </field-descriptor>\n"+ 274 "</class-descriptor>", 275 runOjbXDoclet(OJB_DEST_FILE)); 276 assertEqualsTorqueSchemaFile( 277 "<database name=\"ojbtest\">\n"+ 278 " <table name=\"A\">\n"+ 279 " <column name=\"attr_id\"\n"+ 280 " type=\"INTEGER\"\n"+ 281 " primaryKey=\"true\"\n"+ 282 " required=\"true\"\n"+ 283 " />\n"+ 284 " </table>\n"+ 285 " <table name=\"B\">\n"+ 286 " <column name=\"id\"\n"+ 287 " javaName=\"id\"\n"+ 288 " type=\"INTEGER\"\n"+ 289 " primaryKey=\"true\"\n"+ 290 " required=\"true\"\n"+ 291 " />\n"+ 292 " </table>\n"+ 293 " <table name=\"C\">\n"+ 294 " <column name=\"bid\"\n"+ 295 " javaName=\"bid\"\n"+ 296 " type=\"INTEGER\"\n"+ 297 " />\n"+ 298 " </table>\n"+ 299 "</database>", 300 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 301 } 302 303 public void testSimple4() 305 { 306 addClass( 307 "test.A", 308 "package test;\n"+ 309 "/** @ojb.class */\n"+ 310 "public class A {\n"+ 311 " /** @ojb.nested\n"+ 312 " * @ojb.modify-nested name=\"attr::id\"\n"+ 313 " * jdbc-type=\"BIT\"\n"+ 314 " */\n"+ 315 " private B attr;\n"+ 316 "}\n"); 317 addClass( 318 "test.B", 319 "package test;\n"+ 320 "/** @ojb.class */\n"+ 321 "public class B {\n"+ 322 " /** @ojb.nested\n"+ 323 " * @ojb.modify-nested name=\"id\"\n"+ 324 " * jdbc-type=\"FLOAT\"\n"+ 325 " */\n"+ 326 " private C attr;\n"+ 327 "}\n"); 328 addClass( 329 "test.C", 330 "package test;\n"+ 331 "/** @ojb.class */\n"+ 332 "public class C {\n"+ 333 " /** @ojb.field */\n"+ 334 " private int id;\n"+ 335 "}\n"); 336 337 assertEqualsOjbDescriptorFile( 338 "<class-descriptor\n"+ 339 " class=\"test.A\"\n"+ 340 " table=\"A\"\n"+ 341 ">\n"+ 342 " <field-descriptor\n"+ 343 " name=\"attr::attr::id\"\n"+ 344 " column=\"attr_attr_id\"\n"+ 345 " jdbc-type=\"BIT\"\n"+ 346 " >\n"+ 347 " </field-descriptor>\n"+ 348 "</class-descriptor>\n"+ 349 "<class-descriptor\n"+ 350 " class=\"test.B\"\n"+ 351 " table=\"B\"\n"+ 352 ">\n"+ 353 " <field-descriptor\n"+ 354 " name=\"attr::id\"\n"+ 355 " column=\"attr_id\"\n"+ 356 " jdbc-type=\"FLOAT\"\n"+ 357 " >\n"+ 358 " </field-descriptor>\n"+ 359 "</class-descriptor>\n"+ 360 "<class-descriptor\n"+ 361 " class=\"test.C\"\n"+ 362 " table=\"C\"\n"+ 363 ">\n"+ 364 " <field-descriptor\n"+ 365 " name=\"id\"\n"+ 366 " column=\"id\"\n"+ 367 " jdbc-type=\"INTEGER\"\n"+ 368 " >\n"+ 369 " </field-descriptor>\n"+ 370 "</class-descriptor>", 371 runOjbXDoclet(OJB_DEST_FILE)); 372 assertEqualsTorqueSchemaFile( 373 "<database name=\"ojbtest\">\n"+ 374 " <table name=\"A\">\n"+ 375 " <column name=\"attr_attr_id\"\n"+ 376 " type=\"BIT\"\n"+ 377 " />\n"+ 378 " </table>\n"+ 379 " <table name=\"B\">\n"+ 380 " <column name=\"attr_id\"\n"+ 381 " type=\"FLOAT\"\n"+ 382 " />\n"+ 383 " </table>\n"+ 384 " <table name=\"C\">\n"+ 385 " <column name=\"id\"\n"+ 386 " javaName=\"id\"\n"+ 387 " type=\"INTEGER\"\n"+ 388 " />\n"+ 389 " </table>\n"+ 390 "</database>", 391 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 392 } 393 394 public void testSimple5() 396 { 397 addClass( 398 "test.A", 399 "package test;\n"+ 400 "/** @ojb.class */\n"+ 401 "public class A {\n"+ 402 " /** @ojb.nested\n"+ 403 " * @ojb.modify-nested name=\"id\"\n"+ 404 " * column=\"ID\"\n"+ 405 " * @ojb.modify-nested name=\"name\"\n"+ 406 " * column=\"NAME\"\n"+ 407 " */\n"+ 408 " private B attr;\n"+ 409 "}\n"); 410 addClass( 411 "test.B", 412 "package test;\n"+ 413 "public class B {\n"+ 414 " /** @ojb.field */\n"+ 415 " private int id;\n"+ 416 " /** @ojb.field length=\"24\" */\n"+ 417 " private String name;\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=\"attr::id\"\n"+ 427 " column=\"ID\"\n"+ 428 " jdbc-type=\"INTEGER\"\n"+ 429 " >\n"+ 430 " </field-descriptor>\n"+ 431 " <field-descriptor\n"+ 432 " name=\"attr::name\"\n"+ 433 " column=\"NAME\"\n"+ 434 " jdbc-type=\"VARCHAR\"\n"+ 435 " length=\"24\"\n"+ 436 " >\n"+ 437 " </field-descriptor>\n"+ 438 "</class-descriptor>", 439 runOjbXDoclet(OJB_DEST_FILE)); 440 assertEqualsTorqueSchemaFile( 441 "<database name=\"ojbtest\">\n"+ 442 " <table name=\"A\">\n"+ 443 " <column name=\"ID\"\n"+ 444 " type=\"INTEGER\"\n"+ 445 " />\n"+ 446 " <column name=\"NAME\"\n"+ 447 " type=\"VARCHAR\"\n"+ 448 " size=\"24\"\n"+ 449 " />\n"+ 450 " </table>\n"+ 451 "</database>", 452 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 453 } 454 } 455 | Popular Tags |