| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.test; |
| 21 |
|
|
| 22 |
|
import java.io.File; |
| 23 |
|
import java.util.ArrayList; |
| 24 |
|
import java.util.Date; |
| 25 |
|
import java.util.List; |
| 26 |
|
import java.util.Locale; |
| 27 |
|
import java.util.Map; |
| 28 |
|
import java.util.concurrent.ConcurrentHashMap; |
| 29 |
|
|
| 30 |
|
import javax.inject.Provider; |
| 31 |
|
import javax.script.ScriptContext; |
| 32 |
|
import javax.script.SimpleScriptContext; |
| 33 |
|
import javax.servlet.ServletContext; |
| 34 |
|
|
| 35 |
|
import org.apache.commons.lang3.StringUtils; |
| 36 |
|
import org.junit.rules.MethodRule; |
| 37 |
|
import org.junit.runners.model.FrameworkMethod; |
| 38 |
|
import org.junit.runners.model.Statement; |
| 39 |
|
import org.mockito.internal.util.MockUtil; |
| 40 |
|
import org.mockito.invocation.InvocationOnMock; |
| 41 |
|
import org.mockito.stubbing.Answer; |
| 42 |
|
import org.xwiki.bridge.event.DocumentCreatedEvent; |
| 43 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
| 44 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
| 45 |
|
import org.xwiki.component.descriptor.DefaultComponentDescriptor; |
| 46 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 47 |
|
import org.xwiki.component.manager.ComponentManager; |
| 48 |
|
import org.xwiki.configuration.ConfigurationSource; |
| 49 |
|
import org.xwiki.configuration.internal.MemoryConfigurationSource; |
| 50 |
|
import org.xwiki.context.Execution; |
| 51 |
|
import org.xwiki.context.ExecutionContext; |
| 52 |
|
import org.xwiki.context.ExecutionContextManager; |
| 53 |
|
import org.xwiki.environment.Environment; |
| 54 |
|
import org.xwiki.environment.internal.ServletEnvironment; |
| 55 |
|
import org.xwiki.model.reference.DocumentReference; |
| 56 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
| 57 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
| 58 |
|
import org.xwiki.model.reference.WikiReference; |
| 59 |
|
import org.xwiki.observation.ObservationManager; |
| 60 |
|
import org.xwiki.query.QueryManager; |
| 61 |
|
import org.xwiki.rendering.syntax.Syntax; |
| 62 |
|
import org.xwiki.script.ScriptContextManager; |
| 63 |
|
import org.xwiki.script.internal.ScriptExecutionContextInitializer; |
| 64 |
|
import org.xwiki.security.authorization.AuthorizationManager; |
| 65 |
|
import org.xwiki.security.authorization.ContextualAuthorizationManager; |
| 66 |
|
import org.xwiki.test.annotation.AllComponents; |
| 67 |
|
import org.xwiki.test.internal.MockConfigurationSource; |
| 68 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
| 69 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
| 70 |
|
|
| 71 |
|
import com.xpn.xwiki.CoreConfiguration; |
| 72 |
|
import com.xpn.xwiki.XWiki; |
| 73 |
|
import com.xpn.xwiki.XWikiContext; |
| 74 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
| 75 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 76 |
|
import com.xpn.xwiki.internal.XWikiCfgConfigurationSource; |
| 77 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
| 78 |
|
import com.xpn.xwiki.store.XWikiHibernateStore; |
| 79 |
|
import com.xpn.xwiki.store.XWikiStoreInterface; |
| 80 |
|
import com.xpn.xwiki.store.XWikiVersioningStoreInterface; |
| 81 |
|
import com.xpn.xwiki.user.api.XWikiGroupService; |
| 82 |
|
import com.xpn.xwiki.user.api.XWikiRightService; |
| 83 |
|
import com.xpn.xwiki.util.XWikiStubContextProvider; |
| 84 |
|
import com.xpn.xwiki.web.Utils; |
| 85 |
|
|
| 86 |
|
import static com.xpn.xwiki.test.mockito.OldcoreMatchers.anyXWikiContext; |
| 87 |
|
import static com.xpn.xwiki.test.mockito.OldcoreMatchers.anyXWikiDocument; |
| 88 |
|
import static org.mockito.ArgumentMatchers.any; |
| 89 |
|
import static org.mockito.ArgumentMatchers.anyBoolean; |
| 90 |
|
import static org.mockito.Mockito.doAnswer; |
| 91 |
|
import static org.mockito.Mockito.doReturn; |
| 92 |
|
import static org.mockito.Mockito.mock; |
| 93 |
|
import static org.mockito.Mockito.spy; |
| 94 |
|
import static org.mockito.Mockito.when; |
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
@version |
| 100 |
|
@since |
| 101 |
|
|
| |
|
| 89.2% |
Uncovered Elements: 45 (416) |
Complexity: 101 |
Complexity Density: 0.37 |
|
| 102 |
|
public class MockitoOldcoreRule implements MethodRule |
| 103 |
|
{ |
| 104 |
|
public static final LocalDocumentReference USER_CLASS = new LocalDocumentReference("XWiki", "XWikiUsers"); |
| 105 |
|
|
| 106 |
|
public static final LocalDocumentReference GROUP_CLASS = new LocalDocumentReference("XWiki", "XWikiGroups"); |
| 107 |
|
|
| 108 |
|
private final MethodRule parent; |
| 109 |
|
|
| 110 |
|
private final MockitoComponentManagerRule componentManager; |
| 111 |
|
|
| 112 |
|
private XWikiContext context; |
| 113 |
|
|
| 114 |
|
private XWiki spyXWiki; |
| 115 |
|
|
| 116 |
|
protected File permanentDirectory; |
| 117 |
|
|
| 118 |
|
protected File temporaryDirectory; |
| 119 |
|
|
| 120 |
|
private XWikiHibernateStore mockHibernateStore; |
| 121 |
|
|
| 122 |
|
private XWikiVersioningStoreInterface mockVersioningStore; |
| 123 |
|
|
| 124 |
|
private XWikiRightService mockRightService; |
| 125 |
|
|
| 126 |
|
private XWikiGroupService mockGroupService; |
| 127 |
|
|
| 128 |
|
private AuthorizationManager mockAuthorizationManager; |
| 129 |
|
|
| 130 |
|
private ContextualAuthorizationManager mockContextualAuthorizationManager; |
| 131 |
|
|
| 132 |
|
private QueryManager queryManager; |
| 133 |
|
|
| 134 |
|
private WikiDescriptorManager wikiDescriptorManager; |
| 135 |
|
|
| 136 |
|
protected Map<DocumentReference, XWikiDocument> documents = new ConcurrentHashMap<>(); |
| 137 |
|
|
| 138 |
|
private boolean notifyDocumentCreatedEvent; |
| 139 |
|
|
| 140 |
|
private boolean notifyDocumentUpdatedEvent; |
| 141 |
|
|
| 142 |
|
private boolean notifyDocumentDeletedEvent; |
| 143 |
|
|
| 144 |
|
private MemoryConfigurationSource configurationSource; |
| 145 |
|
|
| 146 |
|
private MemoryConfigurationSource xwikicfgConfigurationSource; |
| 147 |
|
|
| 148 |
|
private MemoryConfigurationSource wikiConfigurationSource; |
| 149 |
|
|
| 150 |
|
private MemoryConfigurationSource spaceConfigurationSource; |
| 151 |
|
|
| 152 |
|
private ScriptContext scriptContext; |
| 153 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 154 |
317 |
public MockitoOldcoreRule()... |
| 155 |
|
{ |
| 156 |
317 |
this(new MockitoComponentManagerRule()); |
| 157 |
|
} |
| 158 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 159 |
372 |
public MockitoOldcoreRule(MockitoComponentManagerRule componentManager)... |
| 160 |
|
{ |
| 161 |
372 |
this(componentManager, componentManager); |
| 162 |
|
} |
| 163 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 164 |
372 |
public MockitoOldcoreRule(MockitoComponentManagerRule componentManager, MethodRule parent)... |
| 165 |
|
{ |
| 166 |
372 |
this.componentManager = componentManager; |
| 167 |
372 |
this.parent = parent; |
| 168 |
|
} |
| 169 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 170 |
6787 |
public MockitoComponentManagerRule getMocker()... |
| 171 |
|
{ |
| 172 |
6787 |
return this.componentManager; |
| 173 |
|
} |
| 174 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 175 |
15 |
public void notifyDocumentCreatedEvent(boolean notifyDocumentCreatedEvent)... |
| 176 |
|
{ |
| 177 |
15 |
this.notifyDocumentCreatedEvent = notifyDocumentCreatedEvent; |
| 178 |
|
} |
| 179 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 180 |
16 |
public void notifyDocumentUpdatedEvent(boolean notifyDocumentUpdatedEvent)... |
| 181 |
|
{ |
| 182 |
16 |
this.notifyDocumentUpdatedEvent = notifyDocumentUpdatedEvent; |
| 183 |
|
} |
| 184 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 185 |
13 |
public void notifyDocumentDeletedEvent(boolean notifyDocumentDeletedEvent)... |
| 186 |
|
{ |
| 187 |
13 |
this.notifyDocumentDeletedEvent = notifyDocumentDeletedEvent; |
| 188 |
|
} |
| 189 |
|
|
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
@throws@link |
| 194 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 195 |
5 |
public void notifyComponentDescriptorEvent() throws ComponentLookupException... |
| 196 |
|
{ |
| 197 |
5 |
getMocker().notifyComponentDescriptorEvent(); |
| 198 |
|
} |
| 199 |
|
|
| |
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 200 |
372 |
@Override... |
| 201 |
|
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) |
| 202 |
|
{ |
| 203 |
372 |
final Statement statement = new Statement() |
| 204 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 205 |
372 |
@Override... |
| 206 |
|
public void evaluate() throws Throwable |
| 207 |
|
{ |
| 208 |
372 |
before(target.getClass()); |
| 209 |
372 |
try { |
| 210 |
372 |
base.evaluate(); |
| 211 |
|
} finally { |
| 212 |
372 |
after(); |
| 213 |
|
} |
| 214 |
|
} |
| 215 |
|
}; |
| 216 |
|
|
| 217 |
372 |
return this.parent != null ? this.parent.apply(statement, method, target) : statement; |
| 218 |
|
} |
| 219 |
|
|
| |
|
| 97% |
Uncovered Elements: 5 (164) |
Complexity: 26 |
Complexity Density: 0.22 |
|
| 220 |
372 |
protected void before(Class<?> testClass) throws Exception... |
| 221 |
|
{ |
| 222 |
|
|
| 223 |
|
|
| 224 |
372 |
Utils.setComponentManager(getMocker()); |
| 225 |
|
|
| 226 |
372 |
this.context = new XWikiContext(); |
| 227 |
|
|
| 228 |
372 |
this.context.setWikiId("xwiki"); |
| 229 |
372 |
this.context.setMainXWiki("xwiki"); |
| 230 |
|
|
| 231 |
372 |
this.spyXWiki = spy(new XWiki()); |
| 232 |
372 |
getXWikiContext().setWiki(this.spyXWiki); |
| 233 |
|
|
| 234 |
372 |
this.mockHibernateStore = mock(XWikiHibernateStore.class); |
| 235 |
372 |
this.mockVersioningStore = mock(XWikiVersioningStoreInterface.class); |
| 236 |
372 |
this.mockRightService = mock(XWikiRightService.class); |
| 237 |
372 |
this.mockGroupService = mock(XWikiGroupService.class); |
| 238 |
|
|
| 239 |
372 |
doReturn(this.mockHibernateStore).when(this.spyXWiki).getStore(); |
| 240 |
372 |
doReturn(this.mockHibernateStore).when(this.spyXWiki).getHibernateStore(); |
| 241 |
372 |
doReturn(this.mockVersioningStore).when(this.spyXWiki).getVersioningStore(); |
| 242 |
372 |
doReturn(this.mockRightService).when(this.spyXWiki).getRightService(); |
| 243 |
372 |
doReturn(this.mockGroupService).when(this.spyXWiki).getGroupService(getXWikiContext()); |
| 244 |
|
|
| 245 |
|
|
| 246 |
372 |
getXWikiContext().put(ComponentManager.class.getName(), getMocker()); |
| 247 |
|
|
| 248 |
372 |
if (testClass.getAnnotation(AllComponents.class) != null) { |
| 249 |
|
|
| 250 |
|
|
| 251 |
55 |
this.mockAuthorizationManager = getMocker().registerMockComponent(AuthorizationManager.class, false); |
| 252 |
55 |
this.mockContextualAuthorizationManager = |
| 253 |
|
getMocker().registerMockComponent(ContextualAuthorizationManager.class, false); |
| 254 |
|
} else { |
| 255 |
|
|
| 256 |
317 |
if (!getMocker().hasComponent(AuthorizationManager.class)) { |
| 257 |
311 |
this.mockAuthorizationManager = getMocker().registerMockComponent(AuthorizationManager.class); |
| 258 |
|
} |
| 259 |
317 |
if (!getMocker().hasComponent(ContextualAuthorizationManager.class)) { |
| 260 |
315 |
this.mockContextualAuthorizationManager = |
| 261 |
|
getMocker().registerMockComponent(ContextualAuthorizationManager.class); |
| 262 |
|
} |
| 263 |
|
} |
| 264 |
|
|
| 265 |
|
|
| 266 |
372 |
if (!getMocker().hasComponent(ConfigurationSource.class)) { |
| 267 |
372 |
this.configurationSource = getMocker().registerMemoryConfigurationSource(); |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
|
| 271 |
372 |
if (!getMocker().hasComponent(ConfigurationSource.class, XWikiCfgConfigurationSource.ROLEHINT)) { |
| 272 |
317 |
this.xwikicfgConfigurationSource = new MockConfigurationSource(); |
| 273 |
317 |
getMocker().registerComponent(MockConfigurationSource.getDescriptor(XWikiCfgConfigurationSource.ROLEHINT), |
| 274 |
|
this.xwikicfgConfigurationSource); |
| 275 |
|
} |
| 276 |
|
|
| 277 |
372 |
if (!getMocker().hasComponent(ConfigurationSource.class, "wiki")) { |
| 278 |
366 |
this.wikiConfigurationSource = new MockConfigurationSource(); |
| 279 |
366 |
getMocker().registerComponent(MockConfigurationSource.getDescriptor("wiki"), this.wikiConfigurationSource); |
| 280 |
|
} |
| 281 |
|
|
| 282 |
|
|
| 283 |
372 |
if (!getMocker().hasComponent(ConfigurationSource.class, "space")) { |
| 284 |
371 |
this.spaceConfigurationSource = new MockConfigurationSource(); |
| 285 |
371 |
getMocker().registerComponent(MockConfigurationSource.getDescriptor("space"), |
| 286 |
|
this.spaceConfigurationSource); |
| 287 |
|
} |
| 288 |
|
|
| 289 |
|
|
| 290 |
|
|
| 291 |
372 |
if (getMocker().hasComponent(Environment.class) |
| 292 |
|
&& getMocker().getInstance(Environment.class) instanceof ServletEnvironment) { |
| 293 |
45 |
ServletEnvironment environment = getMocker().getInstance(Environment.class); |
| 294 |
|
|
| 295 |
45 |
ServletContext servletContextMock = mock(ServletContext.class); |
| 296 |
45 |
environment.setServletContext(servletContextMock); |
| 297 |
45 |
when(servletContextMock.getAttribute("javax.servlet.context.tempdir")) |
| 298 |
|
.thenReturn(new File(System.getProperty("java.io.tmpdir"))); |
| 299 |
|
|
| 300 |
45 |
File testDirectory = new File("target/test-" + new Date().getTime()); |
| 301 |
45 |
this.temporaryDirectory = new File(testDirectory, "temporary-dir"); |
| 302 |
45 |
this.permanentDirectory = new File(testDirectory, "permanent-dir"); |
| 303 |
45 |
environment.setTemporaryDirectory(this.temporaryDirectory); |
| 304 |
45 |
environment.setPermanentDirectory(this.permanentDirectory); |
| 305 |
|
} |
| 306 |
|
|
| 307 |
|
|
| 308 |
372 |
if (this.componentManager.hasComponent(ExecutionContextManager.class)) { |
| 309 |
62 |
ExecutionContextManager ecm = this.componentManager.getInstance(ExecutionContextManager.class); |
| 310 |
62 |
ExecutionContext ec = new ExecutionContext(); |
| 311 |
62 |
ecm.initialize(ec); |
| 312 |
|
} |
| 313 |
|
|
| 314 |
|
|
| 315 |
372 |
Execution execution; |
| 316 |
372 |
if (this.componentManager.hasComponent(Execution.class)) { |
| 317 |
63 |
execution = this.componentManager.getInstance(Execution.class); |
| 318 |
|
} else { |
| 319 |
309 |
execution = this.componentManager.registerMockComponent(Execution.class); |
| 320 |
|
} |
| 321 |
372 |
ExecutionContext econtext; |
| 322 |
372 |
if (MockUtil.isMock(execution)) { |
| 323 |
310 |
econtext = new ExecutionContext(); |
| 324 |
310 |
when(execution.getContext()).thenReturn(econtext); |
| 325 |
|
} else { |
| 326 |
62 |
econtext = execution.getContext(); |
| 327 |
|
} |
| 328 |
|
|
| 329 |
|
|
| 330 |
372 |
econtext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.context); |
| 331 |
372 |
this.scriptContext = (ScriptContext) econtext.getProperty(ScriptExecutionContextInitializer.SCRIPT_CONTEXT_ID); |
| 332 |
372 |
if (this.scriptContext == null) { |
| 333 |
310 |
this.scriptContext = new SimpleScriptContext(); |
| 334 |
310 |
econtext.setProperty(ScriptExecutionContextInitializer.SCRIPT_CONTEXT_ID, this.scriptContext); |
| 335 |
|
} |
| 336 |
|
|
| 337 |
372 |
if (!this.componentManager.hasComponent(ScriptContextManager.class)) { |
| 338 |
309 |
ScriptContextManager scriptContextManager = |
| 339 |
|
this.componentManager.registerMockComponent(ScriptContextManager.class); |
| 340 |
309 |
when(scriptContextManager.getCurrentScriptContext()).thenReturn(this.scriptContext); |
| 341 |
309 |
when(scriptContextManager.getScriptContext()).thenReturn(this.scriptContext); |
| 342 |
|
} |
| 343 |
|
|
| 344 |
|
|
| 345 |
372 |
if (!this.componentManager.hasComponent(XWikiContext.TYPE_PROVIDER)) { |
| 346 |
299 |
Provider<XWikiContext> xcontextProvider = |
| 347 |
|
this.componentManager.registerMockComponent(XWikiContext.TYPE_PROVIDER); |
| 348 |
299 |
when(xcontextProvider.get()).thenReturn(this.context); |
| 349 |
|
} else { |
| 350 |
73 |
Provider<XWikiContext> xcontextProvider = this.componentManager.getInstance(XWikiContext.TYPE_PROVIDER); |
| 351 |
73 |
if (MockUtil.isMock(xcontextProvider)) { |
| 352 |
18 |
when(xcontextProvider.get()).thenReturn(this.context); |
| 353 |
|
} |
| 354 |
|
} |
| 355 |
|
|
| 356 |
|
|
| 357 |
372 |
if (!this.componentManager.hasComponent(XWikiContext.TYPE_PROVIDER, "readonly")) { |
| 358 |
317 |
Provider<XWikiContext> xcontextProvider = |
| 359 |
|
this.componentManager.registerMockComponent(XWikiContext.TYPE_PROVIDER, "readonly"); |
| 360 |
317 |
when(xcontextProvider.get()).thenReturn(this.context); |
| 361 |
|
} else { |
| 362 |
55 |
Provider<XWikiContext> xcontextProvider = this.componentManager.getInstance(XWikiContext.TYPE_PROVIDER); |
| 363 |
55 |
if (MockUtil.isMock(xcontextProvider)) { |
| 364 |
0 |
when(xcontextProvider.get()).thenReturn(this.context); |
| 365 |
|
} |
| 366 |
|
} |
| 367 |
|
|
| 368 |
|
|
| 369 |
372 |
if (this.componentManager.hasComponent(XWikiStubContextProvider.class)) { |
| 370 |
55 |
XWikiStubContextProvider stubContextProvider = |
| 371 |
|
this.componentManager.getInstance(XWikiStubContextProvider.class); |
| 372 |
55 |
if (!MockUtil.isMock(stubContextProvider)) { |
| 373 |
55 |
stubContextProvider.initialize(this.context); |
| 374 |
|
} |
| 375 |
|
} |
| 376 |
|
|
| 377 |
|
|
| 378 |
372 |
if (!this.componentManager.hasComponent(CoreConfiguration.class)) { |
| 379 |
317 |
CoreConfiguration coreConfigurationMock = |
| 380 |
|
this.componentManager.registerMockComponent(CoreConfiguration.class); |
| 381 |
317 |
when(coreConfigurationMock.getDefaultDocumentSyntax()).thenReturn(Syntax.XWIKI_1_0); |
| 382 |
|
} else { |
| 383 |
55 |
CoreConfiguration coreConfiguration = |
| 384 |
|
this.componentManager.registerMockComponent(CoreConfiguration.class, false); |
| 385 |
55 |
if (MockUtil.isMock(coreConfiguration)) { |
| 386 |
55 |
when(coreConfiguration.getDefaultDocumentSyntax()).thenReturn(Syntax.XWIKI_1_0); |
| 387 |
|
} |
| 388 |
|
} |
| 389 |
|
|
| 390 |
|
|
| 391 |
372 |
if (!this.componentManager.hasComponent(ComponentManager.class, "context")) { |
| 392 |
317 |
DefaultComponentDescriptor<ComponentManager> componentManagerDescriptor = |
| 393 |
|
new DefaultComponentDescriptor<>(); |
| 394 |
317 |
componentManagerDescriptor.setRoleHint("context"); |
| 395 |
317 |
componentManagerDescriptor.setRoleType(ComponentManager.class); |
| 396 |
317 |
this.componentManager.registerComponent(componentManagerDescriptor, this.componentManager); |
| 397 |
|
} |
| 398 |
|
|
| 399 |
|
|
| 400 |
|
|
| 401 |
372 |
doAnswer(new Answer<XWikiDocument>() |
| 402 |
|
{ |
| |
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 403 |
1 |
@Override... |
| 404 |
|
public XWikiDocument answer(InvocationOnMock invocation) throws Throwable |
| 405 |
|
{ |
| 406 |
1 |
XWikiDocument doc = invocation.getArgument(0); |
| 407 |
1 |
String revision = invocation.getArgument(1); |
| 408 |
|
|
| 409 |
1 |
if (StringUtils.equals(revision, doc.getVersion())) { |
| 410 |
0 |
return doc; |
| 411 |
|
} |
| 412 |
|
|
| 413 |
|
|
| 414 |
1 |
return new XWikiDocument(doc.getDocumentReference()); |
| 415 |
|
} |
| 416 |
|
}).when(getSpyXWiki()).getDocument(anyXWikiDocument(), any(), anyXWikiContext()); |
| 417 |
372 |
doAnswer(new Answer<XWikiDocument>() |
| 418 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 419 |
2068 |
@Override... |
| 420 |
|
public XWikiDocument answer(InvocationOnMock invocation) throws Throwable |
| 421 |
|
{ |
| 422 |
2068 |
DocumentReference target = invocation.getArgument(0); |
| 423 |
|
|
| 424 |
2068 |
if (target.getLocale() == null) { |
| 425 |
860 |
target = new DocumentReference(target, Locale.ROOT); |
| 426 |
|
} |
| 427 |
|
|
| 428 |
2068 |
XWikiDocument document = documents.get(target); |
| 429 |
|
|
| 430 |
2068 |
if (document == null) { |
| 431 |
1499 |
document = new XWikiDocument(target, target.getLocale()); |
| 432 |
1499 |
document.setSyntax(Syntax.PLAIN_1_0); |
| 433 |
1499 |
document.setOriginalDocument(document.clone()); |
| 434 |
|
} |
| 435 |
|
|
| 436 |
2068 |
return document; |
| 437 |
|
} |
| 438 |
|
}).when(getSpyXWiki()).getDocument(any(DocumentReference.class), anyXWikiContext()); |
| 439 |
372 |
doAnswer(new Answer<XWikiDocument>() |
| 440 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 441 |
24 |
@Override... |
| 442 |
|
public XWikiDocument answer(InvocationOnMock invocation) throws Throwable |
| 443 |
|
{ |
| 444 |
24 |
XWikiDocument target = invocation.getArgument(0); |
| 445 |
|
|
| 446 |
24 |
return getSpyXWiki().getDocument(target.getDocumentReferenceWithLocale(), invocation.getArgument(1)); |
| 447 |
|
} |
| 448 |
|
}).when(getSpyXWiki()).getDocument(anyXWikiDocument(), any(XWikiContext.class)); |
| 449 |
372 |
doAnswer(new Answer<Boolean>() |
| 450 |
|
{ |
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 451 |
19 |
@Override... |
| 452 |
|
public Boolean answer(InvocationOnMock invocation) throws Throwable |
| 453 |
|
{ |
| 454 |
19 |
DocumentReference target = (DocumentReference) invocation.getArguments()[0]; |
| 455 |
|
|
| 456 |
19 |
if (target.getLocale() == null) { |
| 457 |
19 |
target = new DocumentReference(target, Locale.ROOT); |
| 458 |
|
} |
| 459 |
|
|
| 460 |
19 |
return documents.containsKey(target); |
| 461 |
|
} |
| 462 |
|
}).when(getSpyXWiki()).exists(any(DocumentReference.class), anyXWikiContext()); |
| 463 |
372 |
doAnswer(new Answer<Void>() |
| 464 |
|
{ |
| |
|
| 96% |
Uncovered Elements: 2 (50) |
Complexity: 11 |
Complexity Density: 0.32 |
|
| 465 |
515 |
@Override... |
| 466 |
|
public Void answer(InvocationOnMock invocation) throws Throwable |
| 467 |
|
{ |
| 468 |
515 |
XWikiDocument document = invocation.getArgument(0); |
| 469 |
515 |
String comment = invocation.getArgument(1); |
| 470 |
515 |
boolean minorEdit = invocation.getArgument(2); |
| 471 |
|
|
| 472 |
515 |
boolean isNew = document.isNew(); |
| 473 |
|
|
| 474 |
515 |
document.setComment(StringUtils.defaultString(comment)); |
| 475 |
515 |
document.setMinorEdit(minorEdit); |
| 476 |
|
|
| 477 |
515 |
if (document.isContentDirty() || document.isMetaDataDirty()) { |
| 478 |
499 |
document.setDate(new Date()); |
| 479 |
499 |
if (document.isContentDirty()) { |
| 480 |
463 |
document.setContentUpdateDate(new Date()); |
| 481 |
463 |
document.setContentAuthorReference(document.getAuthorReference()); |
| 482 |
|
} |
| 483 |
499 |
document.incrementVersion(); |
| 484 |
|
|
| 485 |
499 |
document.setContentDirty(false); |
| 486 |
499 |
document.setMetaDataDirty(false); |
| 487 |
|
} |
| 488 |
515 |
document.setNew(false); |
| 489 |
515 |
document.setStore(getMockStore()); |
| 490 |
|
|
| 491 |
515 |
XWikiDocument previousDocument = documents.get(document.getDocumentReferenceWithLocale()); |
| 492 |
|
|
| 493 |
515 |
if (previousDocument != null && previousDocument != document) { |
| 494 |
12 |
for (XWikiAttachment attachment : document.getAttachmentList()) { |
| 495 |
4 |
if (!attachment.isContentDirty()) { |
| 496 |
0 |
attachment.setAttachment_content( |
| 497 |
|
previousDocument.getAttachment(attachment.getFilename()).getAttachment_content()); |
| 498 |
|
} |
| 499 |
|
} |
| 500 |
|
} |
| 501 |
|
|
| 502 |
515 |
XWikiDocument originalDocument = document.getOriginalDocument(); |
| 503 |
515 |
if (originalDocument == null) { |
| 504 |
390 |
originalDocument = spyXWiki.getDocument(document.getDocumentReferenceWithLocale(), context); |
| 505 |
390 |
document.setOriginalDocument(originalDocument); |
| 506 |
|
} |
| 507 |
|
|
| 508 |
515 |
XWikiDocument savedDocument = document.clone(); |
| 509 |
|
|
| 510 |
515 |
documents.put(document.getDocumentReferenceWithLocale(), savedDocument); |
| 511 |
|
|
| 512 |
515 |
if (isNew) { |
| 513 |
475 |
if (notifyDocumentCreatedEvent) { |
| 514 |
29 |
getObservationManager().notify(new DocumentCreatedEvent(document.getDocumentReference()), |
| 515 |
|
document, getXWikiContext()); |
| 516 |
|
} |
| 517 |
|
} else { |
| 518 |
40 |
if (notifyDocumentUpdatedEvent) { |
| 519 |
20 |
getObservationManager().notify(new DocumentUpdatedEvent(document.getDocumentReference()), |
| 520 |
|
document, getXWikiContext()); |
| 521 |
|
} |
| 522 |
|
} |
| 523 |
|
|
| 524 |
|
|
| 525 |
515 |
savedDocument.setOriginalDocument(savedDocument.clone()); |
| 526 |
|
|
| 527 |
515 |
return null; |
| 528 |
|
} |
| 529 |
|
}).when(getSpyXWiki()).saveDocument(anyXWikiDocument(), any(String.class), anyBoolean(), anyXWikiContext()); |
| 530 |
372 |
doAnswer(new Answer<Void>() |
| 531 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 532 |
64 |
@Override... |
| 533 |
|
public Void answer(InvocationOnMock invocation) throws Throwable |
| 534 |
|
{ |
| 535 |
64 |
XWikiDocument document = invocation.getArgument(0); |
| 536 |
|
|
| 537 |
64 |
documents.remove(document.getDocumentReferenceWithLocale()); |
| 538 |
|
|
| 539 |
64 |
if (notifyDocumentDeletedEvent) { |
| 540 |
1 |
getObservationManager().notify(new DocumentDeletedEvent(document.getDocumentReference()), document, |
| 541 |
|
getXWikiContext()); |
| 542 |
|
} |
| 543 |
|
|
| 544 |
64 |
return null; |
| 545 |
|
} |
| 546 |
|
}).when(getSpyXWiki()).deleteDocument(anyXWikiDocument(), any(Boolean.class), anyXWikiContext()); |
| 547 |
372 |
doAnswer(new Answer<Void>() |
| 548 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 549 |
64 |
@Override... |
| 550 |
|
public Void answer(InvocationOnMock invocation) throws Throwable |
| 551 |
|
{ |
| 552 |
64 |
XWikiDocument document = invocation.getArgument(0); |
| 553 |
|
|
| 554 |
64 |
spyXWiki.deleteDocument(document, true, context); |
| 555 |
|
|
| 556 |
64 |
return null; |
| 557 |
|
} |
| 558 |
|
}).when(getSpyXWiki()).deleteDocument(anyXWikiDocument(), anyXWikiContext()); |
| 559 |
372 |
doAnswer(new Answer<Void>() |
| 560 |
|
{ |
| |
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 561 |
1 |
@Override... |
| 562 |
|
public Void answer(InvocationOnMock invocation) throws Throwable |
| 563 |
|
{ |
| 564 |
1 |
XWikiDocument document = invocation.getArgument(0); |
| 565 |
|
|
| 566 |
1 |
DocumentReference reference = document.getDocumentReference(); |
| 567 |
|
|
| 568 |
1 |
List<Locale> locales = document.getTranslationLocales(context); |
| 569 |
|
|
| 570 |
1 |
for (Locale locale : locales) { |
| 571 |
0 |
XWikiDocument translation = spyXWiki.getDocument(new DocumentReference(reference, locale), context); |
| 572 |
0 |
spyXWiki.deleteDocument(translation, context); |
| 573 |
|
} |
| 574 |
|
|
| 575 |
1 |
spyXWiki.deleteDocument(document, context); |
| 576 |
|
|
| 577 |
1 |
return null; |
| 578 |
|
} |
| 579 |
|
}).when(getSpyXWiki()).deleteAllDocuments(anyXWikiDocument(), any(Boolean.class), anyXWikiContext()); |
| 580 |
372 |
doAnswer(new Answer<Void>() |
| 581 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 582 |
1 |
@Override... |
| 583 |
|
public Void answer(InvocationOnMock invocation) throws Throwable |
| 584 |
|
{ |
| 585 |
1 |
XWikiDocument document = invocation.getArgument(0); |
| 586 |
|
|
| 587 |
1 |
spyXWiki.deleteAllDocuments(document, true, context); |
| 588 |
|
|
| 589 |
1 |
return null; |
| 590 |
|
} |
| 591 |
|
}).when(getSpyXWiki()).deleteAllDocuments(anyXWikiDocument(), anyXWikiContext()); |
| 592 |
372 |
doAnswer(new Answer<BaseClass>() |
| 593 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 594 |
429 |
@Override... |
| 595 |
|
public BaseClass answer(InvocationOnMock invocation) throws Throwable |
| 596 |
|
{ |
| 597 |
429 |
return getSpyXWiki() |
| 598 |
|
.getDocument((DocumentReference) invocation.getArguments()[0], invocation.getArgument(1)) |
| 599 |
|
.getXClass(); |
| 600 |
|
} |
| 601 |
|
}).when(getSpyXWiki()).getXClass(any(DocumentReference.class), anyXWikiContext()); |
| 602 |
372 |
doAnswer(new Answer<String>() |
| 603 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 604 |
48 |
@Override... |
| 605 |
|
public String answer(InvocationOnMock invocation) throws Throwable |
| 606 |
|
{ |
| 607 |
48 |
return getXWikiContext().getLanguage(); |
| 608 |
|
} |
| 609 |
|
}).when(getSpyXWiki()).getLanguagePreference(anyXWikiContext()); |
| 610 |
|
|
| 611 |
372 |
getXWikiContext().setLocale(Locale.ENGLISH); |
| 612 |
|
|
| 613 |
|
|
| 614 |
|
|
| 615 |
372 |
when(getMockStore().getTranslationList(anyXWikiDocument(), anyXWikiContext())).then(new Answer<List<String>>() |
| 616 |
|
{ |
| |
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 617 |
4 |
@Override... |
| 618 |
|
public List<String> answer(InvocationOnMock invocation) throws Throwable |
| 619 |
|
{ |
| 620 |
4 |
XWikiDocument document = invocation.getArgument(0); |
| 621 |
|
|
| 622 |
4 |
List<String> translations = new ArrayList<String>(); |
| 623 |
|
|
| 624 |
4 |
for (XWikiDocument storedDocument : documents.values()) { |
| 625 |
11 |
Locale storedLocale = storedDocument.getLocale(); |
| 626 |
11 |
if (!storedLocale.equals(Locale.ROOT) |
| 627 |
|
&& storedDocument.getDocumentReference().equals(document.getDocumentReference())) { |
| 628 |
0 |
translations.add(storedLocale.toString()); |
| 629 |
|
} |
| 630 |
|
} |
| 631 |
|
|
| 632 |
4 |
return translations; |
| 633 |
|
} |
| 634 |
|
}); |
| 635 |
372 |
when(getMockStore().loadXWikiDoc(anyXWikiDocument(), anyXWikiContext())).then(new Answer<XWikiDocument>() |
| 636 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 637 |
2 |
@Override... |
| 638 |
|
public XWikiDocument answer(InvocationOnMock invocation) throws Throwable |
| 639 |
|
{ |
| 640 |
2 |
return getSpyXWiki().getDocument(invocation.<XWikiDocument>getArgument(0), |
| 641 |
|
invocation.<XWikiContext>getArgument(1)); |
| 642 |
|
} |
| 643 |
|
}); |
| 644 |
|
|
| 645 |
|
|
| 646 |
|
|
| 647 |
372 |
doAnswer(new Answer<BaseClass>() |
| 648 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 2 |
Complexity Density: 0.13 |
|
| 649 |
3 |
@Override... |
| 650 |
|
public BaseClass answer(InvocationOnMock invocation) throws Throwable |
| 651 |
|
{ |
| 652 |
3 |
XWikiContext xcontext = invocation.getArgument(0); |
| 653 |
|
|
| 654 |
3 |
XWikiDocument userDocument = getSpyXWiki() |
| 655 |
|
.getDocument(new DocumentReference(USER_CLASS, new WikiReference(xcontext.getWikiId())), xcontext); |
| 656 |
|
|
| 657 |
3 |
final BaseClass userClass = userDocument.getXClass(); |
| 658 |
|
|
| 659 |
3 |
if (userDocument.isNew()) { |
| 660 |
2 |
userClass.addTextField("first_name", "First Name", 30); |
| 661 |
2 |
userClass.addTextField("last_name", "Last Name", 30); |
| 662 |
2 |
userClass.addEmailField("email", "e-Mail", 30); |
| 663 |
2 |
userClass.addPasswordField("password", "Password", 10); |
| 664 |
2 |
userClass.addBooleanField("active", "Active", "active"); |
| 665 |
2 |
userClass.addTextAreaField("comment", "Comment", 40, 5); |
| 666 |
2 |
userClass.addTextField("avatar", "Avatar", 30); |
| 667 |
2 |
userClass.addTextField("phone", "Phone", 30); |
| 668 |
2 |
userClass.addTextAreaField("address", "Address", 40, 3); |
| 669 |
|
|
| 670 |
2 |
getSpyXWiki().saveDocument(userDocument, xcontext); |
| 671 |
|
} |
| 672 |
|
|
| 673 |
3 |
return userClass; |
| 674 |
|
} |
| 675 |
|
}).when(getSpyXWiki()).getUserClass(anyXWikiContext()); |
| 676 |
372 |
doAnswer(new Answer<BaseClass>() |
| 677 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 678 |
6 |
@Override... |
| 679 |
|
public BaseClass answer(InvocationOnMock invocation) throws Throwable |
| 680 |
|
{ |
| 681 |
6 |
XWikiContext xcontext = invocation.getArgument(0); |
| 682 |
|
|
| 683 |
6 |
XWikiDocument groupDocument = getSpyXWiki() |
| 684 |
|
.getDocument(new DocumentReference(GROUP_CLASS, new WikiReference(xcontext.getWikiId())), xcontext); |
| 685 |
|
|
| 686 |
6 |
final BaseClass groupClass = groupDocument.getXClass(); |
| 687 |
|
|
| 688 |
6 |
if (groupDocument.isNew()) { |
| 689 |
2 |
groupClass.addTextField("member", "Member", 30); |
| 690 |
|
|
| 691 |
2 |
getSpyXWiki().saveDocument(groupDocument, xcontext); |
| 692 |
|
} |
| 693 |
|
|
| 694 |
6 |
return groupClass; |
| 695 |
|
} |
| 696 |
|
}).when(getSpyXWiki()).getGroupClass(anyXWikiContext()); |
| 697 |
|
|
| 698 |
|
|
| 699 |
|
|
| 700 |
|
|
| 701 |
372 |
if (!this.componentManager.hasComponent(QueryManager.class)) { |
| 702 |
313 |
mockQueryManager(); |
| 703 |
|
} |
| 704 |
372 |
when(getMockStore().getQueryManager()).then(new Answer<QueryManager>() |
| 705 |
|
{ |
| 706 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 707 |
1 |
@Override... |
| 708 |
|
public QueryManager answer(InvocationOnMock invocation) throws Throwable |
| 709 |
|
{ |
| 710 |
1 |
return getQueryManager(); |
| 711 |
|
} |
| 712 |
|
}); |
| 713 |
|
|
| 714 |
|
|
| 715 |
|
|
| 716 |
|
|
| 717 |
372 |
if (!this.componentManager.hasComponent(WikiDescriptorManager.class)) { |
| 718 |
359 |
this.wikiDescriptorManager = getMocker().registerMockComponent(WikiDescriptorManager.class); |
| 719 |
359 |
when(this.wikiDescriptorManager.getMainWikiId()).then(new Answer<String>() |
| 720 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 721 |
0 |
@Override... |
| 722 |
|
public String answer(InvocationOnMock invocation) throws Throwable |
| 723 |
|
{ |
| 724 |
0 |
return getXWikiContext().getMainXWiki(); |
| 725 |
|
} |
| 726 |
|
}); |
| 727 |
359 |
when(this.wikiDescriptorManager.getCurrentWikiId()).then(new Answer<String>() |
| 728 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 729 |
12016 |
@Override... |
| 730 |
|
public String answer(InvocationOnMock invocation) throws Throwable |
| 731 |
|
{ |
| 732 |
12016 |
return getXWikiContext().getWikiId(); |
| 733 |
|
} |
| 734 |
|
}); |
| 735 |
|
} |
| 736 |
|
} |
| 737 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 738 |
0 |
protected DocumentReference resolveDocument(String documentName) throws ComponentLookupException... |
| 739 |
|
{ |
| 740 |
0 |
DocumentReferenceResolver<String> resolver = |
| 741 |
|
getMocker().getInstance(DocumentReferenceResolver.TYPE_STRING, "current"); |
| 742 |
|
|
| 743 |
0 |
return resolver.resolve(documentName); |
| 744 |
|
} |
| 745 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 746 |
372 |
protected void after() throws Exception... |
| 747 |
|
{ |
| 748 |
372 |
Utils.setComponentManager(null); |
| 749 |
|
|
| 750 |
372 |
Execution execution = this.componentManager.getInstance(Execution.class); |
| 751 |
372 |
execution.removeContext(); |
| 752 |
|
} |
| 753 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 754 |
15168 |
public XWikiContext getXWikiContext()... |
| 755 |
|
{ |
| 756 |
15168 |
return this.context; |
| 757 |
|
} |
| 758 |
|
|
| 759 |
|
|
| 760 |
|
@since |
| 761 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 762 |
5795 |
public XWiki getSpyXWiki()... |
| 763 |
|
{ |
| 764 |
5795 |
return this.spyXWiki; |
| 765 |
|
} |
| 766 |
|
|
| 767 |
|
|
| 768 |
|
@deprecated@link |
| 769 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 770 |
0 |
@Deprecated... |
| 771 |
|
public XWiki getMockXWiki() |
| 772 |
|
{ |
| 773 |
0 |
return getSpyXWiki(); |
| 774 |
|
} |
| 775 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 776 |
0 |
public File getPermanentDirectory()... |
| 777 |
|
{ |
| 778 |
0 |
return this.permanentDirectory; |
| 779 |
|
} |
| 780 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 781 |
0 |
public File getTemporaryDirectory()... |
| 782 |
|
{ |
| 783 |
0 |
return this.temporaryDirectory; |
| 784 |
|
} |
| 785 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 786 |
96 |
public XWikiRightService getMockRightService()... |
| 787 |
|
{ |
| 788 |
96 |
return this.mockRightService; |
| 789 |
|
} |
| 790 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 791 |
0 |
public XWikiGroupService getMockGroupService()... |
| 792 |
|
{ |
| 793 |
0 |
return this.mockGroupService; |
| 794 |
|
} |
| 795 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 796 |
23 |
public AuthorizationManager getMockAuthorizationManager()... |
| 797 |
|
{ |
| 798 |
23 |
return this.mockAuthorizationManager; |
| 799 |
|
} |
| 800 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 801 |
40 |
public ContextualAuthorizationManager getMockContextualAuthorizationManager()... |
| 802 |
|
{ |
| 803 |
40 |
return this.mockContextualAuthorizationManager; |
| 804 |
|
} |
| 805 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 806 |
1633 |
public XWikiStoreInterface getMockStore()... |
| 807 |
|
{ |
| 808 |
1633 |
return this.mockHibernateStore; |
| 809 |
|
} |
| 810 |
|
|
| 811 |
|
|
| 812 |
|
@since |
| 813 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 814 |
0 |
public XWikiVersioningStoreInterface getMockVersioningStore()... |
| 815 |
|
{ |
| 816 |
0 |
return this.mockVersioningStore; |
| 817 |
|
} |
| 818 |
|
|
| 819 |
|
|
| 820 |
|
@since |
| 821 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 822 |
12 |
public ExecutionContext getExecutionContext() throws ComponentLookupException... |
| 823 |
|
{ |
| 824 |
12 |
return this.componentManager.<Execution>getInstance(Execution.class).getContext(); |
| 825 |
|
} |
| 826 |
|
|
| 827 |
|
|
| 828 |
|
@since |
| 829 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 830 |
4 |
public ScriptContext getScriptContext()... |
| 831 |
|
{ |
| 832 |
4 |
return this.scriptContext; |
| 833 |
|
} |
| 834 |
|
|
| 835 |
|
|
| 836 |
|
@since |
| 837 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 838 |
53 |
public Map<DocumentReference, XWikiDocument> getDocuments()... |
| 839 |
|
{ |
| 840 |
53 |
return this.documents; |
| 841 |
|
} |
| 842 |
|
|
| 843 |
|
|
| 844 |
|
@since |
| 845 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 846 |
50 |
public ObservationManager getObservationManager() throws ComponentLookupException... |
| 847 |
|
{ |
| 848 |
50 |
return getMocker().getInstance(ObservationManager.class); |
| 849 |
|
} |
| 850 |
|
|
| 851 |
|
|
| 852 |
|
@since |
| 853 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 854 |
9 |
public QueryManager getQueryManager() throws ComponentLookupException... |
| 855 |
|
{ |
| 856 |
9 |
if (this.queryManager == null) { |
| 857 |
0 |
this.queryManager = this.componentManager.getInstance(QueryManager.class); |
| 858 |
|
} |
| 859 |
|
|
| 860 |
9 |
return this.queryManager; |
| 861 |
|
} |
| 862 |
|
|
| 863 |
|
|
| 864 |
|
|
| 865 |
|
|
| 866 |
|
@return |
| 867 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 868 |
313 |
public QueryManager mockQueryManager() throws Exception... |
| 869 |
|
{ |
| 870 |
313 |
this.queryManager = getMocker().registerMockComponent(QueryManager.class); |
| 871 |
|
|
| 872 |
313 |
return this.queryManager; |
| 873 |
|
} |
| 874 |
|
|
| 875 |
|
|
| 876 |
|
@since |
| 877 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 878 |
0 |
public WikiDescriptorManager getWikiDescriptorManager() throws ComponentLookupException... |
| 879 |
|
{ |
| 880 |
0 |
if (this.wikiDescriptorManager == null) { |
| 881 |
|
|
| 882 |
0 |
if (this.componentManager.hasComponent(WikiDescriptorManager.class)) { |
| 883 |
0 |
this.wikiDescriptorManager = this.componentManager.getInstance(WikiDescriptorManager.class); |
| 884 |
|
} |
| 885 |
|
} |
| 886 |
|
|
| 887 |
0 |
return this.wikiDescriptorManager; |
| 888 |
|
} |
| 889 |
|
|
| 890 |
|
|
| 891 |
|
@since |
| 892 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 893 |
0 |
public MemoryConfigurationSource getConfigurationSource()... |
| 894 |
|
{ |
| 895 |
0 |
return this.configurationSource; |
| 896 |
|
} |
| 897 |
|
|
| 898 |
|
|
| 899 |
|
@since |
| 900 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 901 |
24 |
public MemoryConfigurationSource getMockXWikiCfg()... |
| 902 |
|
{ |
| 903 |
24 |
return this.xwikicfgConfigurationSource; |
| 904 |
|
} |
| 905 |
|
|
| 906 |
|
|
| 907 |
|
@since |
| 908 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 909 |
0 |
public MemoryConfigurationSource getMockWikiConfigurationSource()... |
| 910 |
|
{ |
| 911 |
0 |
return this.wikiConfigurationSource; |
| 912 |
|
} |
| 913 |
|
|
| 914 |
|
|
| 915 |
|
@since |
| 916 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 917 |
96 |
public void registerMockEnvironment() throws Exception... |
| 918 |
|
{ |
| 919 |
96 |
Environment environment = getMocker().registerMockComponent(Environment.class); |
| 920 |
|
|
| 921 |
96 |
File temp = new File(new File(System.getProperty("java.io.tmpdir")), "test-" + new Date().getTime()); |
| 922 |
|
|
| 923 |
96 |
when(environment.getTemporaryDirectory()).thenReturn(new File(temp, "temporary")); |
| 924 |
96 |
when(environment.getPermanentDirectory()).thenReturn(new File(temp, "permanent")); |
| 925 |
|
} |
| 926 |
|
} |