1 package xdoclet.modules.ojb.tests; 2 3 17 18 23 public class CollectionTagRefreshAttributeTests extends OjbTestBase 24 { 25 public CollectionTagRefreshAttributeTests(String name) 26 { 27 super(name); 28 } 29 30 public void testRefresh1() 32 { 33 addClass( 34 "test.A", 35 "package test;\n"+ 36 "/** @ojb.class */\n"+ 37 "public class A {\n"+ 38 "/** @ojb.field primarykey=\"true\" */\n"+ 39 " private int id;\n"+ 40 "/** @ojb.collection element-class-ref=\"test.B\"\n"+ 41 " * foreignkey=\"aid\"\n"+ 42 " * refresh=\"\"\n"+ 43 " */\n"+ 44 " private java.util.List objs;\n"+ 45 "}\n"); 46 addClass( 47 "test.B", 48 "package test;\n"+ 49 "/** @ojb.class */\n"+ 50 "public class B {\n"+ 51 "/** @ojb.field */\n"+ 52 " private int aid;\n"+ 53 "}\n"); 54 55 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 56 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 57 } 58 59 public void testRefresh2() 61 { 62 addClass( 63 "test.A", 64 "package test;\n"+ 65 "/** @ojb.class */\n"+ 66 "public class A {\n"+ 67 "/** @ojb.field primarykey=\"true\" */\n"+ 68 " private int id;\n"+ 69 "/** @ojb.collection element-class-ref=\"test.B\"\n"+ 70 " * foreignkey=\"aid\"\n"+ 71 " * refresh=\"no\"\n"+ 72 " */\n"+ 73 " private java.util.List objs;\n"+ 74 "}\n"); 75 addClass( 76 "test.B", 77 "package test;\n"+ 78 "/** @ojb.class */\n"+ 79 "public class B {\n"+ 80 "/** @ojb.field */\n"+ 81 " private int aid;\n"+ 82 "}\n"); 83 84 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 85 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 86 } 87 88 public void testRefresh3() 90 { 91 addClass( 92 "test.A", 93 "package test;\n"+ 94 "/** @ojb.class */\n"+ 95 "public class A {\n"+ 96 "/** @ojb.field primarykey=\"true\" */\n"+ 97 " private int id;\n"+ 98 "/** @ojb.collection element-class-ref=\"test.B\"\n"+ 99 " * foreignkey=\"aid\"\n"+ 100 " * refresh=\"true\"\n"+ 101 " */\n"+ 102 " private java.util.List objs;\n"+ 103 "}\n"); 104 addClass( 105 "test.B", 106 "package test;\n"+ 107 "/** @ojb.class */\n"+ 108 "public class B {\n"+ 109 "/** @ojb.field */\n"+ 110 " private int aid;\n"+ 111 "}\n"); 112 113 assertEqualsOjbDescriptorFile( 114 "<class-descriptor\n"+ 115 " class=\"test.A\"\n"+ 116 " table=\"A\"\n"+ 117 ">\n"+ 118 " <field-descriptor\n"+ 119 " name=\"id\"\n"+ 120 " column=\"id\"\n"+ 121 " jdbc-type=\"INTEGER\"\n"+ 122 " primarykey=\"true\"\n"+ 123 " >\n"+ 124 " </field-descriptor>\n"+ 125 " <collection-descriptor\n"+ 126 " name=\"objs\"\n"+ 127 " element-class-ref=\"test.B\"\n"+ 128 " refresh=\"true\"\n"+ 129 " >\n"+ 130 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 131 " </collection-descriptor>\n"+ 132 "</class-descriptor>\n"+ 133 "<class-descriptor\n"+ 134 " class=\"test.B\"\n"+ 135 " table=\"B\"\n"+ 136 ">\n"+ 137 " <field-descriptor\n"+ 138 " name=\"aid\"\n"+ 139 " column=\"aid\"\n"+ 140 " jdbc-type=\"INTEGER\"\n"+ 141 " >\n"+ 142 " </field-descriptor>\n"+ 143 "</class-descriptor>", 144 runOjbXDoclet(OJB_DEST_FILE)); 145 assertEqualsTorqueSchemaFile( 146 "<database name=\"ojbtest\">\n"+ 147 " <table name=\"A\">\n"+ 148 " <column name=\"id\"\n"+ 149 " javaName=\"id\"\n"+ 150 " type=\"INTEGER\"\n"+ 151 " primaryKey=\"true\"\n"+ 152 " required=\"true\"\n"+ 153 " />\n"+ 154 " </table>\n"+ 155 " <table name=\"B\">\n"+ 156 " <column name=\"aid\"\n"+ 157 " javaName=\"aid\"\n"+ 158 " type=\"INTEGER\"\n"+ 159 " />\n"+ 160 " <foreign-key foreignTable=\"A\">\n"+ 161 " <reference local=\"aid\" foreign=\"id\"/>\n"+ 162 " </foreign-key>\n"+ 163 " </table>\n"+ 164 "</database>", 165 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 166 } 167 168 public void testRefresh4() 170 { 171 addClass( 172 "test.A", 173 "package test;\n"+ 174 "/** @ojb.class */\n"+ 175 "public class A {\n"+ 176 "/** @ojb.field primarykey=\"true\" */\n"+ 177 " private int id;\n"+ 178 "/** @ojb.collection element-class-ref=\"test.B\"\n"+ 179 " * foreignkey=\"aid\"\n"+ 180 " * refresh=\"false\"\n"+ 181 " */\n"+ 182 " private java.util.List objs;\n"+ 183 "}\n"); 184 addClass( 185 "test.B", 186 "package test;\n"+ 187 "/** @ojb.class */\n"+ 188 "public class B {\n"+ 189 "/** @ojb.field */\n"+ 190 " private int aid;\n"+ 191 "}\n"); 192 193 assertEqualsOjbDescriptorFile( 194 "<class-descriptor\n"+ 195 " class=\"test.A\"\n"+ 196 " table=\"A\"\n"+ 197 ">\n"+ 198 " <field-descriptor\n"+ 199 " name=\"id\"\n"+ 200 " column=\"id\"\n"+ 201 " jdbc-type=\"INTEGER\"\n"+ 202 " primarykey=\"true\"\n"+ 203 " >\n"+ 204 " </field-descriptor>\n"+ 205 " <collection-descriptor\n"+ 206 " name=\"objs\"\n"+ 207 " element-class-ref=\"test.B\"\n"+ 208 " refresh=\"false\"\n"+ 209 " >\n"+ 210 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 211 " </collection-descriptor>\n"+ 212 "</class-descriptor>\n"+ 213 "<class-descriptor\n"+ 214 " class=\"test.B\"\n"+ 215 " table=\"B\"\n"+ 216 ">\n"+ 217 " <field-descriptor\n"+ 218 " name=\"aid\"\n"+ 219 " column=\"aid\"\n"+ 220 " jdbc-type=\"INTEGER\"\n"+ 221 " >\n"+ 222 " </field-descriptor>\n"+ 223 "</class-descriptor>", 224 runOjbXDoclet(OJB_DEST_FILE)); 225 assertEqualsTorqueSchemaFile( 226 "<database name=\"ojbtest\">\n"+ 227 " <table name=\"A\">\n"+ 228 " <column name=\"id\"\n"+ 229 " javaName=\"id\"\n"+ 230 " type=\"INTEGER\"\n"+ 231 " primaryKey=\"true\"\n"+ 232 " required=\"true\"\n"+ 233 " />\n"+ 234 " </table>\n"+ 235 " <table name=\"B\">\n"+ 236 " <column name=\"aid\"\n"+ 237 " javaName=\"aid\"\n"+ 238 " type=\"INTEGER\"\n"+ 239 " />\n"+ 240 " <foreign-key foreignTable=\"A\">\n"+ 241 " <reference local=\"aid\" foreign=\"id\"/>\n"+ 242 " </foreign-key>\n"+ 243 " </table>\n"+ 244 "</database>", 245 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 246 } 247 248 public void testRefresh5() 250 { 251 addClass( 252 "test.A", 253 "package test;\n"+ 254 "/** @ojb.class */\n"+ 255 "public class A {\n"+ 256 "/** @ojb.field primarykey=\"true\" */\n"+ 257 " private int id;\n"+ 258 "/** @ojb.collection element-class-ref=\"test.B\"\n"+ 259 " * foreignkey=\"aid\"\n"+ 260 " * database-foreignkey=\"false\"\n"+ 261 " * refresh=\"true\"\n"+ 262 " */\n"+ 263 " private java.util.List objs;\n"+ 264 "}\n"); 265 addClass( 266 "test.B", 267 "package test;\n"+ 268 "/** @ojb.class */\n"+ 269 "public class B {\n"+ 270 "/** @ojb.field */\n"+ 271 " private int aid;\n"+ 272 "}\n"); 273 addClass( 274 "test.C", 275 "package test;\n"+ 276 "/** @ojb.class */\n"+ 277 "public class C extends A {}\n"); 278 279 assertEqualsOjbDescriptorFile( 280 "<class-descriptor\n"+ 281 " class=\"test.A\"\n"+ 282 " table=\"A\"\n"+ 283 ">\n"+ 284 " <extent-class class-ref=\"test.C\"/>\n"+ 285 " <field-descriptor\n"+ 286 " name=\"id\"\n"+ 287 " column=\"id\"\n"+ 288 " jdbc-type=\"INTEGER\"\n"+ 289 " primarykey=\"true\"\n"+ 290 " >\n"+ 291 " </field-descriptor>\n"+ 292 " <collection-descriptor\n"+ 293 " name=\"objs\"\n"+ 294 " element-class-ref=\"test.B\"\n"+ 295 " refresh=\"true\"\n"+ 296 " >\n"+ 297 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 298 " </collection-descriptor>\n"+ 299 "</class-descriptor>\n"+ 300 "<class-descriptor\n"+ 301 " class=\"test.B\"\n"+ 302 " table=\"B\"\n"+ 303 ">\n"+ 304 " <field-descriptor\n"+ 305 " name=\"aid\"\n"+ 306 " column=\"aid\"\n"+ 307 " jdbc-type=\"INTEGER\"\n"+ 308 " >\n"+ 309 " </field-descriptor>\n"+ 310 "</class-descriptor>\n"+ 311 "<class-descriptor\n"+ 312 " class=\"test.C\"\n"+ 313 " table=\"C\"\n"+ 314 ">\n"+ 315 " <field-descriptor\n"+ 316 " name=\"id\"\n"+ 317 " column=\"id\"\n"+ 318 " jdbc-type=\"INTEGER\"\n"+ 319 " primarykey=\"true\"\n"+ 320 " >\n"+ 321 " </field-descriptor>\n"+ 322 " <collection-descriptor\n"+ 323 " name=\"objs\"\n"+ 324 " element-class-ref=\"test.B\"\n"+ 325 " refresh=\"true\"\n"+ 326 " >\n"+ 327 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 328 " </collection-descriptor>\n"+ 329 "</class-descriptor>", 330 runOjbXDoclet(OJB_DEST_FILE)); 331 assertEqualsTorqueSchemaFile( 332 "<database name=\"ojbtest\">\n"+ 333 " <table name=\"A\">\n"+ 334 " <column name=\"id\"\n"+ 335 " javaName=\"id\"\n"+ 336 " type=\"INTEGER\"\n"+ 337 " primaryKey=\"true\"\n"+ 338 " required=\"true\"\n"+ 339 " />\n"+ 340 " </table>\n"+ 341 " <table name=\"B\">\n"+ 342 " <column name=\"aid\"\n"+ 343 " javaName=\"aid\"\n"+ 344 " type=\"INTEGER\"\n"+ 345 " />\n"+ 346 " </table>\n"+ 347 " <table name=\"C\">\n"+ 348 " <column name=\"id\"\n"+ 349 " javaName=\"id\"\n"+ 350 " type=\"INTEGER\"\n"+ 351 " primaryKey=\"true\"\n"+ 352 " required=\"true\"\n"+ 353 " />\n"+ 354 " </table>\n"+ 355 "</database>", 356 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 357 } 358 } 359 | Popular Tags |