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 org.jmock.Mock; |
23 |
|
import org.jmock.cglib.MockObjectTestCase; |
24 |
|
import org.xwiki.component.descriptor.ComponentDescriptor; |
25 |
|
import org.xwiki.component.descriptor.DefaultComponentDescriptor; |
26 |
|
import org.xwiki.security.authorization.AuthorizationManager; |
27 |
|
import org.xwiki.security.authorization.ContextualAuthorizationManager; |
28 |
|
import org.xwiki.test.internal.MockConfigurationSource; |
29 |
|
import org.xwiki.test.jmock.MockingComponentManager; |
30 |
|
import org.xwiki.test.jmock.XWikiComponentInitializer; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@link |
35 |
|
|
36 |
|
|
37 |
|
@deprecated@link |
38 |
|
|
39 |
|
@Deprecated |
|
|
| 73% |
Uncovered Elements: 10 (37) |
Complexity: 13 |
Complexity Density: 0.54 |
|
40 |
|
public abstract class AbstractXWikiComponentTestCase extends MockObjectTestCase |
41 |
|
{ |
42 |
|
private XWikiComponentInitializer initializer = new XWikiComponentInitializer(); |
43 |
|
|
44 |
|
private Mock contextualAuthorizationManager; |
45 |
|
private Mock authorizationManager; |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
133 |
public AbstractXWikiComponentTestCase()... |
48 |
|
{ |
49 |
133 |
super(); |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0 |
public AbstractXWikiComponentTestCase(String testName)... |
53 |
|
{ |
54 |
0 |
super(testName); |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@see |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
62 |
133 |
@Override... |
63 |
|
protected void setUp() throws Exception |
64 |
|
{ |
65 |
133 |
this.initializer.initializeConfigurationSource(); |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
133 |
registerComponents(); |
70 |
|
|
71 |
133 |
this.initializer.initializeExecution(); |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
77 |
133 |
protected void registerComponents() throws Exception... |
78 |
|
{ |
79 |
133 |
this.contextualAuthorizationManager = this.registerMockComponent(ContextualAuthorizationManager.class); |
80 |
133 |
this.authorizationManager = this.registerMockComponent(AuthorizationManager.class); |
81 |
|
|
82 |
133 |
this.contextualAuthorizationManager.stubs().method("hasAccess").will(returnValue(true)); |
83 |
133 |
this.authorizationManager.stubs().method("hasAccess").will(returnValue(true)); |
84 |
|
|
85 |
|
|
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
133 |
@Override... |
89 |
|
protected void tearDown() throws Exception |
90 |
|
{ |
91 |
133 |
this.initializer.shutdown(); |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
@return |
96 |
|
|
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
1614 |
public MockingComponentManager getComponentManager() throws Exception... |
99 |
|
{ |
100 |
1614 |
return this.initializer.getComponentManager(); |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
@return |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
70 |
public MockConfigurationSource getConfigurationSource()... |
107 |
|
{ |
108 |
70 |
return this.initializer.getConfigurationSource(); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
@return |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
0 |
public Mock getContextualAuthorizationManager()... |
115 |
|
{ |
116 |
0 |
return contextualAuthorizationManager; |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
@return |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
0 |
public Mock getAuthorizationManager()... |
123 |
|
{ |
124 |
0 |
return authorizationManager; |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
@since |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
130 |
0 |
public <T> Mock registerMockComponent(Class<T> role, String hint) throws Exception... |
131 |
|
{ |
132 |
0 |
DefaultComponentDescriptor<T> descriptor = createComponentDescriptor(role); |
133 |
0 |
descriptor.setRoleHint(hint); |
134 |
0 |
return registerMockComponent(descriptor); |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
@since |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
756 |
public <T> Mock registerMockComponent(Class<T> role) throws Exception... |
141 |
|
{ |
142 |
756 |
return registerMockComponent(createComponentDescriptor(role)); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
@since |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
148 |
756 |
private <T> Mock registerMockComponent(ComponentDescriptor<T> descriptor) throws Exception... |
149 |
|
{ |
150 |
756 |
Mock mock = mock(descriptor.getRole()); |
151 |
756 |
getComponentManager().registerComponent(descriptor, (T) mock.proxy()); |
152 |
756 |
return mock; |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
@since |
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
158 |
756 |
private <T> DefaultComponentDescriptor<T> createComponentDescriptor(Class<T> role)... |
159 |
|
{ |
160 |
756 |
DefaultComponentDescriptor<T> descriptor = new DefaultComponentDescriptor<T>(); |
161 |
756 |
descriptor.setRole(role); |
162 |
756 |
return descriptor; |
163 |
|
} |
164 |
|
} |