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; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.Date; |
24 |
|
|
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.model.EntityType; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
30 |
|
import org.xwiki.model.reference.WikiReference; |
31 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
32 |
|
import org.xwiki.watchlist.internal.api.WatchListEvent; |
33 |
|
|
34 |
|
import com.xpn.xwiki.plugin.activitystream.api.ActivityEvent; |
35 |
|
import com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl; |
36 |
|
|
37 |
|
import static org.junit.Assert.assertEquals; |
38 |
|
import static org.mockito.Mockito.when; |
39 |
|
|
40 |
|
|
41 |
|
@link@link |
42 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
|
47 |
|
public class ActivityEventWatchListEventConverterTest |
48 |
|
{ |
49 |
|
@Rule |
50 |
|
public final MockitoComponentMockingRule<WatchListEventConverter<ActivityEvent>> mocker = |
51 |
|
new MockitoComponentMockingRule<WatchListEventConverter<ActivityEvent>>( |
52 |
|
ActivityEventWatchListEventConverter.class); |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
54 |
1 |
@Test... |
55 |
|
public void testConversion() throws Exception |
56 |
|
{ |
57 |
|
|
58 |
1 |
ActivityEvent activityEvent = new ActivityEventImpl(); |
59 |
1 |
activityEvent.setWiki("xwiki"); |
60 |
1 |
activityEvent.setPage("Space1.Space2.Page"); |
61 |
1 |
activityEvent.setType("update"); |
62 |
1 |
activityEvent.setUser("xwiki:XWiki.SomeUser"); |
63 |
1 |
activityEvent.setVersion("1.3"); |
64 |
1 |
activityEvent.setDate(new Date()); |
65 |
|
|
66 |
|
|
67 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Space1", "Space2"), "Page"); |
68 |
1 |
WikiReference wikiReference = new WikiReference(activityEvent.getWiki()); |
69 |
1 |
EntityReferenceResolver<String> resolver = mocker.getInstance(EntityReferenceResolver.TYPE_STRING, "explicit"); |
70 |
|
|
71 |
1 |
when(resolver.resolve(activityEvent.getPage(), EntityType.DOCUMENT, wikiReference)).thenReturn( |
72 |
|
documentReference); |
73 |
|
|
74 |
1 |
DocumentReference userReference = new DocumentReference("xwiki", "XWiki", "SomeUser"); |
75 |
1 |
when(resolver.resolve(activityEvent.getUser(), EntityType.DOCUMENT, wikiReference)).thenReturn(userReference); |
76 |
|
|
77 |
|
|
78 |
1 |
WatchListEvent watchListEvent = mocker.getComponentUnderTest().convert(activityEvent); |
79 |
|
|
80 |
|
|
81 |
1 |
assertEquals(documentReference, watchListEvent.getDocumentReference()); |
82 |
|
|
83 |
1 |
assertEquals(activityEvent.getWiki(), watchListEvent.getDocumentReference().getWikiReference().getName()); |
84 |
|
|
85 |
1 |
assertEquals(activityEvent.getType(), watchListEvent.getType()); |
86 |
|
|
87 |
1 |
assertEquals(userReference, watchListEvent.getAuthorReference()); |
88 |
1 |
assertEquals(1, watchListEvent.getAuthorReferences().size()); |
89 |
|
|
90 |
1 |
assertEquals(activityEvent.getVersion(), watchListEvent.getVersion()); |
91 |
1 |
assertEquals(1, watchListEvent.getVersions().size()); |
92 |
|
|
93 |
1 |
assertEquals(activityEvent.getDate(), watchListEvent.getDate()); |
94 |
1 |
assertEquals(1, watchListEvent.getDates().size()); |
95 |
|
} |
96 |
|
} |