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 |
|
|
24 |
|
import javax.servlet.ServletContext; |
25 |
|
|
26 |
|
import org.jmock.Expectations; |
27 |
|
import org.jmock.api.Imposteriser; |
28 |
|
import org.jmock.lib.legacy.ClassImposteriser; |
29 |
|
import org.junit.After; |
30 |
|
import org.junit.Before; |
31 |
|
import org.xwiki.component.manager.ComponentManager; |
32 |
|
import org.xwiki.context.Execution; |
33 |
|
import org.xwiki.environment.Environment; |
34 |
|
import org.xwiki.environment.internal.ServletEnvironment; |
35 |
|
import org.xwiki.rendering.syntax.Syntax; |
36 |
|
import org.xwiki.security.authorization.AuthorizationManager; |
37 |
|
import org.xwiki.security.authorization.ContextualAuthorizationManager; |
38 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
39 |
|
|
40 |
|
import com.xpn.xwiki.CoreConfiguration; |
41 |
|
import com.xpn.xwiki.XWikiContext; |
42 |
|
import com.xpn.xwiki.util.XWikiStubContextProvider; |
43 |
|
import com.xpn.xwiki.web.Utils; |
44 |
|
|
45 |
|
|
46 |
|
@link |
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
@deprecated@link |
51 |
|
|
52 |
|
@Deprecated |
|
|
| 95.5% |
Uncovered Elements: 2 (44) |
Complexity: 10 |
Complexity Density: 0.29 |
|
53 |
|
public class AbstractBridgedComponentTestCase extends AbstractComponentTestCase |
54 |
|
{ |
55 |
|
private XWikiContext context; |
56 |
|
|
57 |
|
private ContextualAuthorizationManager contextualAuthorizationManager; |
58 |
|
private AuthorizationManager authorizationManager; |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
17 |
protected AbstractBridgedComponentTestCase()... |
61 |
|
{ |
62 |
|
|
63 |
17 |
this(ClassImposteriser.INSTANCE); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
17 |
protected AbstractBridgedComponentTestCase(Imposteriser imposteriser)... |
67 |
|
{ |
68 |
17 |
getMockery().setImposteriser(imposteriser); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
|
71 |
17 |
@Override... |
72 |
|
@Before |
73 |
|
public void setUp() throws Exception |
74 |
|
{ |
75 |
17 |
super.setUp(); |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
17 |
Utils.setComponentManager(getComponentManager()); |
80 |
|
|
81 |
17 |
this.context = new XWikiContext(); |
82 |
|
|
83 |
17 |
this.context.setWikiId("xwiki"); |
84 |
17 |
this.context.setMainXWiki("xwiki"); |
85 |
|
|
86 |
|
|
87 |
17 |
getContext().put(ComponentManager.class.getName(), getComponentManager()); |
88 |
|
|
89 |
|
|
90 |
17 |
Execution execution = getComponentManager().getInstance(Execution.class); |
91 |
17 |
execution.getContext().setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.context); |
92 |
17 |
XWikiStubContextProvider stubContextProvider = |
93 |
|
getComponentManager().getInstance(XWikiStubContextProvider.class); |
94 |
17 |
stubContextProvider.initialize(this.context); |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
17 |
ServletEnvironment environment = (ServletEnvironment) getComponentManager().getInstance(Environment.class); |
99 |
17 |
final ServletContext mockServletContext = getMockery().mock(ServletContext.class); |
100 |
17 |
environment.setServletContext(mockServletContext); |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
101 |
17 |
getMockery().checking(new Expectations() {{... |
102 |
17 |
allowing(mockServletContext).getResourceAsStream("/WEB-INF/cache/infinispan/config.xml"); |
103 |
17 |
will(returnValue(null)); |
104 |
17 |
allowing(mockServletContext).getResourceAsStream("/WEB-INF/xwiki.cfg"); |
105 |
17 |
will(returnValue(null)); |
106 |
17 |
allowing(mockServletContext).getAttribute("javax.servlet.context.tempdir"); |
107 |
17 |
will(returnValue(new File(System.getProperty("java.io.tmpdir")))); |
108 |
|
}}); |
109 |
|
|
110 |
17 |
final CoreConfiguration mockCoreConfiguration = registerMockComponent(CoreConfiguration.class); |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
111 |
17 |
getMockery().checking(new Expectations() {{... |
112 |
17 |
allowing(mockCoreConfiguration).getDefaultDocumentSyntax(); will(returnValue(Syntax.XWIKI_1_0)); |
113 |
|
}}); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
116 |
17 |
@Override... |
117 |
|
protected void registerComponents() throws Exception |
118 |
|
{ |
119 |
17 |
super.registerComponents(); |
120 |
|
|
121 |
17 |
this.contextualAuthorizationManager = this.registerMockComponent(ContextualAuthorizationManager.class); |
122 |
17 |
this.authorizationManager = this.registerMockComponent(AuthorizationManager.class); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
125 |
17 |
@Override... |
126 |
|
@After |
127 |
|
public void tearDown() throws Exception |
128 |
|
{ |
129 |
17 |
super.tearDown(); |
130 |
|
|
131 |
17 |
Utils.setComponentManager(null); |
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
154 |
public XWikiContext getContext()... |
135 |
|
{ |
136 |
154 |
return this.context; |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
@return |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
2 |
public ContextualAuthorizationManager getContextualAuthorizationManager()... |
143 |
|
{ |
144 |
2 |
return contextualAuthorizationManager; |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
@return |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
0 |
public AuthorizationManager getAuthorizationManager()... |
151 |
|
{ |
152 |
0 |
return authorizationManager; |
153 |
|
} |
154 |
|
} |