1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.repository.test; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.io.InputStream; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Arrays; |
26 |
|
import java.util.HashMap; |
27 |
|
import java.util.List; |
28 |
|
import java.util.Map; |
29 |
|
|
30 |
|
import org.xwiki.extension.Extension; |
31 |
|
import org.xwiki.extension.ExtensionAuthor; |
32 |
|
import org.xwiki.extension.ExtensionDependency; |
33 |
|
import org.xwiki.extension.ExtensionId; |
34 |
|
import org.xwiki.extension.RemoteExtension; |
35 |
|
import org.xwiki.extension.internal.converter.ExtensionIdConverter; |
36 |
|
import org.xwiki.extension.test.RepositoryUtils; |
37 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
38 |
|
import org.xwiki.repository.internal.XWikiRepositoryModel; |
39 |
|
import org.xwiki.rest.model.jaxb.Objects; |
40 |
|
import org.xwiki.rest.model.jaxb.Page; |
41 |
|
import org.xwiki.test.ui.TestUtils; |
42 |
|
|
43 |
|
import static org.xwiki.test.ui.TestUtils.RestTestUtils.object; |
44 |
|
import static org.xwiki.test.ui.TestUtils.RestTestUtils.property; |
45 |
|
|
46 |
|
|
47 |
|
@version |
48 |
|
@since |
49 |
|
|
|
|
| 85.2% |
Uncovered Elements: 19 (128) |
Complexity: 36 |
Complexity Density: 0.45 |
|
50 |
|
public class RepositoryTestUtils |
51 |
|
{ |
52 |
|
public final static String PROPERTY_KEY = "repositoryutils"; |
53 |
|
|
54 |
|
private final static String SPACENAME_EXTENSION = "Extension"; |
55 |
|
|
56 |
|
|
57 |
|
@since |
58 |
|
|
|
|
| 83.3% |
Uncovered Elements: 5 (30) |
Complexity: 7 |
Complexity Density: 0.35 |
|
59 |
15 |
public static org.xwiki.rest.model.jaxb.Object extensionObject(RemoteExtension extension)... |
60 |
|
{ |
61 |
15 |
org.xwiki.rest.model.jaxb.Object extensionObject = object(XWikiRepositoryModel.EXTENSION_CLASSNAME); |
62 |
|
|
63 |
15 |
extensionObject.getProperties() |
64 |
|
.add(property(XWikiRepositoryModel.PROP_EXTENSION_ID, extension.getId().getId())); |
65 |
15 |
extensionObject.getProperties().add(property(XWikiRepositoryModel.PROP_EXTENSION_TYPE, extension.getType())); |
66 |
15 |
extensionObject.getProperties().add(property(XWikiRepositoryModel.PROP_EXTENSION_NAME, extension.getName())); |
67 |
15 |
extensionObject.getProperties() |
68 |
|
.add(property(XWikiRepositoryModel.PROP_EXTENSION_SUMMARY, extension.getSummary())); |
69 |
15 |
extensionObject.getProperties() |
70 |
15 |
.add(property(XWikiRepositoryModel.PROP_EXTENSION_RECOMMENDED, extension.isRecommended() ? 1 : 0)); |
71 |
15 |
if (!extension.getLicenses().isEmpty()) { |
72 |
1 |
extensionObject.getProperties().add(property(XWikiRepositoryModel.PROP_EXTENSION_LICENSENAME, |
73 |
|
extension.getLicenses().iterator().next().getName())); |
74 |
|
} |
75 |
15 |
extensionObject.getProperties().add(property(XWikiRepositoryModel.PROP_EXTENSION_FEATURES, |
76 |
|
ExtensionIdConverter.toStringList(extension.getExtensionFeatures()))); |
77 |
15 |
List<String> authors = new ArrayList<String>(); |
78 |
15 |
for (ExtensionAuthor author : extension.getAuthors()) { |
79 |
2 |
authors.add(author.getName()); |
80 |
|
} |
81 |
15 |
extensionObject.getProperties().add(property(XWikiRepositoryModel.PROP_EXTENSION_AUTHORS, authors)); |
82 |
15 |
extensionObject.getProperties() |
83 |
|
.add(property(XWikiRepositoryModel.PROP_EXTENSION_WEBSITE, extension.getWebSite())); |
84 |
15 |
if (extension.getAllowedNamespaces() != null) { |
85 |
0 |
extensionObject.getProperties() |
86 |
|
.add(property(XWikiRepositoryModel.PROP_EXTENSION_ALLOWEDNAMESPACES, extension.getAllowedNamespaces())); |
87 |
0 |
extensionObject.getProperties().add(property(XWikiRepositoryModel.PROP_EXTENSION_ALLOWEDNAMESPACES_EMPTY, |
88 |
0 |
extension.getAllowedNamespaces() != null && extension.getAllowedNamespaces().isEmpty() ? 1 : 0)); |
89 |
|
} |
90 |
15 |
if (extension.getScm() != null) { |
91 |
1 |
extensionObject.getProperties() |
92 |
|
.add(property(XWikiRepositoryModel.PROP_EXTENSION_SCMURL, extension.getScm().getUrl())); |
93 |
|
} |
94 |
15 |
return extensionObject; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
@since |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
100 |
15 |
public static org.xwiki.rest.model.jaxb.Object extensionVersionObject(Extension extension)... |
101 |
|
{ |
102 |
15 |
org.xwiki.rest.model.jaxb.Object extensionVersionObject = extensionVersionObject(extension.getId().getVersion(), |
103 |
|
null, XWikiRepositoryModel.toStringList(extension.getRepositories())); |
104 |
|
|
105 |
15 |
extensionVersionObject.getProperties().add(property(XWikiRepositoryModel.PROP_VERSION_FEATURES, |
106 |
|
ExtensionIdConverter.toStringList(extension.getExtensionFeatures()))); |
107 |
|
|
108 |
15 |
return extensionVersionObject; |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
@since |
113 |
|
|
|
|
| 71.4% |
Uncovered Elements: 4 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
114 |
15 |
public static org.xwiki.rest.model.jaxb.Object extensionVersionObject(Object version, Object download,... |
115 |
|
Object repositories) |
116 |
|
{ |
117 |
15 |
org.xwiki.rest.model.jaxb.Object versionObject = object(XWikiRepositoryModel.EXTENSIONVERSION_CLASSNAME); |
118 |
|
|
119 |
15 |
if (version != null) { |
120 |
15 |
versionObject.getProperties().add(property(XWikiRepositoryModel.PROP_VERSION_VERSION, version)); |
121 |
|
} |
122 |
15 |
if (download != null) { |
123 |
0 |
versionObject.getProperties().add(property(XWikiRepositoryModel.PROP_VERSION_DOWNLOAD, download)); |
124 |
|
} |
125 |
15 |
if (repositories != null) { |
126 |
15 |
versionObject.getProperties().add(property(XWikiRepositoryModel.PROP_VERSION_REPOSITORIES, repositories)); |
127 |
|
} |
128 |
|
|
129 |
15 |
return versionObject; |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
@since |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
135 |
15 |
public static List<org.xwiki.rest.model.jaxb.Object> extensionDependencyObjects(Extension extension)... |
136 |
|
{ |
137 |
15 |
List<org.xwiki.rest.model.jaxb.Object> dependencies = new ArrayList<>(extension.getDependencies().size()); |
138 |
|
|
139 |
15 |
int number = 0; |
140 |
15 |
for (ExtensionDependency dependency : extension.getDependencies()) { |
141 |
8 |
org.xwiki.rest.model.jaxb.Object dependencyObject = |
142 |
|
extensionDependencyObject(extension.getId().getVersion(), dependency); |
143 |
8 |
dependencyObject.setNumber(number++); |
144 |
|
|
145 |
8 |
dependencies.add(dependencyObject); |
146 |
|
} |
147 |
|
|
148 |
15 |
return dependencies; |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
@since |
153 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
154 |
8 |
public static org.xwiki.rest.model.jaxb.Object extensionDependencyObject(Object version,... |
155 |
|
ExtensionDependency dependency) |
156 |
|
{ |
157 |
8 |
org.xwiki.rest.model.jaxb.Object dependencyObject = object(XWikiRepositoryModel.EXTENSIONDEPENDENCY_CLASSNAME); |
158 |
|
|
159 |
8 |
dependencyObject.getProperties() |
160 |
|
.add(property(XWikiRepositoryModel.PROP_DEPENDENCY_CONSTRAINT, dependency.getVersionConstraint())); |
161 |
|
|
162 |
8 |
dependencyObject.getProperties().add(property(XWikiRepositoryModel.PROP_DEPENDENCY_EXTENSIONVERSION, version)); |
163 |
|
|
164 |
8 |
dependencyObject.getProperties().add(property(XWikiRepositoryModel.PROP_DEPENDENCY_ID, dependency.getId())); |
165 |
|
|
166 |
8 |
return dependencyObject; |
167 |
|
} |
168 |
|
|
169 |
|
private final TestUtils testUtils; |
170 |
|
|
171 |
|
private RepositoryUtils repositoryUtil; |
172 |
|
|
173 |
|
private SolrTestUtils solrUtils; |
174 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
175 |
4 |
public RepositoryTestUtils(TestUtils testUtils, RepositoryUtils repositoryUtil, SolrTestUtils solrUtils)... |
176 |
|
{ |
177 |
4 |
this.testUtils = testUtils; |
178 |
4 |
this.repositoryUtil = repositoryUtil != null ? repositoryUtil : new RepositoryUtils(); |
179 |
4 |
this.solrUtils = solrUtils; |
180 |
|
} |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
20 |
public RepositoryUtils getRepositoryUtil()... |
183 |
|
{ |
184 |
20 |
return this.repositoryUtil; |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
4 |
public void init() throws Exception... |
190 |
|
{ |
191 |
|
|
192 |
4 |
this.repositoryUtil.setup(); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
197 |
24 |
public TestExtension getTestExtension(ExtensionId id, String type)... |
198 |
|
{ |
199 |
24 |
File extensionFile = this.repositoryUtil.getExtensionPackager().getExtensionFile(id); |
200 |
|
|
201 |
24 |
return extensionFile != null ? new TestExtension(id, type, extensionFile) : null; |
202 |
|
} |
203 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
204 |
57 |
private LocalDocumentReference getExtensionPageReference(Extension extension)... |
205 |
|
{ |
206 |
57 |
String extensionName = extension.getName() != null ? extension.getName() : extension.getId().getId(); |
207 |
|
|
208 |
57 |
return getExtensionPageReference(extensionName); |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
@since |
213 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
214 |
132 |
private LocalDocumentReference getExtensionPageReference(String extensionName)... |
215 |
|
{ |
216 |
132 |
return new LocalDocumentReference(Arrays.asList(SPACENAME_EXTENSION, extensionName), "WebHome"); |
217 |
|
} |
218 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
0 |
public void deleteExtension(Extension extension) throws Exception... |
220 |
|
{ |
221 |
0 |
this.testUtils.rest().delete(getExtensionPageReference(extension)); |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
@since |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
75 |
public void deleteExtension(String extensionName) throws Exception... |
228 |
|
{ |
229 |
75 |
this.testUtils.rest().delete(getExtensionPageReference(extensionName)); |
230 |
|
} |
231 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
232 |
15 |
public void addExtension(RemoteExtension extension) throws Exception... |
233 |
|
{ |
234 |
|
|
235 |
15 |
this.testUtils.rest().delete(getExtensionPageReference(extension)); |
236 |
|
|
237 |
|
|
238 |
15 |
Page extensionPage = this.testUtils.rest().page(getExtensionPageReference(extension)); |
239 |
|
|
240 |
15 |
extensionPage.setObjects(new Objects()); |
241 |
|
|
242 |
|
|
243 |
15 |
extensionPage.getObjects().getObjectSummaries().add(extensionObject(extension)); |
244 |
|
|
245 |
|
|
246 |
15 |
extensionPage.getObjects().getObjectSummaries().add(extensionVersionObject(extension)); |
247 |
|
|
248 |
|
|
249 |
15 |
extensionPage.getObjects().getObjectSummaries().addAll(extensionDependencyObjects(extension)); |
250 |
|
|
251 |
|
|
252 |
15 |
this.testUtils.rest().save(extensionPage, TestUtils.STATUS_CREATED); |
253 |
|
|
254 |
|
|
255 |
15 |
attachFile(extension); |
256 |
|
} |
257 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
258 |
1 |
public void addVersionObject(Extension extension)... |
259 |
|
{ |
260 |
1 |
addVersionObject(extension, extension.getId().getVersion(), null); |
261 |
|
} |
262 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
263 |
6 |
public void addVersionObject(Extension extension, Object version, Object download)... |
264 |
|
{ |
265 |
6 |
Map<String, Object> queryParameters = new HashMap<String, Object>(); |
266 |
|
|
267 |
6 |
if (version != null) { |
268 |
6 |
queryParameters.put(XWikiRepositoryModel.PROP_VERSION_VERSION, version); |
269 |
|
} |
270 |
6 |
if (download != null) { |
271 |
5 |
queryParameters.put(XWikiRepositoryModel.PROP_VERSION_DOWNLOAD, download); |
272 |
|
} |
273 |
|
|
274 |
6 |
this.testUtils.addObject(getExtensionPageReference(extension), XWikiRepositoryModel.EXTENSIONVERSION_CLASSNAME, |
275 |
|
queryParameters); |
276 |
|
} |
277 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
278 |
0 |
public void addDependencies(Extension extension)... |
279 |
|
{ |
280 |
0 |
addDependencies(extension, extension.getId().getVersion()); |
281 |
|
} |
282 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
283 |
1 |
public void addDependencies(Extension extension, Object version)... |
284 |
|
{ |
285 |
1 |
for (ExtensionDependency dependency : extension.getDependencies()) { |
286 |
2 |
addDependency(extension, version, dependency); |
287 |
|
} |
288 |
|
} |
289 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
290 |
0 |
public void addDependency(Extension extension, ExtensionDependency dependency)... |
291 |
|
{ |
292 |
0 |
addDependency(extension, extension.getId().getVersion(), dependency); |
293 |
|
} |
294 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
295 |
2 |
public void addDependency(Extension extension, Object version, ExtensionDependency dependency)... |
296 |
|
{ |
297 |
2 |
this.testUtils.addObject(getExtensionPageReference(extension), |
298 |
|
XWikiRepositoryModel.EXTENSIONDEPENDENCY_CLASSNAME, XWikiRepositoryModel.PROP_DEPENDENCY_CONSTRAINT, |
299 |
|
dependency.getVersionConstraint(), XWikiRepositoryModel.PROP_DEPENDENCY_ID, dependency.getId(), |
300 |
|
XWikiRepositoryModel.PROP_DEPENDENCY_EXTENSIONVERSION, version); |
301 |
|
} |
302 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
303 |
19 |
public void attachFile(Extension extension) throws Exception... |
304 |
|
{ |
305 |
19 |
InputStream is = extension.getFile().openStream(); |
306 |
19 |
try { |
307 |
19 |
this.testUtils.attachFile(getExtensionPageReference(extension), |
308 |
|
extension.getId().getId() + "-" + extension.getId().getVersion() + "." + extension.getType(), is, true); |
309 |
|
} finally { |
310 |
19 |
is.close(); |
311 |
|
} |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
317 |
18 |
public void waitUntilReady() throws Exception... |
318 |
|
{ |
319 |
|
|
320 |
18 |
this.solrUtils.waitEmpyQueue(); |
321 |
|
} |
322 |
|
} |