| 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.util.Collection; |
| 23 |
|
import java.util.List; |
| 24 |
|
|
| 25 |
|
import org.junit.Before; |
| 26 |
|
import org.junit.Rule; |
| 27 |
|
import org.xwiki.cache.CacheManager; |
| 28 |
|
import org.xwiki.extension.ExtensionId; |
| 29 |
|
import org.xwiki.extension.InstalledExtension; |
| 30 |
|
import org.xwiki.extension.LocalExtension; |
| 31 |
|
import org.xwiki.extension.job.InstallRequest; |
| 32 |
|
import org.xwiki.extension.job.UninstallRequest; |
| 33 |
|
import org.xwiki.extension.job.plan.ExtensionPlan; |
| 34 |
|
import org.xwiki.extension.job.plan.ExtensionPlanNode; |
| 35 |
|
import org.xwiki.extension.job.plan.internal.DefaultExtensionPlan; |
| 36 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
| 37 |
|
import org.xwiki.extension.repository.LocalExtensionRepository; |
| 38 |
|
import org.xwiki.extension.repository.internal.core.CoreExtensionScanner; |
| 39 |
|
import org.xwiki.job.Job; |
| 40 |
|
import org.xwiki.job.JobExecutor; |
| 41 |
|
import org.xwiki.job.Request; |
| 42 |
|
import org.xwiki.logging.LogLevel; |
| 43 |
|
import org.xwiki.logging.event.LogEvent; |
| 44 |
|
import org.xwiki.test.annotation.AfterComponent; |
| 45 |
|
import org.xwiki.test.annotation.AllComponents; |
| 46 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
| 47 |
|
|
| 48 |
|
@AllComponents |
| |
|
| 87.6% |
Uncovered Elements: 15 (121) |
Complexity: 45 |
Complexity Density: 0.67 |
|
| 49 |
|
public abstract class AbstractExtensionHandlerTest |
| 50 |
|
{ |
| 51 |
|
protected MockitoComponentManagerRule mocker = new MockitoComponentManagerRule(); |
| 52 |
|
|
| 53 |
|
@Rule |
| 54 |
|
public MockitoRepositoryUtilsRule repositoryUtil = new MockitoRepositoryUtilsRule(this.mocker); |
| 55 |
|
|
| 56 |
|
protected LocalExtensionRepository localExtensionRepository; |
| 57 |
|
|
| 58 |
|
protected InstalledExtensionRepository installedExtensionRepository; |
| 59 |
|
|
| 60 |
|
protected JobExecutor jobExecutor; |
| 61 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 62 |
77 |
@AfterComponent... |
| 63 |
|
public void afterComponent() throws Exception |
| 64 |
|
{ |
| 65 |
|
|
| 66 |
77 |
this.mocker.registerMockComponent(CoreExtensionScanner.class); |
| 67 |
|
} |
| 68 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 69 |
77 |
@Before... |
| 70 |
|
public void setUp() throws Exception |
| 71 |
|
{ |
| 72 |
77 |
this.jobExecutor = this.mocker.getInstance(JobExecutor.class); |
| 73 |
77 |
this.localExtensionRepository = this.mocker.getInstance(LocalExtensionRepository.class); |
| 74 |
77 |
this.installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class); |
| 75 |
|
|
| 76 |
77 |
this.mocker.registerMockComponent(CacheManager.class); |
| 77 |
|
} |
| 78 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 79 |
4 |
protected ExtensionPlanNode getNode(ExtensionId id, Collection<ExtensionPlanNode> nodes)... |
| 80 |
|
{ |
| 81 |
4 |
for (ExtensionPlanNode node : nodes) { |
| 82 |
6 |
if (node.getAction().getExtension().getId().equals(id)) { |
| 83 |
4 |
return node; |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
|
| 87 |
0 |
return null; |
| 88 |
|
} |
| 89 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 90 |
158 |
protected Job executeJob(String jobId, Request request, LogLevel failFrom) throws Throwable... |
| 91 |
|
{ |
| 92 |
158 |
Job installJob = this.jobExecutor.execute(jobId, request); |
| 93 |
|
|
| 94 |
158 |
installJob.join(); |
| 95 |
|
|
| 96 |
158 |
List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(failFrom); |
| 97 |
158 |
if (!errors.isEmpty()) { |
| 98 |
13 |
throw errors.get(0).getThrowable() != null ? errors.get(0).getThrowable() |
| 99 |
|
: new Exception(errors.get(0).getFormattedMessage()); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
145 |
return installJob; |
| 103 |
|
} |
| 104 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 105 |
41 |
protected InstalledExtension install(ExtensionId extensionId) throws Throwable... |
| 106 |
|
{ |
| 107 |
41 |
return install(extensionId, true); |
| 108 |
|
} |
| 109 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
41 |
protected InstalledExtension install(ExtensionId extensionId, boolean rootModifications) throws Throwable... |
| 111 |
|
{ |
| 112 |
41 |
return install(extensionId, (String[]) null, rootModifications); |
| 113 |
|
} |
| 114 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 115 |
1 |
protected InstalledExtension install(ExtensionId extensionId, String[] namespaces) throws Throwable... |
| 116 |
|
{ |
| 117 |
1 |
return install(extensionId, namespaces, true); |
| 118 |
|
} |
| 119 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 120 |
42 |
protected InstalledExtension install(ExtensionId extensionId, String[] namespaces, boolean rootModifications)... |
| 121 |
|
throws Throwable |
| 122 |
|
{ |
| 123 |
42 |
return install(extensionId, namespaces, rootModifications, LogLevel.WARN); |
| 124 |
|
} |
| 125 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 126 |
38 |
protected InstalledExtension install(ExtensionId extensionId, String namespace) throws Throwable... |
| 127 |
|
{ |
| 128 |
38 |
return install(extensionId, namespace, true); |
| 129 |
|
} |
| 130 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 131 |
39 |
protected InstalledExtension install(ExtensionId extensionId, String namespace, boolean rootModifications)... |
| 132 |
|
throws Throwable |
| 133 |
|
{ |
| 134 |
39 |
return install(extensionId, namespace, rootModifications, LogLevel.WARN); |
| 135 |
|
} |
| 136 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 137 |
4 |
protected InstalledExtension install(ExtensionId extensionId, String namespace, LogLevel failFrom) throws Throwable... |
| 138 |
|
{ |
| 139 |
4 |
return install(extensionId, namespace, true, failFrom); |
| 140 |
|
} |
| 141 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 142 |
43 |
protected InstalledExtension install(ExtensionId extensionId, String namespace, boolean rootModifications,... |
| 143 |
|
LogLevel failFrom) throws Throwable |
| 144 |
|
{ |
| 145 |
43 |
return install(extensionId, namespace != null ? new String[] { namespace } : (String[]) null, rootModifications, |
| 146 |
|
failFrom); |
| 147 |
|
} |
| 148 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 149 |
0 |
protected InstalledExtension install(ExtensionId extensionId, String[] namespaces, LogLevel failFrom)... |
| 150 |
|
throws Throwable |
| 151 |
|
{ |
| 152 |
0 |
return install(extensionId, namespaces, true, failFrom); |
| 153 |
|
} |
| 154 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 155 |
85 |
protected InstalledExtension install(ExtensionId extensionId, String[] namespaces, boolean rootModifications,... |
| 156 |
|
LogLevel failFrom) throws Throwable |
| 157 |
|
{ |
| 158 |
85 |
install("install", extensionId, namespaces, rootModifications, failFrom); |
| 159 |
|
|
| 160 |
82 |
return this.installedExtensionRepository.resolve(extensionId); |
| 161 |
|
} |
| 162 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 163 |
19 |
protected ExtensionPlan installPlan(ExtensionId extensionId) throws Throwable... |
| 164 |
|
{ |
| 165 |
19 |
return installPlan(extensionId, true); |
| 166 |
|
} |
| 167 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 168 |
20 |
protected ExtensionPlan installPlan(ExtensionId extensionId, boolean rootModifications) throws Throwable... |
| 169 |
|
{ |
| 170 |
20 |
return installPlan(extensionId, (String[]) null, rootModifications); |
| 171 |
|
} |
| 172 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 173 |
0 |
protected ExtensionPlan installPlan(ExtensionId extensionId, String[] namespaces) throws Throwable... |
| 174 |
|
{ |
| 175 |
0 |
return installPlan(extensionId, namespaces, true); |
| 176 |
|
} |
| 177 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 178 |
20 |
protected ExtensionPlan installPlan(ExtensionId extensionId, String[] namespaces, boolean rootModifications)... |
| 179 |
|
throws Throwable |
| 180 |
|
{ |
| 181 |
20 |
return installPlan(extensionId, namespaces, rootModifications, LogLevel.WARN); |
| 182 |
|
} |
| 183 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 184 |
6 |
protected ExtensionPlan installPlan(ExtensionId extensionId, String namespace) throws Throwable... |
| 185 |
|
{ |
| 186 |
6 |
return installPlan(extensionId, namespace, true); |
| 187 |
|
} |
| 188 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 189 |
8 |
protected ExtensionPlan installPlan(ExtensionId extensionId, String namespace, boolean rootModifications)... |
| 190 |
|
throws Throwable |
| 191 |
|
{ |
| 192 |
8 |
return installPlan(extensionId, namespace != null ? new String[] { namespace } : null, rootModifications, |
| 193 |
|
LogLevel.WARN); |
| 194 |
|
} |
| 195 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 196 |
0 |
protected ExtensionPlan installPlan(ExtensionId extensionId, String[] namespaces, LogLevel failFrom)... |
| 197 |
|
throws Throwable |
| 198 |
|
{ |
| 199 |
0 |
return installPlan(extensionId, namespaces, true, failFrom); |
| 200 |
|
} |
| 201 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 202 |
28 |
protected ExtensionPlan installPlan(ExtensionId extensionId, String[] namespaces, boolean rootModifications,... |
| 203 |
|
LogLevel failFrom) throws Throwable |
| 204 |
|
{ |
| 205 |
28 |
Job installJob = install("installplan", extensionId, namespaces, rootModifications, failFrom); |
| 206 |
|
|
| 207 |
19 |
return (ExtensionPlan) installJob.getStatus(); |
| 208 |
|
} |
| 209 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 210 |
3 |
protected Job install(String jobId, ExtensionId extensionId, String[] namespaces, LogLevel failFrom)... |
| 211 |
|
throws Throwable |
| 212 |
|
{ |
| 213 |
3 |
return install(jobId, extensionId, namespaces, true, failFrom); |
| 214 |
|
} |
| 215 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 216 |
116 |
protected Job install(String jobId, ExtensionId extensionId, String[] namespaces, boolean rootModifications,... |
| 217 |
|
LogLevel failFrom) throws Throwable |
| 218 |
|
{ |
| 219 |
116 |
InstallRequest installRequest = createInstallRequest(extensionId, namespaces, rootModifications); |
| 220 |
|
|
| 221 |
116 |
return executeJob(jobId, installRequest, failFrom); |
| 222 |
|
} |
| 223 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 224 |
116 |
protected InstallRequest createInstallRequest(ExtensionId extensionId, String[] namespaces,... |
| 225 |
|
boolean rootModifications) |
| 226 |
|
{ |
| 227 |
116 |
InstallRequest installRequest = new InstallRequest(); |
| 228 |
116 |
installRequest.addExtension(extensionId); |
| 229 |
116 |
if (namespaces != null) { |
| 230 |
53 |
for (String namespace : namespaces) { |
| 231 |
54 |
installRequest.addNamespace(namespace); |
| 232 |
|
} |
| 233 |
|
} |
| 234 |
116 |
installRequest.setRootModificationsAllowed(rootModifications); |
| 235 |
|
|
| 236 |
116 |
return installRequest; |
| 237 |
|
} |
| 238 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 239 |
31 |
protected LocalExtension uninstall(ExtensionId extensionId, String namespace) throws Throwable... |
| 240 |
|
{ |
| 241 |
31 |
return uninstall(extensionId, namespace, LogLevel.WARN); |
| 242 |
|
} |
| 243 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 244 |
34 |
protected LocalExtension uninstall(ExtensionId extensionId, String namespace, LogLevel failFrom) throws Throwable... |
| 245 |
|
{ |
| 246 |
34 |
uninstall("uninstall", extensionId, namespace, failFrom); |
| 247 |
|
|
| 248 |
33 |
return this.localExtensionRepository.resolve(extensionId); |
| 249 |
|
} |
| 250 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 251 |
0 |
protected DefaultExtensionPlan<UninstallRequest> uninstallPlan(ExtensionId extensionId, String namespace,... |
| 252 |
|
LogLevel failFrom) throws Throwable |
| 253 |
|
{ |
| 254 |
0 |
Job uninstallJob = uninstall("installplan", extensionId, namespace, failFrom); |
| 255 |
|
|
| 256 |
0 |
return (DefaultExtensionPlan<UninstallRequest>) uninstallJob.getStatus(); |
| 257 |
|
} |
| 258 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 259 |
34 |
protected Job uninstall(String jobId, ExtensionId extensionId, String namespace, LogLevel failFrom) throws Throwable... |
| 260 |
|
{ |
| 261 |
34 |
UninstallRequest uninstallRequest = new UninstallRequest(); |
| 262 |
34 |
uninstallRequest.addExtension(extensionId); |
| 263 |
34 |
if (namespace != null) { |
| 264 |
11 |
uninstallRequest.addNamespace(namespace); |
| 265 |
|
} |
| 266 |
|
|
| 267 |
34 |
return executeJob(jobId, uninstallRequest, failFrom); |
| 268 |
|
} |
| 269 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 270 |
2 |
protected ExtensionPlan upgradePlan() throws Throwable... |
| 271 |
|
{ |
| 272 |
2 |
return upgradePlan((String) null); |
| 273 |
|
} |
| 274 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 275 |
4 |
protected ExtensionPlan upgradePlan(String namespace) throws Throwable... |
| 276 |
|
{ |
| 277 |
4 |
return upgradePlan(namespace, (Collection<ExtensionId>) null); |
| 278 |
|
} |
| 279 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 280 |
7 |
protected ExtensionPlan upgradePlan(String namespace, Collection<ExtensionId> excludedExtensions) throws Throwable... |
| 281 |
|
{ |
| 282 |
7 |
return upgradePlan(namespace, excludedExtensions, LogLevel.WARN); |
| 283 |
|
} |
| 284 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 285 |
0 |
protected ExtensionPlan upgradePlan(String namespace, LogLevel failFrom) throws Throwable... |
| 286 |
|
{ |
| 287 |
0 |
return upgradePlan(namespace, null, failFrom); |
| 288 |
|
} |
| 289 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 290 |
7 |
protected ExtensionPlan upgradePlan(String namespace, Collection<ExtensionId> excludedExtensions, LogLevel failFrom)... |
| 291 |
|
throws Throwable |
| 292 |
|
{ |
| 293 |
7 |
InstallRequest installRequest = new InstallRequest(); |
| 294 |
7 |
if (namespace != null) { |
| 295 |
2 |
installRequest.addNamespace(namespace); |
| 296 |
|
} |
| 297 |
7 |
if (excludedExtensions != null) { |
| 298 |
3 |
installRequest.getExcludedExtensions().addAll(excludedExtensions); |
| 299 |
|
} |
| 300 |
|
|
| 301 |
7 |
return (ExtensionPlan) executeJob("upgradeplan", installRequest, failFrom).getStatus(); |
| 302 |
|
} |
| 303 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 304 |
1 |
protected ExtensionPlan upgradePlan(InstallRequest installRequest) throws Throwable... |
| 305 |
|
{ |
| 306 |
1 |
return upgradePlan(installRequest, LogLevel.WARN); |
| 307 |
|
} |
| 308 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 309 |
1 |
protected ExtensionPlan upgradePlan(InstallRequest installRequest, LogLevel failFrom) throws Throwable... |
| 310 |
|
{ |
| 311 |
1 |
return (ExtensionPlan) executeJob("upgradeplan", installRequest, failFrom).getStatus(); |
| 312 |
|
} |
| 313 |
|
} |