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

File DefaultWikiDeleterTest.java

 

Code metrics

0
22
3
1
109
67
4
0.18
7.33
3
1.33

Classes

Class Line # Actions
DefaultWikiDeleterTest 44 22 0% 4 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.wiki.internal.manager;
21   
22    import javax.inject.Provider;
23   
24    import org.junit.Before;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.test.mockito.MockitoComponentMockingRule;
28    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
29    import org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor;
30    import org.xwiki.wiki.internal.descriptor.document.WikiDescriptorDocumentHelper;
31    import org.xwiki.wiki.manager.WikiManagerException;
32   
33    import com.xpn.xwiki.XWikiContext;
34    import com.xpn.xwiki.doc.XWikiDocument;
35    import com.xpn.xwiki.store.XWikiStoreInterface;
36   
37    import static org.junit.Assert.assertTrue;
38    import static org.mockito.ArgumentMatchers.any;
39    import static org.mockito.ArgumentMatchers.eq;
40    import static org.mockito.Mockito.mock;
41    import static org.mockito.Mockito.verify;
42    import static org.mockito.Mockito.when;
43   
 
44    public class DefaultWikiDeleterTest
45    {
46    @Rule
47    public MockitoComponentMockingRule<DefaultWikiDeleter> mocker =
48    new MockitoComponentMockingRule(DefaultWikiDeleter.class);
49   
50    private WikiDescriptorManager wikiDescriptorManager;
51   
52    private Provider<XWikiContext> xcontextProvider;
53   
54    private WikiDescriptorDocumentHelper descriptorDocumentHelper;
55   
56    private XWikiContext xcontext;
57   
58    private com.xpn.xwiki.XWiki xwiki;
59   
60    private XWikiStoreInterface store;
61   
 
62  2 toggle @Before
63    public void setUp() throws Exception
64    {
65    // Injection
66  2 wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
67  2 xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
68  2 descriptorDocumentHelper = mocker.getInstance(WikiDescriptorDocumentHelper.class);
69   
70    // Frequent uses
71  2 xcontext = mock(XWikiContext.class);
72  2 when(xcontextProvider.get()).thenReturn(xcontext);
73  2 xwiki = mock(com.xpn.xwiki.XWiki.class);
74  2 when(xcontext.getWiki()).thenReturn(xwiki);
75  2 when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki");
76  2 store = mock(XWikiStoreInterface.class);
77  2 when(xwiki.getStore()).thenReturn(store);
78    }
79   
 
80  1 toggle @Test
81    public void deleteTheMainWiki() throws Exception
82    {
83  1 boolean exceptionCaught = false;
84  1 try {
85  1 this.mocker.getComponentUnderTest().delete("xwiki");
86    } catch (WikiManagerException e) {
87  1 exceptionCaught = true;
88    }
89  1 assertTrue(exceptionCaught);
90    }
91   
 
92  1 toggle @Test
93    public void deleteWiki() throws Exception
94    {
95    // Mock
96  1 DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid", "wikialias");
97  1 descriptor.addAlias("wikialias2");
98  1 XWikiDocument descriptorDocument = mock(XWikiDocument.class);
99  1 when(descriptorDocumentHelper.getDocumentFromWikiId("wikiid")).thenReturn(descriptorDocument);
100   
101    // Delete
102  1 this.mocker.getComponentUnderTest().delete("wikiid");
103   
104    // Verify that the database has been deleted
105  1 verify(store).deleteWiki(eq("wikiid"), any(XWikiContext.class));
106    // Verify that the descriptor document has been deleted
107  1 verify(xwiki).deleteDocument(eq(descriptorDocument), any(XWikiContext.class));
108    }
109    }