1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.user.internal; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Date; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Rule; |
28 |
|
import org.junit.Test; |
29 |
|
import org.xwiki.context.Execution; |
30 |
|
import org.xwiki.context.ExecutionContext; |
31 |
|
import org.xwiki.model.reference.DocumentReference; |
32 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
33 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
34 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
35 |
|
import org.xwiki.wiki.user.MembershipType; |
36 |
|
import org.xwiki.wiki.user.UserScope; |
37 |
|
import org.xwiki.wiki.user.WikiUserConfiguration; |
38 |
|
|
39 |
|
import com.xpn.xwiki.XWiki; |
40 |
|
import com.xpn.xwiki.XWikiContext; |
41 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
42 |
|
import com.xpn.xwiki.objects.BaseObject; |
43 |
|
import com.xpn.xwiki.store.migration.hibernate.HibernateDataMigration; |
44 |
|
|
45 |
|
import static org.mockito.ArgumentMatchers.any; |
46 |
|
import static org.mockito.ArgumentMatchers.eq; |
47 |
|
import static org.mockito.Mockito.mock; |
48 |
|
import static org.mockito.Mockito.times; |
49 |
|
import static org.mockito.Mockito.verify; |
50 |
|
import static org.mockito.Mockito.when; |
51 |
|
|
52 |
|
|
53 |
|
@link |
54 |
|
|
55 |
|
@since |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (80) |
Complexity: 4 |
Complexity Density: 0.05 |
|
57 |
|
public class WikiUserFromXEMMigrationTest |
58 |
|
{ |
59 |
|
@Rule |
60 |
|
public MockitoComponentMockingRule<WikiUserFromXEMMigration> mocker = |
61 |
|
new MockitoComponentMockingRule(WikiUserFromXEMMigration.class, HibernateDataMigration.class, |
62 |
|
"R530010WikiUserFromXEMMigration"); |
63 |
|
|
64 |
|
private WikiDescriptorManager wikiDescriptorManager; |
65 |
|
|
66 |
|
private WikiUserConfigurationHelper wikiUserConfigurationHelper; |
67 |
|
|
68 |
|
private Execution execution; |
69 |
|
|
70 |
|
private XWikiContext xcontext; |
71 |
|
|
72 |
|
private XWiki xwiki; |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
74 |
3 |
@Before... |
75 |
|
public void setUp() throws Exception |
76 |
|
{ |
77 |
3 |
wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
78 |
3 |
wikiUserConfigurationHelper = mocker.getInstance(WikiUserConfigurationHelper.class); |
79 |
3 |
execution = mock(Execution.class); |
80 |
3 |
mocker.registerComponent(Execution.class, execution); |
81 |
3 |
xcontext = mock(XWikiContext.class); |
82 |
3 |
xwiki = mock(XWiki.class); |
83 |
|
|
84 |
3 |
ExecutionContext executionContext = mock(ExecutionContext.class); |
85 |
3 |
when(execution.getContext()).thenReturn(executionContext); |
86 |
3 |
when(executionContext.getProperty("xwikicontext")).thenReturn(xcontext); |
87 |
3 |
when(xcontext.getWiki()).thenReturn(xwiki); |
88 |
3 |
when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki"); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
public void upgradeRegularSubWiki() throws Exception |
93 |
|
{ |
94 |
|
|
95 |
1 |
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki"); |
96 |
1 |
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class); |
97 |
1 |
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerSubwiki")), |
98 |
|
any(XWikiContext.class))).thenReturn(oldDescriptorDocument); |
99 |
1 |
when(oldDescriptorDocument.getXObject(eq(new DocumentReference("mainWiki", "WorkspaceManager", "WorkspaceClass") |
100 |
|
))).thenReturn(null); |
101 |
|
|
102 |
|
|
103 |
1 |
mocker.getComponentUnderTest().hibernateMigrate(); |
104 |
|
|
105 |
|
|
106 |
1 |
WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration(); |
107 |
1 |
expectedConfiguration.setUserScope(UserScope.LOCAL_AND_GLOBAL); |
108 |
1 |
expectedConfiguration.setMembershipType(MembershipType.INVITE); |
109 |
1 |
verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("subwiki")); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (44) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void upgradeWorkspace() throws Exception |
114 |
|
{ |
115 |
|
|
116 |
1 |
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspace"); |
117 |
1 |
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class); |
118 |
1 |
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspace")), |
119 |
|
any(XWikiContext.class))).thenReturn(oldDescriptorDocument); |
120 |
|
|
121 |
|
|
122 |
1 |
BaseObject oldObject = mock(BaseObject.class); |
123 |
1 |
when(oldDescriptorDocument.getXObject(eq(new DocumentReference("mainWiki", "WorkspaceManager", "WorkspaceClass") |
124 |
|
))).thenReturn(oldObject); |
125 |
1 |
when(oldObject.getStringValue("membershipType")).thenReturn("request"); |
126 |
|
|
127 |
|
|
128 |
1 |
DocumentReference memberGroupRef = new DocumentReference("workspace", XWiki.SYSTEM_SPACE, "XWikiAllGroup"); |
129 |
1 |
XWikiDocument memberGroupDoc = mock(XWikiDocument.class); |
130 |
1 |
when(xwiki.getDocument(eq(memberGroupRef), any(XWikiContext.class))).thenReturn(memberGroupDoc); |
131 |
1 |
DocumentReference candidacyOldClass = new DocumentReference("workspace", "XWiki", |
132 |
|
"WorkspaceCandidateMemberClass"); |
133 |
1 |
List<BaseObject> oldCandidacies = new ArrayList<>(); |
134 |
1 |
BaseObject oldCandidacy = mock(BaseObject.class); |
135 |
1 |
oldCandidacies.add(oldCandidacy); |
136 |
1 |
when(memberGroupDoc.getXObjects(eq(candidacyOldClass))).thenReturn(oldCandidacies); |
137 |
1 |
LocalDocumentReference newCandidacyClassRef = WikiCandidateMemberClassInitializer.REFERENCE; |
138 |
1 |
BaseObject newCandidacyObject = mock(BaseObject.class); |
139 |
1 |
when(memberGroupDoc.newXObject(eq(newCandidacyClassRef), any(XWikiContext.class))) |
140 |
|
.thenReturn(newCandidacyObject); |
141 |
1 |
when(oldCandidacy.getStringValue("type")).thenReturn("aa"); |
142 |
1 |
when(oldCandidacy.getStringValue("status")).thenReturn("bb"); |
143 |
1 |
when(oldCandidacy.getStringValue("userName")).thenReturn("cc"); |
144 |
1 |
when(oldCandidacy.getLargeStringValue("userComment")).thenReturn("dd"); |
145 |
1 |
when(oldCandidacy.getStringValue("reviewer")).thenReturn("ee"); |
146 |
1 |
when(oldCandidacy.getLargeStringValue("reviewerComment")).thenReturn("ff"); |
147 |
1 |
when(oldCandidacy.getLargeStringValue("reviewerPrivateComment")).thenReturn("gg"); |
148 |
1 |
when(oldCandidacy.getDateValue("date")).thenReturn(new Date(2000)); |
149 |
1 |
when(oldCandidacy.getDateValue("resolutionDate")).thenReturn(new Date(8000)); |
150 |
|
|
151 |
|
|
152 |
1 |
mocker.getComponentUnderTest().hibernateMigrate(); |
153 |
|
|
154 |
|
|
155 |
1 |
WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration(); |
156 |
1 |
expectedConfiguration.setUserScope(UserScope.GLOBAL_ONLY); |
157 |
1 |
expectedConfiguration.setMembershipType(MembershipType.REQUEST); |
158 |
1 |
verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("workspace")); |
159 |
|
|
160 |
|
|
161 |
1 |
verify(oldDescriptorDocument).removeXObject(oldObject); |
162 |
1 |
verify(xwiki, times(1)).saveDocument(oldDescriptorDocument, "[UPGRADE] Remove the old WorkspaceManager.WorkspaceClass" + |
163 |
|
" object.", xcontext); |
164 |
|
|
165 |
|
|
166 |
1 |
verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE, "aa"); |
167 |
1 |
verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, "bb"); |
168 |
1 |
verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_USER, "cc"); |
169 |
1 |
verify(newCandidacyObject).setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, "dd"); |
170 |
1 |
verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, "ee"); |
171 |
1 |
verify(newCandidacyObject).setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, "ff"); |
172 |
1 |
verify(newCandidacyObject).setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT, |
173 |
|
"gg"); |
174 |
1 |
verify(newCandidacyObject).setDateValue(eq(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION), |
175 |
|
eq(new Date(2000))); |
176 |
1 |
verify(newCandidacyObject).setDateValue(eq(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE), |
177 |
|
eq(new Date(8000))); |
178 |
|
|
179 |
|
|
180 |
1 |
verify(memberGroupDoc).removeXObject(oldCandidacy); |
181 |
1 |
verify(xwiki, times(1)).saveDocument(memberGroupDoc, "Upgrade candidacies from the old Workspace Application" + |
182 |
|
" to the new Wiki Application.", xcontext); |
183 |
|
|
184 |
|
} |
185 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
186 |
1 |
@Test... |
187 |
|
public void upgradeOldWorkspaceTemplate() throws Exception |
188 |
|
{ |
189 |
|
|
190 |
1 |
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspacetemplate"); |
191 |
1 |
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class); |
192 |
1 |
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspacetemplate")), |
193 |
|
any(XWikiContext.class))).thenReturn(oldDescriptorDocument); |
194 |
|
|
195 |
|
|
196 |
1 |
when(xwiki.exists(eq(new DocumentReference("workspacetemplate", "XWiki", "ManageWorkspace")), |
197 |
|
any(XWikiContext.class))).thenReturn(true); |
198 |
|
|
199 |
|
|
200 |
1 |
DocumentReference memberGroupRef = new DocumentReference("workspacetemplate", XWiki.SYSTEM_SPACE, |
201 |
|
"XWikiAllGroup"); |
202 |
1 |
XWikiDocument memberGroupDoc = mock(XWikiDocument.class); |
203 |
1 |
when(xwiki.getDocument(eq(memberGroupRef), any(XWikiContext.class))).thenReturn(memberGroupDoc); |
204 |
|
|
205 |
|
|
206 |
1 |
mocker.getComponentUnderTest().hibernateMigrate(); |
207 |
|
|
208 |
|
|
209 |
1 |
WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration(); |
210 |
1 |
expectedConfiguration.setUserScope(UserScope.GLOBAL_ONLY); |
211 |
1 |
expectedConfiguration.setMembershipType(MembershipType.INVITE); |
212 |
1 |
verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("workspacetemplate")); |
213 |
|
} |
214 |
|
|
215 |
|
} |