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

File DefaultWatchedEntitiesConfigurationTest.java

 

Code metrics

0
19
3
1
118
69
3
0.16
6.33
3
1

Classes

Class Line # Actions
DefaultWatchedEntitiesConfigurationTest 43 19 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

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.notifications.filters.watch.internal;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Before;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.bridge.DocumentAccessBridge;
28    import org.xwiki.configuration.ConfigurationSource;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.WikiReference;
31    import org.xwiki.notifications.filters.watch.AutomaticWatchMode;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
34   
35    import static org.junit.Assert.assertEquals;
36    import static org.mockito.Mockito.when;
37   
38    /**
39    * @version $Id: bc34b7c33d045924b3dc82f96448ec23de8f3e52 $
40    * @since 10.6RC1
41    * @since 9.11.8
42    */
 
43    public class DefaultWatchedEntitiesConfigurationTest
44    {
45    @Rule
46    public final MockitoComponentMockingRule<DefaultWatchedEntitiesConfiguration> mocker =
47    new MockitoComponentMockingRule<>(DefaultWatchedEntitiesConfiguration.class);
48   
49    private static final DocumentReference CURRENT_USER
50    = new DocumentReference("wikiA", "XWiki", "UserA");
51   
52    private static final WikiReference CURRENT_WIKI = new WikiReference("wikiA");
53   
54    private DocumentAccessBridge documentAccessBridge;
55    private ConfigurationSource configurationSource;
56    private WikiDescriptorManager wikiDescriptorManager;
57   
 
58  2 toggle @Before
59    public void setUp() throws Exception
60    {
61  2 documentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
62  2 configurationSource = mocker.getInstance(ConfigurationSource.class);
63  2 wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
64   
65  2 when(documentAccessBridge.getCurrentDocumentReference()).thenReturn(new DocumentReference("wikiA", "Main", "WebHome"));
66  2 when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
67    }
68   
 
69  1 toggle @Test
70    public void getAutomaticWatchMode() throws Exception
71    {
72    // Default value
73  1 assertEquals(AutomaticWatchMode.MAJOR, mocker.getComponentUnderTest().getAutomaticWatchMode(CURRENT_USER));
74   
75    // Fallback to the value of the Watchlist
76  1 when(documentAccessBridge.getProperty(
77    CURRENT_USER,
78    new DocumentReference("wikiA", "XWiki", "WatchListClass"),
79    "automaticwatch")).thenReturn("NEW");
80  1 assertEquals(AutomaticWatchMode.NEW, mocker.getComponentUnderTest().getAutomaticWatchMode(CURRENT_USER));
81   
82    // User the user's preference
83  1 when(documentAccessBridge.getProperty(
84    CURRENT_USER,
85    new DocumentReference("wikiA", Arrays.asList("XWiki", "Notifications", "Code"), "AutomaticWatchModeClass"),
86    "automaticWatchMode")).thenReturn("ALL");
87  1 assertEquals(AutomaticWatchMode.ALL, mocker.getComponentUnderTest().getAutomaticWatchMode(CURRENT_USER));
88    }
89   
 
90  1 toggle @Test
91    public void getDefaultAutomaticWatchMode() throws Exception
92    {
93    // Default value
94  1 assertEquals(AutomaticWatchMode.MAJOR, mocker.getComponentUnderTest().getDefaultAutomaticWatchMode(CURRENT_WIKI));
95   
96    // Fallback on the watchlist configuration
97  1 when(configurationSource.getProperty("xwiki.plugin.watchlist.automaticwatch")).thenReturn("new");
98  1 assertEquals(AutomaticWatchMode.NEW, mocker.getComponentUnderTest().getDefaultAutomaticWatchMode(CURRENT_WIKI));
99   
100    // Fallback on the notifications configuration
101  1 when(configurationSource.getProperty("notifications.watchedEntities.autoWatch")).thenReturn("all");
102  1 assertEquals(AutomaticWatchMode.ALL, mocker.getComponentUnderTest().getDefaultAutomaticWatchMode(CURRENT_WIKI));
103   
104    // Fallback on the main wiki's configuration
105  1 when(documentAccessBridge.getProperty(
106    new DocumentReference("mainWiki", Arrays.asList("XWiki", "Notifications", "Code"), "NotificationAdministration"),
107    new DocumentReference("mainWiki", Arrays.asList("XWiki", "Notifications", "Code"), "AutomaticWatchModeClass"),
108    "automaticWatchMode")).thenReturn("NONE");
109  1 assertEquals(AutomaticWatchMode.NONE, mocker.getComponentUnderTest().getDefaultAutomaticWatchMode(CURRENT_WIKI));
110   
111    // Use the wiki's configuration
112  1 when(documentAccessBridge.getProperty(
113    new DocumentReference("wikiA", Arrays.asList("XWiki", "Notifications", "Code"), "NotificationAdministration"),
114    new DocumentReference("wikiA", Arrays.asList("XWiki", "Notifications", "Code"), "AutomaticWatchModeClass"),
115    "automaticWatchMode")).thenReturn("NEW");
116  1 assertEquals(AutomaticWatchMode.NEW, mocker.getComponentUnderTest().getDefaultAutomaticWatchMode(CURRENT_WIKI));
117    }
118    }