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