1
|
package org.dataone.client.types;
|
2
|
|
3
|
import static org.junit.Assert.*;
|
4
|
|
5
|
import java.util.Date;
|
6
|
|
7
|
import org.dataone.client.D1TypeBuilder;
|
8
|
import org.dataone.service.types.v1.Identifier;
|
9
|
import org.junit.Before;
|
10
|
import org.junit.Test;
|
11
|
|
12
|
public class ObsoletesChainTest {
|
13
|
|
14
|
private ObsoletesChain chain;
|
15
|
private ObsoletesChain chainWithNulls;
|
16
|
private Identifier foo1 = D1TypeBuilder.buildIdentifier("foo1");
|
17
|
private Identifier foo2 = D1TypeBuilder.buildIdentifier("foo2");
|
18
|
private Identifier foo3 = D1TypeBuilder.buildIdentifier("foo3");
|
19
|
private Identifier foo4 = D1TypeBuilder.buildIdentifier("foo4");
|
20
|
private Identifier foo5 = D1TypeBuilder.buildIdentifier("foo5");
|
21
|
private Identifier foo6 = D1TypeBuilder.buildIdentifier("foo6");
|
22
|
private Identifier foo7 = D1TypeBuilder.buildIdentifier("foo7");
|
23
|
private Identifier foo8 = D1TypeBuilder.buildIdentifier("foo8");
|
24
|
private Identifier foo9 = D1TypeBuilder.buildIdentifier("foo9");
|
25
|
|
26
|
@Before
|
27
|
public void setUp() throws Exception {
|
28
|
|
29
|
chain = new ObsoletesChain(foo3);
|
30
|
chain.addObject(foo4, new Date(4000000), foo3, foo5, true, false);
|
31
|
chain.addObject(foo3, new Date(3000000), foo2, foo4, true, false);
|
32
|
chain.addObject(foo2, new Date(2000000), foo1, foo3, true, false);
|
33
|
chain.addObject(foo1, new Date(1000000), null, foo2, true, false);
|
34
|
|
35
|
chain.addObject(foo5, new Date(5000000), foo4, foo6, true, false);
|
36
|
chain.addObject(foo6, new Date(6000000), foo5, foo7, true, false);
|
37
|
chain.addObject(foo7, new Date(7000000), foo6, foo8, true, false);
|
38
|
chain.addObject(foo8, new Date(8000000), foo7, foo9, true, false);
|
39
|
chain.addObject(foo9, new Date(9000000), foo8, null, false, false);
|
40
|
|
41
|
chainWithNulls = new ObsoletesChain(foo3);
|
42
|
chainWithNulls.addObject(foo4, new Date(4000000), foo3, foo5, true, false);
|
43
|
chainWithNulls.addObject(foo3, new Date(3000000), foo2, foo4, true, false);
|
44
|
chainWithNulls.addObject(foo2, new Date(2000000), foo1, foo3, true, false);
|
45
|
chainWithNulls.addObject(foo1, new Date(1000000), null, foo2, true, false);
|
46
|
|
47
|
chainWithNulls.addObject(foo5, new Date(5000000), foo4, foo6, true, false);
|
48
|
chainWithNulls.addObject(foo6, new Date(6000000), foo5, foo7, true, false);
|
49
|
chainWithNulls.addObject(foo7, new Date(7000000), foo6, foo8, true, false);
|
50
|
chainWithNulls.addObject(foo8, new Date(8000000), foo7, foo9, true, false);
|
51
|
chainWithNulls.addObject(foo9, new Date(9000000), foo8, null, null, false);
|
52
|
|
53
|
|
54
|
}
|
55
|
|
56
|
@Test
|
57
|
public void testGetStartingPoint() {
|
58
|
assertTrue(chain.getStartingPoint().equals(foo3));
|
59
|
}
|
60
|
|
61
|
|
62
|
public void testAddObject() {
|
63
|
fail("Not yet implemented");
|
64
|
}
|
65
|
|
66
|
@Test
|
67
|
public void testGetVersionAsOf() {
|
68
|
assertTrue(chain.getVersionAsOf(new Date(6300000)).equals(foo6));
|
69
|
assertNull(chain.getVersionAsOf(new Date(300000)));
|
70
|
assertTrue(chain.getVersionAsOf(new Date(10300000)).equals(foo9));
|
71
|
}
|
72
|
|
73
|
@Test
|
74
|
public void testNextVersion() {
|
75
|
assertTrue(chain.nextVersion(foo2).equals(foo3));
|
76
|
assertNull(chain.nextVersion(foo9));
|
77
|
}
|
78
|
|
79
|
@Test
|
80
|
public void testPreviousVersion() {
|
81
|
assertTrue(chain.previousVersion(foo8).equals(foo7));
|
82
|
assertNull(chain.previousVersion(foo1));
|
83
|
}
|
84
|
|
85
|
@Test
|
86
|
public void testGetLatestVersion() {
|
87
|
assertTrue(chain.getLatestVersion().equals(foo9));
|
88
|
}
|
89
|
|
90
|
@Test
|
91
|
public void testGetOriginalVersion() {
|
92
|
assertTrue(chain.getOriginalVersion().equals(foo1));
|
93
|
}
|
94
|
|
95
|
@Test
|
96
|
public void testGetByPosition() {
|
97
|
assertTrue(chain.getByPosition(4).equals(foo5));
|
98
|
}
|
99
|
|
100
|
@Test
|
101
|
public void testSize() {
|
102
|
assertTrue(chain.size() == 9);
|
103
|
}
|
104
|
|
105
|
@Test
|
106
|
public void testIsComplete() {
|
107
|
assertTrue(chain.isComplete());
|
108
|
}
|
109
|
|
110
|
@Test
|
111
|
public void testIsArchived() {
|
112
|
assertTrue(chain.isArchived(foo2));
|
113
|
assertFalse(chain.isArchived(foo9));
|
114
|
}
|
115
|
|
116
|
@Test
|
117
|
public void testLatestIsArchived() {
|
118
|
assertFalse(chain.latestIsArchived());
|
119
|
}
|
120
|
|
121
|
@Test
|
122
|
public void testGetPublishDate() {
|
123
|
Date expect = new Date(2000000);
|
124
|
System.out.print(expect.getTime());
|
125
|
System.out.print(chain.getPublishDate(foo2).getTime());
|
126
|
assertTrue(chain.getPublishDate(foo2).equals(expect));
|
127
|
}
|
128
|
|
129
|
@Test
|
130
|
public void testIsLatestVersion() {
|
131
|
assertTrue(chain.isLatestVersion(foo9));
|
132
|
assertFalse(chain.isLatestVersion(foo5));
|
133
|
}
|
134
|
|
135
|
|
136
|
@Test
|
137
|
public void testIsArchived_Null() {
|
138
|
assertTrue(chainWithNulls.isArchived(foo2));
|
139
|
assertFalse(chainWithNulls.isArchived(foo9));
|
140
|
}
|
141
|
}
|