1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal; |
21 |
|
|
22 |
|
import org.jmock.Mock; |
23 |
|
import org.xwiki.context.ExecutionContext; |
24 |
|
import org.xwiki.context.ExecutionContextException; |
25 |
|
import org.xwiki.context.ExecutionContextManager; |
26 |
|
|
27 |
|
import com.xpn.xwiki.XWiki; |
28 |
|
import com.xpn.xwiki.XWikiContext; |
29 |
|
import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase; |
30 |
|
import com.xpn.xwiki.util.XWikiStubContextProvider; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
|
|
|
| 96.2% |
Uncovered Elements: 1 (26) |
Complexity: 4 |
Complexity Density: 0.17 |
|
37 |
|
public class XWikiStubContextInitializerTest extends AbstractBridgedXWikiComponentTestCase |
38 |
|
{ |
39 |
|
private ExecutionContextManager executionContextManager; |
40 |
|
|
41 |
|
private Mock mockXWiki; |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
43 |
1 |
@Override... |
44 |
|
protected void setUp() throws Exception |
45 |
|
{ |
46 |
1 |
super.setUp(); |
47 |
|
|
48 |
1 |
this.executionContextManager = getComponentManager().getInstance(ExecutionContextManager.class); |
49 |
|
} |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
51 |
1 |
public void testWithAndWithoutXWikiContext() throws Exception... |
52 |
|
{ |
53 |
1 |
XWikiContext xcontext = new XWikiContext(); |
54 |
1 |
xcontext.put("key", "value"); |
55 |
|
|
56 |
1 |
this.mockXWiki = mock(XWiki.class); |
57 |
1 |
this.mockXWiki.stubs().method("prepareResources"); |
58 |
|
|
59 |
1 |
xcontext.setWiki((XWiki) this.mockXWiki.proxy()); |
60 |
|
|
61 |
1 |
ExecutionContext context = new ExecutionContext(); |
62 |
1 |
xcontext.declareInExecutionContext(context); |
63 |
|
|
64 |
1 |
XWikiStubContextProvider stubContextProvider = |
65 |
|
getComponentManager().getInstance(XWikiStubContextProvider.class); |
66 |
1 |
stubContextProvider.initialize(xcontext); |
67 |
|
|
68 |
1 |
final ExecutionContext daemonContext = new ExecutionContext(); |
69 |
|
|
70 |
1 |
Thread thread = new Thread(new Runnable() |
71 |
|
{ |
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
72 |
1 |
@Override... |
73 |
|
public void run() |
74 |
|
{ |
75 |
1 |
try { |
76 |
1 |
executionContextManager.initialize(daemonContext); |
77 |
|
} catch (ExecutionContextException e) { |
78 |
0 |
fail("Failed to initialize execution context: " + e.getStackTrace()); |
79 |
|
} |
80 |
|
} |
81 |
|
}); |
82 |
|
|
83 |
1 |
thread.start(); |
84 |
1 |
thread.join(); |
85 |
|
|
86 |
1 |
XWikiContext daemonXcontext = (XWikiContext) daemonContext.getProperty("xwikicontext"); |
87 |
1 |
assertNotNull(daemonXcontext); |
88 |
1 |
assertNotSame(xcontext, daemonXcontext); |
89 |
1 |
assertEquals("value", daemonXcontext.get("key")); |
90 |
1 |
assertNotNull(daemonXcontext.getWiki()); |
91 |
|
} |
92 |
|
} |