1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (52) |
Complexity: 2 |
Complexity Density: 0.04 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
56 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (45) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
66 |
1 |
@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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
132 |
1 |
mocker.getComponentUnderTest().deleteSearchSuggestCustomConfig("mainWiki"); |
133 |
|
|
134 |
|
|
135 |
1 |
verify(searchSuggestConfigDoc).removeXObject(objConfig1); |
136 |
1 |
verify(searchSuggestConfigDoc).removeXObject(objConfig3); |
137 |
|
|
138 |
1 |
verify(xwiki).saveDocument(searchSuggestConfigDoc, |
139 |
|
"Remove object previously introduced by WorkspaceManager.Install", xcontext); |
140 |
|
|
141 |
|
} |
142 |
|
|
143 |
|
} |