1 package xdoclet.modules.ojb.tests; 2 3 17 18 24 public class FieldTagPrimarykeyAttributeTests extends OjbTestBase 25 { 26 public FieldTagPrimarykeyAttributeTests(String name) 27 { 28 super(name); 29 } 30 31 public void testPrimarykey1() 33 { 34 addClass( 35 "test.A", 36 "package test;\n"+ 37 "/** @ojb.class */\n"+ 38 "public class A {\n"+ 39 "/** @ojb.field primarykey=\"\" */\n"+ 40 " private int attr;\n"+ 41 "}\n"); 42 43 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 44 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 45 } 46 47 public void testPrimarykey2() 49 { 50 addClass( 51 "test.A", 52 "package test;\n"+ 53 "/** @ojb.class */\n"+ 54 "public class A {\n"+ 55 "/** @ojb.field primarykey=\"yes\" */\n"+ 56 " private int attr;\n"+ 57 "}\n"); 58 59 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 60 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 61 } 62 63 public void testPrimarykey3() 65 { 66 addClass( 67 "test.A", 68 "package test;\n"+ 69 "/** @ojb.class */\n"+ 70 "public class A {\n"+ 71 "/** @ojb.field primarykey=\"true\"\n"+ 72 " */\n"+ 73 " private int attr;\n"+ 74 "}\n"); 75 76 assertEqualsOjbDescriptorFile( 77 "<class-descriptor\n"+ 78 " class=\"test.A\"\n"+ 79 " table=\"A\"\n"+ 80 ">\n"+ 81 " <field-descriptor\n"+ 82 " name=\"attr\"\n"+ 83 " column=\"attr\"\n"+ 84 " jdbc-type=\"INTEGER\"\n"+ 85 " primarykey=\"true\"\n"+ 86 " >\n"+ 87 " </field-descriptor>\n"+ 88 "</class-descriptor>", 89 runOjbXDoclet(OJB_DEST_FILE)); 90 assertEqualsTorqueSchemaFile( 91 "<database name=\"ojbtest\">\n"+ 92 " <table name=\"A\">\n"+ 93 " <column name=\"attr\"\n"+ 94 " javaName=\"attr\"\n"+ 95 " type=\"INTEGER\"\n"+ 96 " primaryKey=\"true\"\n"+ 97 " required=\"true\"\n"+ 98 " />\n"+ 99 " </table>\n"+ 100 "</database>", 101 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 102 } 103 104 public void testPrimarykey4() 106 { 107 addClass( 108 "test.A", 109 "package test;\n"+ 110 "/** @ojb.class */\n"+ 111 "public class A {\n"+ 112 "/** @ojb.field primarykey=\"false\" */\n"+ 113 " private int attr;\n"+ 114 "}\n"); 115 116 assertEqualsOjbDescriptorFile( 117 "<class-descriptor\n"+ 118 " class=\"test.A\"\n"+ 119 " table=\"A\"\n"+ 120 ">\n"+ 121 " <field-descriptor\n"+ 122 " name=\"attr\"\n"+ 123 " column=\"attr\"\n"+ 124 " jdbc-type=\"INTEGER\"\n"+ 125 " primarykey=\"false\"\n"+ 126 " >\n"+ 127 " </field-descriptor>\n"+ 128 "</class-descriptor>", 129 runOjbXDoclet(OJB_DEST_FILE)); 130 assertEqualsTorqueSchemaFile( 131 "<database name=\"ojbtest\">\n"+ 132 " <table name=\"A\">\n"+ 133 " <column name=\"attr\"\n"+ 134 " javaName=\"attr\"\n"+ 135 " type=\"INTEGER\"\n"+ 136 " />\n"+ 137 " </table>\n"+ 138 "</database>", 139 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 140 } 141 142 public void testPrimarykey5() 144 { 145 addClass( 146 "test.A", 147 "package test;\n"+ 148 "/** @ojb.class */\n"+ 149 "public class A {\n"+ 150 "/** @ojb.field primarykey=\"true\" */\n"+ 151 " private int attr;\n"+ 152 "}\n"); 153 addClass( 154 "test.B", 155 "package test;\n"+ 156 "public class B extends A {}\n"); 157 addClass( 158 "test.C", 159 "package test;\n"+ 160 "/** @ojb.class */\n"+ 161 "public class C extends B {}\n"); 162 163 assertEqualsOjbDescriptorFile( 164 "<class-descriptor\n"+ 165 " class=\"test.A\"\n"+ 166 " table=\"A\"\n"+ 167 ">\n"+ 168 " <extent-class class-ref=\"test.C\"/>\n"+ 169 " <field-descriptor\n"+ 170 " name=\"attr\"\n"+ 171 " column=\"attr\"\n"+ 172 " jdbc-type=\"INTEGER\"\n"+ 173 " primarykey=\"true\"\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=\"attr\"\n"+ 183 " column=\"attr\"\n"+ 184 " jdbc-type=\"INTEGER\"\n"+ 185 " primarykey=\"true\"\n"+ 186 " >\n"+ 187 " </field-descriptor>\n"+ 188 "</class-descriptor>", 189 runOjbXDoclet(OJB_DEST_FILE)); 190 assertEqualsTorqueSchemaFile( 191 "<database name=\"ojbtest\">\n"+ 192 " <table name=\"A\">\n"+ 193 " <column name=\"attr\"\n"+ 194 " javaName=\"attr\"\n"+ 195 " type=\"INTEGER\"\n"+ 196 " primaryKey=\"true\"\n"+ 197 " required=\"true\"\n"+ 198 " />\n"+ 199 " </table>\n"+ 200 " <table name=\"C\">\n"+ 201 " <column name=\"attr\"\n"+ 202 " javaName=\"attr\"\n"+ 203 " type=\"INTEGER\"\n"+ 204 " primaryKey=\"true\"\n"+ 205 " required=\"true\"\n"+ 206 " />\n"+ 207 " </table>\n"+ 208 "</database>", 209 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 210 } 211 } 212 | Popular Tags |