01: package net.sourceforge.jaxor.example.tests;
02:
03: import net.sourceforge.jaxor.MetaRow;
04: import net.sourceforge.jaxor.SQLValidationException;
05: import net.sourceforge.jaxor.SqlAdapter;
06: import net.sourceforge.jaxor.example.simple.AutoBase;
07: import net.sourceforge.jaxor.example.simple.AutoEntity;
08: import net.sourceforge.jaxor.example.simple.AutoFinder;
09: import net.sourceforge.jaxor.example.simple.AutoMetaRow;
10: import net.sourceforge.jaxor.example.simple.AutoList;
11: import net.sourceforge.jaxor.example.db.MySqlContextTestingFactory;
12:
13: /*
14: * User: Mike
15: * Date: Dec 12, 2002
16: * Time: 10:51:31 PM
17: */
18:
19: public class AutoAssignTest extends TableTestCase {
20:
21: protected MetaRow getRow() {
22: return new AutoMetaRow();
23: }
24:
25: public void testInserting() {
26: if (getTestingContext().hasAutoIncrementColumns()) {
27: AutoEntity ent = AutoFinder.newInstance();
28: ent.setField("myField");
29: commit();
30: AutoList list = AutoFinder.selectAll();
31: assertEquals(1, list.size());
32: ent = list.get(0);
33: assertNotNull(ent.getKey());
34: assertEquals("myField", ent.getField());
35: }
36: }
37:
38: public void testEquality() {
39: AutoEntity ent = AutoFinder.newInstance();
40: ent.setField("myField");
41: assertEquals(ent, ent);
42: AutoEntity two = AutoFinder.newInstance();
43: two.setField("myField");
44: assertTrue(two.equals(ent));
45: }
46:
47: public void testKeyIsNotPartOfInsertStatement() {
48: String key = new AutoMetaRow().getKey().getColumn();
49: AutoBase entity = new AutoBase();
50: entity.setMetaRow(new AutoMetaRow());
51: SqlAdapter adapter = new SqlAdapter(entity);
52: assertEquals(-1, adapter.insertSQL().indexOf(key));
53: }
54: }
|