01: package net.sourceforge.jaxor.tests;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.jaxor.EntityChange;
05: import net.sourceforge.jaxor.example.domain.AddressBase;
06: import net.sourceforge.jaxor.example.domain.AddressImpl;
07: import net.sourceforge.jaxor.example.domain.AddressMetaRow;
08:
09: import java.util.Iterator;
10: import java.util.SortedSet;
11: import java.util.TreeSet;
12:
13: /*
14: * User: Mike
15: * Date: Jan 9, 2003
16: * Time: 8:22:03 PM
17: */
18:
19: public class EntityChangeTest extends TestCase {
20:
21: public void testEquality() {
22: AddressBase impl = createAddress(new Long(1));
23: AddressBase two = createAddress(new Long(1));
24: assertEquals(EntityChange.insert(1, impl), EntityChange.insert(
25: 2, two));
26: }
27:
28: public void testSorting() {
29: SortedSet set = new TreeSet();
30: AddressBase impl = createAddress(new Long(1));
31: AddressBase two = createAddress(new Long(2));
32: EntityChange change = EntityChange.insert(1, impl);
33: set.add(change);
34: EntityChange change2 = EntityChange.insert(2, two);
35: set.add(change2);
36: Iterator iter = set.iterator();
37: assertEquals(change, iter.next());
38: assertEquals(change2, iter.next());
39: }
40:
41: private AddressImpl createAddress(Long id) {
42: AddressImpl impl = new AddressImpl(id);
43: impl.setMetaRow(new AddressMetaRow());
44: return impl;
45: }
46:
47: public void testSortingReverse() {
48: SortedSet set = new TreeSet();
49: AddressBase impl = createAddress(new Long(1));
50: AddressBase two = createAddress(new Long(2));
51: EntityChange change = EntityChange.insert(2, impl);
52: set.add(change);
53: EntityChange change2 = EntityChange.insert(1, two);
54: set.add(change2);
55: Iterator iter = set.iterator();
56: assertEquals(change2, iter.next());
57: assertEquals(change, iter.next());
58: }
59:
60: }
|