1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.wiki.workspacesmigrator.internal

File DefaultSearchSuggestCustomConfigDeleterTest.java

 

Code metrics

0
50
2
1
143
93
2
0.04
25
2
1

Classes

Class Line # Actions
DefaultSearchSuggestCustomConfigDeleterTest 44 50 0% 2 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.wiki.workspacesmigrator.internal;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import javax.inject.Provider;
26   
27    import org.junit.Before;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.xwiki.model.reference.DocumentReference;
31    import org.xwiki.test.mockito.MockitoComponentMockingRule;
32   
33    import com.xpn.xwiki.XWiki;
34    import com.xpn.xwiki.XWikiContext;
35    import com.xpn.xwiki.doc.XWikiDocument;
36    import com.xpn.xwiki.objects.BaseObject;
37   
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 DefaultSearchSuggestCustomConfigDeleterTest
45    {
46    @Rule
47    public MockitoComponentMockingRule<DefaultSearchSuggestCustomConfigDeleter> mocker =
48    new MockitoComponentMockingRule(DefaultSearchSuggestCustomConfigDeleter.class);
49   
50    private Provider<XWikiContext> xcontextProvider;
51   
52    private XWikiContext xcontext;
53   
54    private XWiki xwiki;
55   
 
56  1 toggle @Before
57    public void setUp() throws Exception
58    {
59  1 xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
60  1 xcontext = mock(XWikiContext.class);
61  1 when(xcontextProvider.get()).thenReturn(xcontext);
62  1 xwiki = mock(XWiki.class);
63  1 when(xcontext.getWiki()).thenReturn(xwiki);
64    }
65   
 
66  1 toggle @Test
67    public void deleteSearchSuggestCustomConfig() throws Exception
68    {
69  1 XWikiDocument searchSuggestConfigDoc = mock(XWikiDocument.class);
70  1 when(xwiki.getDocument(eq(new DocumentReference("mainWiki", "XWiki", "SearchSuggestConfig")),
71    any(XWikiContext.class))).thenReturn(searchSuggestConfigDoc);
72  1 BaseObject objConfig1 = mock(BaseObject.class);
73  1 BaseObject objConfig2 = mock(BaseObject.class);
74  1 BaseObject objConfig3 = mock(BaseObject.class);
75  1 BaseObject objConfig4 = mock(BaseObject.class);
76  1 BaseObject objConfig5 = mock(BaseObject.class);
77  1 BaseObject objConfig6 = mock(BaseObject.class);
78  1 List<BaseObject> objects = new ArrayList<BaseObject>();
79  1 objects.add(objConfig1);
80  1 objects.add(objConfig2);
81  1 objects.add(objConfig3);
82    // null objects can be present in the list
83  1 objects.add(null);
84  1 objects.add(objConfig4);
85  1 objects.add(objConfig5);
86  1 objects.add(objConfig6);
87  1 when(searchSuggestConfigDoc.getXObjects(eq(new DocumentReference("mainWiki", "XWiki",
88    "SearchSuggestSourceClass")))).thenReturn(objects);
89   
90    // Object 1
91  1 when(objConfig1.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces");
92  1 when(objConfig1.getStringValue("engine")).thenReturn("solr");
93  1 when(objConfig1.getStringValue("query")).thenReturn("class:XWiki.XWikiServerClass AND " +
94    "propertyname:wikiprettyname AND propertyvalue__:(__INPUT__*)");
95  1 when(objConfig1.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestSolrService");
96   
97    // Object 2
98  1 when(objConfig2.getStringValue("name")).thenReturn("Bad name");
99  1 when(objConfig2.getStringValue("engine")).thenReturn("solr");
100  1 when(objConfig2.getStringValue("query")).thenReturn("class:XWiki.XWikiServerClass AND " +
101    "propertyname:wikiprettyname AND propertyvalue__:(__INPUT__*)");
102  1 when(objConfig2.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestSolrService");
103   
104    // Object 3
105  1 when(objConfig3.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces");
106  1 when(objConfig3.getStringValue("engine")).thenReturn("lucene");
107  1 when(objConfig3.getStringValue("query")).thenReturn("XWiki.XWikiServerClass.wikiprettyname:__INPUT__* AND " +
108    "object:WorkspaceManager.WorkspaceClass");
109  1 when(objConfig3.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestLuceneService");
110   
111    // Object 4
112  1 when(objConfig4.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces");
113  1 when(objConfig4.getStringValue("engine")).thenReturn(null);
114  1 when(objConfig4.getStringValue("query")).thenReturn("XWiki.XWikiServerClass.wikiprettyname:__INPUT__* AND " +
115    "object:WorkspaceManager.WorkspaceClass");
116  1 when(objConfig4.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestLuceneService");
117   
118    // Object 5
119  1 when(objConfig5.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces");
120  1 when(objConfig5.getStringValue("engine")).thenReturn(null);
121  1 when(objConfig5.getStringValue("query")).thenReturn("bad query");
122  1 when(objConfig5.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestLuceneService");
123   
124    // Object 6
125  1 when(objConfig6.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces");
126  1 when(objConfig6.getStringValue("engine")).thenReturn(null);
127  1 when(objConfig6.getStringValue("query")).thenReturn("XWiki.XWikiServerClass.wikiprettyname:__INPUT__* AND " +
128    "object:WorkspaceManager.WorkspaceClass");
129  1 when(objConfig6.getStringValue("url")).thenReturn("bad URL");
130   
131    // Run
132  1 mocker.getComponentUnderTest().deleteSearchSuggestCustomConfig("mainWiki");
133   
134    // Verify that the good objects has been removed
135  1 verify(searchSuggestConfigDoc).removeXObject(objConfig1);
136  1 verify(searchSuggestConfigDoc).removeXObject(objConfig3);
137    // Verify that the document have been saved
138  1 verify(xwiki).saveDocument(searchSuggestConfigDoc,
139    "Remove object previously introduced by WorkspaceManager.Install", xcontext);
140   
141    }
142   
143    }