/
TestEAV.java
117 lines (89 loc) · 3.18 KB
/
TestEAV.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package dk.netarkivet.harvester.datamodel.eav;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import com.antiaction.raptor.dao.AttributeBase;
import com.antiaction.raptor.dao.AttributeTypeBase;
import dk.netarkivet.harvester.datamodel.eav.EAV.AttributeAndType;
public class TestEAV {
@Test
public void testEAV() {
AttributeAndType aat;
AttributeTypeBase at;
AttributeBase a;
List<AttributeAndType> antList1 = new ArrayList<AttributeAndType>();
List<AttributeAndType> antList2 = new ArrayList<AttributeAndType>();
Assert.assertEquals(0, EAV.compare(antList1, antList2));
at = new ContentAttrType_Generic();
at.tree_id = 1;
at.id = 1;
at.datatype = 1;
aat = new AttributeAndType(at, new ContentAttribute_Generic(at));
aat.attribute.setInteger(1);
antList2.add(aat);
Assert.assertEquals(1, EAV.compare(antList1, antList2));
Assert.assertEquals(-1, EAV.compare(antList2, antList1));
antList1.add(aat);
Assert.assertEquals(0, EAV.compare(antList1, antList2));
Assert.assertEquals(0, EAV.compare(antList2, antList1));
antList1.clear();
antList2.clear();
at = new ContentAttrType_Generic();
at.tree_id = 1;
at.id = 1;
at.datatype = 1;
aat = new AttributeAndType(at, new ContentAttribute_Generic(at));
aat.attribute.setInteger(1);
antList1.add(aat);
at = new ContentAttrType_Generic();
at.tree_id = 1;
at.id = 2;
at.datatype = 1;
aat = new AttributeAndType(at, new ContentAttribute_Generic(at));
aat.attribute.setInteger(1);
antList2.add(aat);
Assert.assertEquals(1, EAV.compare(antList1, antList2));
Assert.assertEquals(-1, EAV.compare(antList2, antList1));
antList1.clear();
antList2.clear();
at = new ContentAttrType_Generic();
at.tree_id = 1;
at.id = 1;
at.datatype = 1;
aat = new AttributeAndType(at, new ContentAttribute_Generic(at));
aat.attribute.setInteger(1);
antList1.add(aat);
antList2.add(aat);
at = new ContentAttrType_Generic();
at.tree_id = 1;
at.id = 2;
at.datatype = 1;
aat = new AttributeAndType(at, new ContentAttribute_Generic(at));
aat.attribute.setInteger(1);
antList1.add(aat);
//Insert the attributes in antList2 in a different order - should still be identical
antList2.add(0, aat);
Assert.assertEquals(0, EAV.compare(antList1, antList2));
Assert.assertEquals(0, EAV.compare(antList2, antList1));
antList1.clear();
antList2.clear();
at = new ContentAttrType_Generic();
at.tree_id = 1;
at.id = 1;
at.datatype = 1;
aat = new AttributeAndType(at, new ContentAttribute_Generic(at));
aat.attribute.setInteger(1);
antList1.add(aat);
at = new ContentAttrType_Generic();
at.tree_id = 1;
at.id = 1;
at.datatype = 1;
aat = new AttributeAndType(at, new ContentAttribute_Generic(at));
aat.attribute.setInteger(2);
antList2.add(aat);
Assert.assertEquals(1, EAV.compare(antList1, antList2));
Assert.assertEquals(-1, EAV.compare(antList2, antList1));
}
}