1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.watchlist.internal.api; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.Date; |
24 |
|
|
25 |
|
import org.junit.Assert; |
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Rule; |
28 |
|
import org.junit.Test; |
29 |
|
import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer; |
30 |
|
import org.xwiki.model.internal.reference.DefaultSymbolScheme; |
31 |
|
import org.xwiki.model.internal.reference.LocalStringEntityReferenceSerializer; |
32 |
|
import org.xwiki.model.reference.DocumentReference; |
33 |
|
import org.xwiki.test.annotation.ComponentList; |
34 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
35 |
|
|
36 |
|
import com.xpn.xwiki.web.Utils; |
37 |
|
|
38 |
|
|
39 |
|
@link |
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
44 |
|
@ComponentList({ |
45 |
|
LocalStringEntityReferenceSerializer.class, |
46 |
|
DefaultStringEntityReferenceSerializer.class, |
47 |
|
DefaultSymbolScheme.class |
48 |
|
}) |
|
|
| 100% |
Uncovered Elements: 0 (37) |
Complexity: 5 |
Complexity Density: 0.16 |
|
49 |
|
public class WatchListEventTest |
50 |
|
{ |
51 |
|
@Rule |
52 |
|
public MockitoComponentManagerRule mocker = new MockitoComponentManagerRule(); |
53 |
|
|
54 |
|
private DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); |
55 |
|
|
56 |
|
private DocumentReference userReference = new DocumentReference("wiki", "XWiki", "user"); |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
3 |
@Before... |
59 |
|
public void setup() |
60 |
|
{ |
61 |
|
|
62 |
3 |
Utils.setComponentManager(this.mocker); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
65 |
1 |
@Test... |
66 |
|
public void addEventsOnlyUpdates() |
67 |
|
{ |
68 |
1 |
WatchListEvent event = newEvent(WatchListEventType.UPDATE, "2.2", new Date(1000000)); |
69 |
1 |
event.addEvent(newEvent(WatchListEventType.UPDATE, "2.1", new Date(900000))); |
70 |
1 |
event.addEvent(newEvent(WatchListEventType.UPDATE, "2.0", new Date(800000))); |
71 |
|
|
72 |
1 |
Assert.assertEquals(this.documentReference, event.getDocumentReference()); |
73 |
1 |
Assert.assertEquals(this.userReference, event.getAuthorReference()); |
74 |
1 |
Assert.assertEquals(Arrays.asList("wiki:XWiki.user"), event.getAuthors()); |
75 |
1 |
Assert.assertEquals(WatchListEventType.UPDATE, event.getType()); |
76 |
1 |
Assert.assertEquals(Arrays.asList(new Date(1000000), new Date(900000), new Date(800000)), event.getDates()); |
77 |
1 |
Assert.assertEquals("2.2", event.getVersion()); |
78 |
1 |
Assert.assertEquals(Arrays.asList("2.2", "2.1", "2.0"), event.getVersions()); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void addEventsUpdateThenCreate() |
83 |
|
{ |
84 |
1 |
WatchListEvent event = newEvent(WatchListEventType.UPDATE, "2.2", new Date(1000000)); |
85 |
1 |
event.addEvent(newEvent(WatchListEventType.UPDATE, "2.1", new Date(900000))); |
86 |
1 |
event.addEvent(newEvent(WatchListEventType.CREATE, "1.1", new Date(800000))); |
87 |
|
|
88 |
1 |
Assert.assertEquals(this.documentReference, event.getDocumentReference()); |
89 |
1 |
Assert.assertEquals(this.userReference, event.getAuthorReference()); |
90 |
1 |
Assert.assertEquals(Arrays.asList("wiki:XWiki.user"), event.getAuthors()); |
91 |
1 |
Assert.assertEquals(WatchListEventType.UPDATE, event.getType()); |
92 |
1 |
Assert.assertEquals(Arrays.asList(new Date(1000000), new Date(900000), new Date(800000)), event.getDates()); |
93 |
1 |
Assert.assertEquals("2.2", event.getVersion()); |
94 |
1 |
Assert.assertEquals(Arrays.asList("2.2", "2.1", "1.1"), event.getVersions()); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
97 |
1 |
@Test... |
98 |
|
public void addEventsDeleteUpdateUpdate() |
99 |
|
{ |
100 |
1 |
WatchListEvent event = newEvent(WatchListEventType.DELETE, "1.4", new Date(1000000)); |
101 |
1 |
event.addEvent(newEvent(WatchListEventType.UPDATE, "1.3", new Date(900000))); |
102 |
1 |
event.addEvent(newEvent(WatchListEventType.UPDATE, "1.2", new Date(800000))); |
103 |
|
|
104 |
1 |
Assert.assertEquals(this.documentReference, event.getDocumentReference()); |
105 |
1 |
Assert.assertEquals(this.userReference, event.getAuthorReference()); |
106 |
1 |
Assert.assertEquals(Arrays.asList("wiki:XWiki.user"), event.getAuthors()); |
107 |
1 |
Assert.assertEquals(WatchListEventType.DELETE, event.getType()); |
108 |
1 |
Assert.assertEquals(Arrays.asList(new Date(1000000)), event.getDates()); |
109 |
1 |
Assert.assertEquals("1.4", event.getVersion()); |
110 |
1 |
Assert.assertEquals(Arrays.asList("1.4"), event.getVersions()); |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
9 |
private WatchListEvent newEvent(String type, String version, Date date)... |
146 |
|
{ |
147 |
9 |
return new WatchListEvent(this.documentReference, type, this.userReference, version, date); |
148 |
|
} |
149 |
|
} |