1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.messagestream; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
import java.util.UUID; |
24 |
|
|
25 |
|
import org.apache.commons.lang3.StringUtils; |
26 |
|
import org.jmock.Expectations; |
27 |
|
import org.junit.Assert; |
28 |
|
import org.junit.Before; |
29 |
|
import org.junit.Test; |
30 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
32 |
|
import org.xwiki.eventstream.Event; |
33 |
|
import org.xwiki.eventstream.Event.Importance; |
34 |
|
import org.xwiki.eventstream.EventFactory; |
35 |
|
import org.xwiki.eventstream.EventStream; |
36 |
|
import org.xwiki.eventstream.internal.DefaultEvent; |
37 |
|
import org.xwiki.messagestream.internal.DefaultMessageStream; |
38 |
|
import org.xwiki.model.ModelContext; |
39 |
|
import org.xwiki.model.reference.DocumentReference; |
40 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
41 |
|
import org.xwiki.model.reference.ObjectReference; |
42 |
|
import org.xwiki.query.Query; |
43 |
|
import org.xwiki.query.QueryException; |
44 |
|
import org.xwiki.query.QueryManager; |
45 |
|
import org.xwiki.test.jmock.AbstractMockingComponentTestCase; |
46 |
|
import org.xwiki.test.jmock.annotation.MockingRequirement; |
47 |
|
|
48 |
|
|
49 |
|
@link |
50 |
|
@link |
51 |
|
|
52 |
|
@version |
53 |
|
|
54 |
|
@MockingRequirement(DefaultMessageStream.class) |
|
|
| 100% |
Uncovered Elements: 0 (225) |
Complexity: 45 |
Complexity Density: 0.25 |
|
55 |
|
public class MessageStreamTest extends AbstractMockingComponentTestCase<MessageStream> |
56 |
|
{ |
57 |
|
private MessageStream stream; |
58 |
|
|
59 |
|
private final DocumentReference currentUser = new DocumentReference("wiki", "XWiki", "JohnDoe"); |
60 |
|
|
61 |
|
private final DocumentReference targetUser = new DocumentReference("wiki", "XWiki", "JaneBuck"); |
62 |
|
|
63 |
|
private final DocumentReference targetGroup = new DocumentReference("wiki", "XWiki", "MyFriends"); |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
28 |
@Before... |
66 |
|
public void configure() throws Exception |
67 |
|
{ |
68 |
28 |
this.stream = getComponentManager().getInstance(MessageStream.class); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void testPostPublicMessage() throws Exception |
73 |
|
{ |
74 |
1 |
Event postedMessage = setupForPublicMessage(); |
75 |
1 |
this.stream.postPublicMessage("Hello World!"); |
76 |
1 |
Assert.assertEquals("Hello World!", postedMessage.getBody()); |
77 |
1 |
Assert.assertEquals(Importance.MINOR, postedMessage.getImportance()); |
78 |
1 |
Assert.assertEquals("publicMessage", postedMessage.getType()); |
79 |
1 |
Assert.assertEquals(this.currentUser, postedMessage.getRelatedEntity()); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
82 |
1 |
@Test... |
83 |
|
public void testPostPublicMessageWithNullMessage() throws Exception |
84 |
|
{ |
85 |
1 |
Event postedMessage = setupForPublicMessage(); |
86 |
1 |
this.stream.postPublicMessage(null); |
87 |
1 |
Assert.assertEquals(null, postedMessage.getBody()); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
public void testPostPublicMessageWithEmptyMessage() throws Exception |
92 |
|
{ |
93 |
1 |
Event postedMessage = setupForPublicMessage(); |
94 |
1 |
this.stream.postPublicMessage(""); |
95 |
1 |
Assert.assertEquals("", postedMessage.getBody()); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void testPostPublicMessageWithLongMessage() throws Exception |
100 |
|
{ |
101 |
1 |
Event postedMessage = setupForPublicMessage(); |
102 |
1 |
this.stream.postPublicMessage(StringUtils.repeat('a', 10000)); |
103 |
1 |
Assert.assertEquals(StringUtils.repeat('a', 2000), postedMessage.getBody()); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
106 |
1 |
@Test... |
107 |
|
public void testPostPersonalMessage() throws Exception |
108 |
|
{ |
109 |
1 |
Event postedMessage = setupForPersonalMessage(); |
110 |
1 |
this.stream.postPersonalMessage("Hello World!"); |
111 |
1 |
Assert.assertEquals("Hello World!", postedMessage.getBody()); |
112 |
1 |
Assert.assertEquals(Importance.MEDIUM, postedMessage.getImportance()); |
113 |
1 |
Assert.assertEquals("personalMessage", postedMessage.getType()); |
114 |
1 |
Assert.assertEquals(this.currentUser, postedMessage.getRelatedEntity()); |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
117 |
1 |
@Test... |
118 |
|
public void testPostPersonalMessageWithNullMessage() throws Exception |
119 |
|
{ |
120 |
1 |
Event postedMessage = setupForPersonalMessage(); |
121 |
1 |
this.stream.postPersonalMessage(null); |
122 |
1 |
Assert.assertEquals(null, postedMessage.getBody()); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void testPostPersonalMessageWithEmptyMessage() throws Exception |
127 |
|
{ |
128 |
1 |
Event postedMessage = setupForPersonalMessage(); |
129 |
1 |
this.stream.postPersonalMessage(""); |
130 |
1 |
Assert.assertEquals("", postedMessage.getBody()); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
133 |
1 |
@Test... |
134 |
|
public void testPostPersonalMessageWithLongMessage() throws Exception |
135 |
|
{ |
136 |
1 |
Event postedMessage = setupForPersonalMessage(); |
137 |
1 |
this.stream.postPersonalMessage(StringUtils.repeat('a', 10000)); |
138 |
1 |
Assert.assertEquals(StringUtils.repeat('a', 2000), postedMessage.getBody()); |
139 |
|
} |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
141 |
1 |
@Test... |
142 |
|
public void testPostDirectMessage() throws Exception |
143 |
|
{ |
144 |
1 |
Event postedMessage = setupForDirectMessage(); |
145 |
1 |
this.stream.postDirectMessageToUser("Hello World!", this.targetUser); |
146 |
1 |
Assert.assertEquals("Hello World!", postedMessage.getBody()); |
147 |
1 |
Assert.assertEquals(Importance.CRITICAL, postedMessage.getImportance()); |
148 |
1 |
Assert.assertEquals("directMessage", postedMessage.getType()); |
149 |
1 |
Assert.assertEquals("wiki:XWiki.JaneBuck", postedMessage.getStream()); |
150 |
1 |
Assert.assertEquals(new ObjectReference("XWiki.XWikiUsers", this.targetUser), postedMessage.getRelatedEntity()); |
151 |
|
} |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
153 |
1 |
@Test... |
154 |
|
public void testPostDirectMessageWithNullMessage() throws Exception |
155 |
|
{ |
156 |
1 |
Event postedMessage = setupForDirectMessage(); |
157 |
1 |
this.stream.postDirectMessageToUser(null, this.targetUser); |
158 |
1 |
Assert.assertEquals(null, postedMessage.getBody()); |
159 |
|
} |
160 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
161 |
1 |
@Test... |
162 |
|
public void testPostDirectMessageWithEmptyMessage() throws Exception |
163 |
|
{ |
164 |
1 |
Event postedMessage = setupForDirectMessage(); |
165 |
1 |
this.stream.postDirectMessageToUser("", this.targetUser); |
166 |
1 |
Assert.assertEquals("", postedMessage.getBody()); |
167 |
|
} |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
169 |
1 |
@Test... |
170 |
|
public void testPostDirectMessageWithLongMessage() throws Exception |
171 |
|
{ |
172 |
1 |
Event postedMessage = setupForDirectMessage(); |
173 |
1 |
this.stream.postDirectMessageToUser(StringUtils.repeat('a', 10000), this.targetUser); |
174 |
1 |
Assert.assertEquals(StringUtils.repeat('a', 2000), postedMessage.getBody()); |
175 |
|
} |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
177 |
1 |
@Test(expected = IllegalArgumentException.class)... |
178 |
|
public void testPostDirectMessageWithNonExistingTarget() throws Exception |
179 |
|
{ |
180 |
1 |
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class); |
181 |
1 |
final DocumentReference targetUser = new DocumentReference("xwiki", "XWiki", "Nobody"); |
182 |
1 |
getMockery().checking(new Expectations() |
183 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
184 |
1 |
{... |
185 |
1 |
exactly(1).of(mockBridge).exists(targetUser); |
186 |
1 |
will(returnValue(false)); |
187 |
|
} |
188 |
|
}); |
189 |
1 |
this.stream.postDirectMessageToUser("Hello Nobody!", targetUser); |
190 |
|
} |
191 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
192 |
1 |
@Test... |
193 |
|
public void testPostGroupMessage() throws Exception |
194 |
|
{ |
195 |
1 |
Event postedMessage = setupForGroupMessage(); |
196 |
1 |
this.stream.postMessageToGroup("Hello Friends!", this.targetGroup); |
197 |
1 |
Assert.assertEquals("Hello Friends!", postedMessage.getBody()); |
198 |
1 |
Assert.assertEquals(Importance.MAJOR, postedMessage.getImportance()); |
199 |
1 |
Assert.assertEquals("groupMessage", postedMessage.getType()); |
200 |
1 |
Assert.assertEquals("wiki:XWiki.MyFriends", postedMessage.getStream()); |
201 |
1 |
Assert.assertEquals(new ObjectReference("XWiki.XWikiGroups", this.targetGroup), postedMessage |
202 |
|
.getRelatedEntity()); |
203 |
|
} |
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
205 |
1 |
@Test(expected = IllegalArgumentException.class)... |
206 |
|
public void testPostGroupMessageWithNonExistingTarget() throws Exception |
207 |
|
{ |
208 |
1 |
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class); |
209 |
1 |
final DocumentReference targetGroup = new DocumentReference("xwiki", "XWiki", "Nobodies"); |
210 |
1 |
getMockery().checking(new Expectations() |
211 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
212 |
1 |
{... |
213 |
1 |
exactly(1).of(mockBridge).exists(targetGroup); |
214 |
1 |
will(returnValue(false)); |
215 |
|
} |
216 |
|
}); |
217 |
1 |
this.stream.postMessageToGroup("Hello Nobodies!", targetGroup); |
218 |
|
} |
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
220 |
1 |
@Test... |
221 |
|
public void testGetRecentPersonalMessages() throws Exception |
222 |
|
{ |
223 |
1 |
setupForLimitQueries(30, 0); |
224 |
1 |
this.stream.getRecentPersonalMessages(); |
225 |
|
} |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
227 |
1 |
@Test... |
228 |
|
public void testGetRecentPersonalMessagesForAuthor() throws Exception |
229 |
|
{ |
230 |
1 |
setupForLimitQueries(30, 0); |
231 |
1 |
this.stream.getRecentPersonalMessages(this.currentUser); |
232 |
|
} |
233 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
234 |
1 |
@Test... |
235 |
|
public void testGetRecentPersonalMessagesWithNegativeLimit() throws Exception |
236 |
|
{ |
237 |
1 |
setupForLimitQueries(30, 0); |
238 |
1 |
this.stream.getRecentPersonalMessages(-4, 0); |
239 |
|
} |
240 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
241 |
1 |
@Test... |
242 |
|
public void testGetRecentPersonalMessagesWithZeroLimit() throws Exception |
243 |
|
{ |
244 |
1 |
setupForLimitQueries(30, 0); |
245 |
1 |
this.stream.getRecentPersonalMessages(0, 0); |
246 |
|
} |
247 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
248 |
1 |
@Test... |
249 |
|
public void testGetRecentPersonalMessagesWithLimit1() throws Exception |
250 |
|
{ |
251 |
1 |
setupForLimitQueries(1, 0); |
252 |
1 |
this.stream.getRecentPersonalMessages(1, 0); |
253 |
|
} |
254 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
255 |
1 |
@Test... |
256 |
|
public void testGetRecentPersonalMessagesWithLimit30() throws Exception |
257 |
|
{ |
258 |
1 |
setupForLimitQueries(30, 0); |
259 |
1 |
this.stream.getRecentPersonalMessages(30, 0); |
260 |
|
} |
261 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
262 |
1 |
@Test... |
263 |
|
public void testGetRecentPersonalMessagesWithLimit100() throws Exception |
264 |
|
{ |
265 |
1 |
setupForLimitQueries(100, 0); |
266 |
1 |
this.stream.getRecentPersonalMessages(100, 0); |
267 |
|
} |
268 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
269 |
1 |
@Test... |
270 |
|
public void testGetRecentPersonalMessagesWithNegativeOffset() throws Exception |
271 |
|
{ |
272 |
1 |
setupForLimitQueries(30, 0); |
273 |
1 |
this.stream.getRecentPersonalMessages(30, -4); |
274 |
|
} |
275 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
276 |
1 |
@Test... |
277 |
|
public void testGetRecentPersonalMessagesWithNegativeLimitAndOffset() throws Exception |
278 |
|
{ |
279 |
1 |
setupForLimitQueries(30, 0); |
280 |
1 |
this.stream.getRecentPersonalMessages(-1, -1); |
281 |
|
} |
282 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
283 |
1 |
@Test... |
284 |
|
public void testGetRecentPersonalMessagesWithZeroOffset() throws Exception |
285 |
|
{ |
286 |
1 |
setupForLimitQueries(100, 0); |
287 |
1 |
this.stream.getRecentPersonalMessages(100, 0); |
288 |
|
} |
289 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
290 |
1 |
@Test... |
291 |
|
public void testGetRecentPersonalMessagesWithOffset1() throws Exception |
292 |
|
{ |
293 |
1 |
setupForLimitQueries(20, 1); |
294 |
1 |
this.stream.getRecentPersonalMessages(20, 1); |
295 |
|
} |
296 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
297 |
1 |
@Test... |
298 |
|
public void testGetRecentPersonalMessagesWithOffset100() throws Exception |
299 |
|
{ |
300 |
1 |
setupForLimitQueries(50, 100); |
301 |
1 |
this.stream.getRecentPersonalMessages(50, 100); |
302 |
|
} |
303 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
304 |
1 |
@Test... |
305 |
|
public void testGetRecentPersonalMessagesWhenQueryFails() throws Exception |
306 |
|
{ |
307 |
1 |
final Query mockQuery = getMockQuery(); |
308 |
1 |
final QueryManager mockQueryManager = getComponentManager().getInstance(QueryManager.class); |
309 |
1 |
final EventStream mockEventStream = getComponentManager().getInstance(EventStream.class); |
310 |
1 |
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class); |
311 |
1 |
final EntityReferenceSerializer<String> mockSerializer = |
312 |
|
getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING); |
313 |
1 |
getMockery().checking(new Expectations() |
314 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
315 |
1 |
{... |
316 |
1 |
allowing(mockBridge).getCurrentUserReference(); |
317 |
1 |
will(returnValue(MessageStreamTest.this.currentUser)); |
318 |
1 |
allowing(mockSerializer).serialize(MessageStreamTest.this.currentUser); |
319 |
1 |
will(returnValue("wiki:XWiki.JohnDoe")); |
320 |
1 |
exactly(1).of(mockQuery).setLimit(30); |
321 |
1 |
will(returnValue(mockQuery)); |
322 |
1 |
exactly(1).of(mockQuery).setOffset(0); |
323 |
1 |
will(returnValue(mockQuery)); |
324 |
1 |
allowing(mockQuery).bindValue(with(any(String.class)), with("wiki:XWiki.JohnDoe")); |
325 |
1 |
allowing(mockQueryManager).createQuery(with(aNonNull(String.class)), with(aNonNull(String.class))); |
326 |
1 |
will(returnValue(mockQuery)); |
327 |
1 |
exactly(1).of(mockEventStream).searchEvents(with(mockQuery)); |
328 |
1 |
will(throwException(new QueryException("", null, null))); |
329 |
|
} |
330 |
|
}); |
331 |
1 |
List<Event> result = this.stream.getRecentPersonalMessages(); |
332 |
1 |
Assert.assertNotNull(result); |
333 |
1 |
Assert.assertTrue(result.isEmpty()); |
334 |
|
} |
335 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
336 |
13 |
private Event setupForNewMessage() throws ComponentLookupException, Exception... |
337 |
|
{ |
338 |
13 |
final EventFactory mockEventFactory = getComponentManager().getInstance(EventFactory.class); |
339 |
13 |
final Event e = new DefaultEvent(); |
340 |
13 |
e.setId(UUID.randomUUID().toString()); |
341 |
13 |
final ModelContext mockContext = getComponentManager().getInstance(ModelContext.class); |
342 |
13 |
final EventStream mockEventStream = getComponentManager().getInstance(EventStream.class); |
343 |
13 |
getMockery().checking(new Expectations() |
344 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
345 |
13 |
{... |
346 |
13 |
exactly(1).of(mockEventFactory).createEvent(); |
347 |
13 |
will(returnValue(e)); |
348 |
13 |
exactly(1).of(mockContext).getCurrentEntityReference(); |
349 |
13 |
will(returnValue(new DocumentReference("wiki", "Space", "Page"))); |
350 |
13 |
exactly(1).of(mockEventStream).addEvent(e); |
351 |
|
} |
352 |
|
}); |
353 |
13 |
return e; |
354 |
|
} |
355 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
356 |
4 |
private Event setupForPublicMessage() throws Exception... |
357 |
|
{ |
358 |
4 |
final Event e = setupForNewMessage(); |
359 |
4 |
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class); |
360 |
4 |
final EntityReferenceSerializer<String> mockSerializer = |
361 |
|
getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING); |
362 |
4 |
getMockery().checking(new Expectations() |
363 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
364 |
4 |
{... |
365 |
4 |
exactly(1).of(mockBridge).getCurrentUserReference(); |
366 |
4 |
will(returnValue(MessageStreamTest.this.currentUser)); |
367 |
4 |
exactly(1).of(mockSerializer).serialize(MessageStreamTest.this.currentUser); |
368 |
4 |
will(returnValue("wiki:XWiki.JohnDoe")); |
369 |
|
} |
370 |
|
}); |
371 |
4 |
return e; |
372 |
|
} |
373 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
374 |
4 |
private Event setupForPersonalMessage() throws Exception... |
375 |
|
{ |
376 |
4 |
final Event e = setupForNewMessage(); |
377 |
4 |
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class); |
378 |
4 |
final EntityReferenceSerializer<String> mockSerializer = |
379 |
|
getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING); |
380 |
4 |
getMockery().checking(new Expectations() |
381 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
382 |
4 |
{... |
383 |
4 |
exactly(1).of(mockBridge).getCurrentUserReference(); |
384 |
4 |
will(returnValue(MessageStreamTest.this.currentUser)); |
385 |
4 |
exactly(1).of(mockSerializer).serialize(MessageStreamTest.this.currentUser); |
386 |
4 |
will(returnValue("wiki:XWiki.JohnDoe")); |
387 |
|
} |
388 |
|
}); |
389 |
4 |
return e; |
390 |
|
} |
391 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
392 |
4 |
private Event setupForDirectMessage() throws ComponentLookupException, Exception... |
393 |
|
{ |
394 |
4 |
final Event e = setupForNewMessage(); |
395 |
4 |
final EntityReferenceSerializer<String> mockSerializer = |
396 |
|
getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING); |
397 |
4 |
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class); |
398 |
4 |
getMockery().checking(new Expectations() |
399 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
400 |
4 |
{... |
401 |
4 |
exactly(1).of(mockBridge).exists(MessageStreamTest.this.targetUser); |
402 |
4 |
will(returnValue(true)); |
403 |
4 |
exactly(1).of(mockSerializer).serialize(MessageStreamTest.this.targetUser); |
404 |
4 |
will(returnValue("wiki:XWiki.JaneBuck")); |
405 |
|
} |
406 |
|
}); |
407 |
4 |
return e; |
408 |
|
} |
409 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
410 |
1 |
private Event setupForGroupMessage() throws ComponentLookupException, Exception... |
411 |
|
{ |
412 |
1 |
final Event e = setupForNewMessage(); |
413 |
1 |
final EntityReferenceSerializer<String> mockSerializer = |
414 |
|
getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING); |
415 |
1 |
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class); |
416 |
1 |
getMockery().checking(new Expectations() |
417 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
418 |
1 |
{... |
419 |
1 |
exactly(1).of(mockBridge).exists(MessageStreamTest.this.targetGroup); |
420 |
1 |
will(returnValue(true)); |
421 |
1 |
exactly(1).of(mockSerializer).serialize(MessageStreamTest.this.targetGroup); |
422 |
1 |
will(returnValue("wiki:XWiki.MyFriends")); |
423 |
|
} |
424 |
|
}); |
425 |
1 |
return e; |
426 |
|
} |
427 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
428 |
12 |
private void setupForLimitQueries(final int expectedLimit, final int expectedOffset)... |
429 |
|
throws ComponentLookupException, Exception |
430 |
|
{ |
431 |
12 |
final Query mockQuery = getMockQuery(); |
432 |
12 |
final QueryManager mockQueryManager = getComponentManager().getInstance(QueryManager.class); |
433 |
12 |
final EventStream mockEventStream = getComponentManager().getInstance(EventStream.class); |
434 |
12 |
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class); |
435 |
12 |
final EntityReferenceSerializer<String> mockSerializer = |
436 |
|
getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING); |
437 |
12 |
getMockery().checking(new Expectations() |
438 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
439 |
12 |
{... |
440 |
12 |
allowing(mockBridge).getCurrentUserReference(); |
441 |
12 |
will(returnValue(MessageStreamTest.this.currentUser)); |
442 |
12 |
allowing(mockSerializer).serialize(MessageStreamTest.this.currentUser); |
443 |
12 |
will(returnValue("wiki:XWiki.JohnDoe")); |
444 |
12 |
exactly(1).of(mockQuery).setLimit(expectedLimit); |
445 |
12 |
will(returnValue(mockQuery)); |
446 |
12 |
exactly(1).of(mockQuery).setOffset(expectedOffset); |
447 |
12 |
will(returnValue(mockQuery)); |
448 |
12 |
allowing(mockQuery).bindValue(with(any(String.class)), with("wiki:XWiki.JohnDoe")); |
449 |
12 |
allowing(mockQueryManager).createQuery(with(aNonNull(String.class)), with(aNonNull(String.class))); |
450 |
12 |
will(returnValue(mockQuery)); |
451 |
12 |
exactly(1).of(mockEventStream).searchEvents(with(mockQuery)); |
452 |
12 |
will(returnValue(null)); |
453 |
|
} |
454 |
|
}); |
455 |
|
} |
456 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
457 |
13 |
private Query getMockQuery()... |
458 |
|
{ |
459 |
13 |
return getMockery().mock(Query.class); |
460 |
|
} |
461 |
|
} |