1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.test; |
21 |
|
|
22 |
|
import java.io.InputStream; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import org.apache.commons.httpclient.UsernamePasswordCredentials; |
27 |
|
import org.apache.commons.io.IOUtils; |
28 |
|
import org.openqa.selenium.By; |
29 |
|
import org.xwiki.extension.ExtensionId; |
30 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
31 |
|
import org.xwiki.test.ui.TestUtils; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 96.3% |
Uncovered Elements: 1 (27) |
Complexity: 9 |
Complexity Density: 0.43 |
|
39 |
|
public class ExtensionTestUtils |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
public final static String PROPERTY_KEY = "extensionUtils"; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
private static final LocalDocumentReference SERVICE_REFERENCE = new LocalDocumentReference("ExtensionTest", "Service"); |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
private final TestUtils utils; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@param |
60 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 4 |
Complexity Density: 0.57 |
|
61 |
2 |
public ExtensionTestUtils(TestUtils utils)... |
62 |
|
{ |
63 |
2 |
this.utils = utils; |
64 |
|
|
65 |
|
|
66 |
2 |
try (InputStream extensionTestService = this.getClass().getResourceAsStream("/extensionTestService.wiki")) { |
67 |
|
|
68 |
2 |
UsernamePasswordCredentials currentCredentials = |
69 |
|
utils.setDefaultCredentials(TestUtils.SUPER_ADMIN_CREDENTIALS); |
70 |
|
|
71 |
|
|
72 |
2 |
utils.rest().savePage(SERVICE_REFERENCE, IOUtils.toString(extensionTestService), ""); |
73 |
|
|
74 |
|
|
75 |
2 |
utils.setDefaultCredentials(currentCredentials); |
76 |
|
} catch (Exception e) { |
77 |
0 |
throw new RuntimeException("Failed to setup the service", e); |
78 |
|
} |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
@param |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
45 |
public void uninstall(String extensionId)... |
87 |
|
{ |
88 |
45 |
uninstall(extensionId, false); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
@param |
95 |
|
@param |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
97 |
46 |
public void uninstall(String extensionId, boolean keepLocalCache)... |
98 |
|
{ |
99 |
46 |
Map<String, String> parameters = new HashMap<String, String>(); |
100 |
46 |
parameters.put("extensionId", extensionId); |
101 |
46 |
parameters.put("keepLocalCache", String.valueOf(keepLocalCache)); |
102 |
46 |
doAction("uninstall", parameters); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
@param |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
110 |
6 |
public void install(ExtensionId extensionId)... |
111 |
|
{ |
112 |
6 |
Map<String, String> parameters = new HashMap<String, String>(); |
113 |
6 |
parameters.put("extensionId", extensionId.getId()); |
114 |
6 |
parameters.put("extensionVersion", extensionId.getVersion().getValue()); |
115 |
6 |
doAction("install", parameters); |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
121 |
15 |
public void finishCurrentJob()... |
122 |
|
{ |
123 |
15 |
doAction("finish", new HashMap<String, String>()); |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
126 |
67 |
private void doAction(String action, Map<String, String> parameters)... |
127 |
|
{ |
128 |
67 |
parameters.put("action", action); |
129 |
67 |
parameters.put("outputSyntax", "plain"); |
130 |
67 |
utils.gotoPage(SERVICE_REFERENCE, "get", parameters); |
131 |
67 |
utils.getDriver().waitUntilElementHasTextContent(By.tagName("body"), "Done!"); |
132 |
|
} |
133 |
|
} |