01: /*
02: * User: mrettig
03: * Date: Jun 25, 2002
04: * Time: 1:52:22 PM
05: */
06: package net.sourceforge.jaxor.tests;
07:
08: import junit.framework.TestCase;
09: import net.sourceforge.jaxor.EntityRow;
10: import net.sourceforge.jaxor.MetaField;
11: import net.sourceforge.jaxor.mappers.FieldAdapterImpl;
12: import net.sourceforge.jaxor.mappers.BooleanMapper;
13:
14: public class EntityRowTest extends TestCase {
15:
16: public void testToString() {
17: EntityRow row = new EntityRow("table");
18: assertEquals("table", row.toString());
19: row.setFields(createField());
20: assertEquals("table\nname = null", row.toString());
21: }
22:
23: public void testEquals() {
24: EntityRow row = new EntityRow("table");
25: row.setFields(createField());
26: EntityRow row2 = new EntityRow("table");
27: row2.setFields(createField());
28: assertEquals(row, row2);
29: }
30:
31: public void testNotEquals() {
32: EntityRow row = new EntityRow("table");
33: FieldAdapterImpl[] field1 = createField();
34: row.setFields(field1);
35: EntityRow row2 = new EntityRow("table2");
36: FieldAdapterImpl[] field2 = createField();
37: row2.setFields(field2);
38: assertTrue(!row.equals(row2));
39: }
40:
41: public void testNotEqualsOnFieldValue() {
42: EntityRow row = new EntityRow("table");
43: FieldAdapterImpl[] field1 = createField();
44: field1[0].setValue(Boolean.FALSE);
45: row.setFields(field1);
46: EntityRow row2 = new EntityRow("table");
47: FieldAdapterImpl[] field2 = createField();
48: field2[0].setValue(Boolean.TRUE);
49: row2.setFields(field2);
50: assertTrue(!row.equals(row2));
51: }
52:
53: public void testGetValues() {
54: EntityRow row = new EntityRow("table");
55: FieldAdapterImpl[] field1 = createField();
56: field1[0].setValue(Boolean.FALSE);
57: row.setFields(field1);
58: FieldAdapterImpl[] field2 = createField();
59: field2[0].setValue(Boolean.TRUE);
60: row.setFields(field2);
61: Object[] values = row.getAllValues();
62: assertEquals(1, values.length);
63: assertEquals(values[0], Boolean.TRUE);
64: }
65:
66: private FieldAdapterImpl[] createField() {
67: return new FieldAdapterImpl[] { new FieldAdapterImpl(
68: new MetaField("name", true, BooleanMapper.class), null) };
69: }
70: }
|