1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.watchlist.internal

File ActivityEventWatchListEventConverterTest.java

 

Code metrics

0
23
1
1
96
50
1
0.04
23
1
1

Classes

Class Line # Actions
ActivityEventWatchListEventConverterTest 47 23 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Test the conversion from {@link ActivityEvent} to {@link WatchListEvent} done by
42    * {@link ActivityEventWatchListEventConverter}.
43    *
44    * @version $Id: 3712ca64ea08b01214c4251668f785e2b3c7d4f4 $
45    * @since 7.2M1
46    */
 
47    public class ActivityEventWatchListEventConverterTest
48    {
49    @Rule
50    public final MockitoComponentMockingRule<WatchListEventConverter<ActivityEvent>> mocker =
51    new MockitoComponentMockingRule<WatchListEventConverter<ActivityEvent>>(
52    ActivityEventWatchListEventConverter.class);
53   
 
54  1 toggle @Test
55    public void testConversion() throws Exception
56    {
57    // Input.
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    // Mocks
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    // Note: cheating a bit, it should return an entityReference instead of documentReference, but we are fine.
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    // Convert.
78  1 WatchListEvent watchListEvent = mocker.getComponentUnderTest().convert(activityEvent);
79   
80    // Test the output.
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    }