| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.component.internal; |
| 21 |
|
|
| 22 |
|
import javax.inject.Provider; |
| 23 |
|
|
| 24 |
|
import org.jmock.Expectations; |
| 25 |
|
import org.jmock.States; |
| 26 |
|
import org.junit.Assert; |
| 27 |
|
import org.junit.Test; |
| 28 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
| 29 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
| 30 |
|
import org.xwiki.bridge.event.WikiDeletedEvent; |
| 31 |
|
import org.xwiki.component.descriptor.DefaultComponentDescriptor; |
| 32 |
|
import org.xwiki.component.internal.multi.ComponentManagerManager; |
| 33 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 34 |
|
import org.xwiki.component.manager.ComponentManager; |
| 35 |
|
import org.xwiki.component.manager.NamespacedComponentManager; |
| 36 |
|
import org.xwiki.model.reference.DocumentReference; |
| 37 |
|
import org.xwiki.model.reference.SpaceReference; |
| 38 |
|
import org.xwiki.model.reference.WikiReference; |
| 39 |
|
import org.xwiki.observation.ObservationManager; |
| 40 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
| 41 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
| 42 |
|
|
| 43 |
|
import static org.junit.Assert.assertEquals; |
| 44 |
|
import static org.junit.Assert.assertNotNull; |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@link |
| 48 |
|
@link |
| 49 |
|
@link |
| 50 |
|
|
| 51 |
|
@version |
| 52 |
|
@since |
| 53 |
|
|
| |
|
| 97.6% |
Uncovered Elements: 6 (250) |
Complexity: 32 |
Complexity Density: 0.14 |
|
| 54 |
|
public class ContextComponentManagerTest extends AbstractComponentTestCase |
| 55 |
|
{ |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
private DocumentAccessBridge mockDocumentAccessBridge; |
| 60 |
|
|
| 61 |
|
private WikiDescriptorManager mockWikiDescriptorManager; |
| 62 |
|
|
| 63 |
|
private Provider<DocumentReference> mockCurrentDocumentReferenceProvider; |
| 64 |
|
|
| 65 |
|
private Provider<SpaceReference> mockCurrentSpaceReferenceProvider; |
| 66 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 67 |
|
public static interface Role |
| 68 |
|
{ |
| 69 |
|
} |
| 70 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 71 |
|
public static class RoleImpl implements Role |
| 72 |
|
{ |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 75 |
13 |
@Override... |
| 76 |
|
protected void registerComponents() throws Exception |
| 77 |
|
{ |
| 78 |
13 |
super.registerComponents(); |
| 79 |
|
|
| 80 |
|
|
| 81 |
13 |
this.mockDocumentAccessBridge = registerMockComponent(DocumentAccessBridge.class); |
| 82 |
13 |
this.mockWikiDescriptorManager = registerMockComponent(WikiDescriptorManager.class); |
| 83 |
13 |
this.mockCurrentDocumentReferenceProvider = registerMockComponent(DocumentReference.TYPE_PROVIDER, "current"); |
| 84 |
13 |
this.mockCurrentSpaceReferenceProvider = registerMockComponent(SpaceReference.TYPE_PROVIDER, "current"); |
| 85 |
|
} |
| 86 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 87 |
13 |
@Override... |
| 88 |
|
public void setUp() throws Exception |
| 89 |
|
{ |
| 90 |
13 |
super.setUp(); |
| 91 |
|
|
| 92 |
|
|
| 93 |
13 |
StackingComponentEventManager eventManager = new StackingComponentEventManager(); |
| 94 |
13 |
eventManager |
| 95 |
|
.setObservationManager(getComponentManager().<ObservationManager>getInstance(ObservationManager.class)); |
| 96 |
13 |
eventManager.shouldStack(false); |
| 97 |
13 |
getComponentManager().setComponentEventManager(eventManager); |
| 98 |
|
} |
| 99 |
|
|
| |
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 3 |
Complexity Density: 0.18 |
1PASS
|
|
| 100 |
1 |
@Test... |
| 101 |
|
public void testRegisterComponentInUserComponentManager() throws Exception |
| 102 |
|
{ |
| 103 |
1 |
final States state = getMockery().states("test"); |
| 104 |
|
|
| 105 |
1 |
getMockery().checking(new Expectations() |
| 106 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
| 107 |
1 |
{... |
| 108 |
1 |
allowing(mockDocumentAccessBridge).getCurrentUserReference(); |
| 109 |
1 |
when(state.isNot("otheruser")); |
| 110 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user1"))); |
| 111 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 112 |
1 |
will(returnValue("wiki")); |
| 113 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 114 |
1 |
will(returnValue(new SpaceReference("space", new WikiReference("wiki")))); |
| 115 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 116 |
1 |
will(returnValue(new DocumentReference("wiki", "space", "document"))); |
| 117 |
|
} |
| 118 |
|
}); |
| 119 |
|
|
| 120 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
1 |
try { |
| 125 |
1 |
contextCM.getInstance(Role.class); |
| 126 |
0 |
Assert.fail("Should have raised an exception"); |
| 127 |
|
} catch (ComponentLookupException expected) { |
| 128 |
|
|
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
| 132 |
1 |
ComponentManager userCM = getComponentManager().getInstance(ComponentManager.class, "user"); |
| 133 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
| 134 |
1 |
cd.setRole(Role.class); |
| 135 |
1 |
cd.setImplementation(RoleImpl.class); |
| 136 |
1 |
userCM.registerComponent(cd); |
| 137 |
|
|
| 138 |
|
|
| 139 |
1 |
Assert.assertNotNull(contextCM.getInstance(Role.class)); |
| 140 |
|
|
| 141 |
|
|
| 142 |
1 |
state.become("otheruser"); |
| 143 |
1 |
getMockery().checking(new Expectations() |
| 144 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 145 |
1 |
{... |
| 146 |
1 |
allowing(mockDocumentAccessBridge).getCurrentUserReference(); |
| 147 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user2"))); |
| 148 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 149 |
1 |
will(returnValue("wiki")); |
| 150 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 151 |
1 |
will(returnValue(new SpaceReference("space", new WikiReference("wiki")))); |
| 152 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 153 |
1 |
will(returnValue(new DocumentReference("wiki", "space", "document"))); |
| 154 |
|
} |
| 155 |
|
}); |
| 156 |
|
|
| 157 |
1 |
try { |
| 158 |
1 |
contextCM.getInstance(Role.class); |
| 159 |
0 |
Assert.fail("Should have raised an exception"); |
| 160 |
|
} catch (ComponentLookupException expected) { |
| 161 |
|
|
| 162 |
|
} |
| 163 |
|
} |
| 164 |
|
|
| |
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 2 |
Complexity Density: 0.14 |
1PASS
|
|
| 165 |
1 |
@Test... |
| 166 |
|
public void testRegisterComponentInDocumentComponentManager() throws Exception |
| 167 |
|
{ |
| 168 |
1 |
final States state = getMockery().states("test"); |
| 169 |
|
|
| 170 |
1 |
getMockery().checking(new Expectations() |
| 171 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
| 172 |
1 |
{... |
| 173 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 174 |
1 |
when(state.isNot("otherdocument")); |
| 175 |
1 |
will(returnValue("wiki1")); |
| 176 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 177 |
1 |
when(state.isNot("otherdocument")); |
| 178 |
1 |
will(returnValue(new SpaceReference("space1", new WikiReference("wiki")))); |
| 179 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 180 |
1 |
when(state.isNot("otherdocument")); |
| 181 |
1 |
will(returnValue(new DocumentReference("wiki1", "space1", "document1"))); |
| 182 |
1 |
allowing(mockDocumentAccessBridge).getCurrentUserReference(); |
| 183 |
1 |
when(state.isNot("otherdocument")); |
| 184 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user"))); |
| 185 |
|
} |
| 186 |
|
}); |
| 187 |
|
|
| 188 |
1 |
ComponentManager documentCM = getComponentManager().getInstance(ComponentManager.class, "document"); |
| 189 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
| 190 |
1 |
cd.setRole(Role.class); |
| 191 |
1 |
cd.setImplementation(RoleImpl.class); |
| 192 |
|
|
| 193 |
|
|
| 194 |
1 |
documentCM.registerComponent(cd); |
| 195 |
|
|
| 196 |
|
|
| 197 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 198 |
1 |
Assert.assertNotNull(contextCM.getInstance(Role.class)); |
| 199 |
|
|
| 200 |
|
|
| 201 |
1 |
state.become("otherdocument"); |
| 202 |
1 |
getMockery().checking(new Expectations() |
| 203 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 204 |
1 |
{... |
| 205 |
1 |
exactly(1).of(mockDocumentAccessBridge).getCurrentUserReference(); |
| 206 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user"))); |
| 207 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 208 |
1 |
will(returnValue("wiki2")); |
| 209 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 210 |
1 |
will(returnValue(new SpaceReference("space2", new WikiReference("wiki2")))); |
| 211 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 212 |
1 |
will(returnValue(new DocumentReference("wiki2", "space2", "document2"))); |
| 213 |
|
} |
| 214 |
|
}); |
| 215 |
|
|
| 216 |
1 |
try { |
| 217 |
1 |
contextCM.getInstance(Role.class); |
| 218 |
0 |
Assert.fail("Should have raised an exception"); |
| 219 |
|
} catch (ComponentLookupException expected) { |
| 220 |
|
|
| 221 |
|
} |
| 222 |
|
} |
| 223 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 224 |
1 |
@Test... |
| 225 |
|
public void testDeleteDocument() throws Exception |
| 226 |
|
{ |
| 227 |
1 |
getMockery().checking(new Expectations() |
| 228 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 229 |
1 |
{... |
| 230 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 231 |
1 |
will(returnValue("wiki")); |
| 232 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 233 |
1 |
will(returnValue(new SpaceReference("space", new WikiReference("wiki")))); |
| 234 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 235 |
1 |
will(returnValue(new DocumentReference("wiki", "space", "document"))); |
| 236 |
1 |
allowing(mockDocumentAccessBridge).getCurrentUserReference(); |
| 237 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user"))); |
| 238 |
|
} |
| 239 |
|
}); |
| 240 |
|
|
| 241 |
1 |
ComponentManager documentCM = getComponentManager().getInstance(ComponentManager.class, "document"); |
| 242 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
| 243 |
1 |
cd.setRoleType(Role.class); |
| 244 |
1 |
cd.setImplementation(RoleImpl.class); |
| 245 |
|
|
| 246 |
|
|
| 247 |
1 |
documentCM.registerComponent(cd); |
| 248 |
|
|
| 249 |
|
|
| 250 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 251 |
1 |
Assert.assertNotNull(contextCM.getComponentDescriptor(Role.class, "default")); |
| 252 |
|
|
| 253 |
1 |
ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class); |
| 254 |
|
|
| 255 |
1 |
observationManager.notify(new DocumentDeletedEvent(new DocumentReference("wiki", "space", "document")), null, |
| 256 |
|
null); |
| 257 |
|
|
| 258 |
1 |
Assert.assertNull(contextCM.getComponentDescriptor(Role.class, "default")); |
| 259 |
|
} |
| 260 |
|
|
| |
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 2 |
Complexity Density: 0.14 |
1PASS
|
|
| 261 |
1 |
@Test... |
| 262 |
|
public void testRegisterComponentInSpaceComponentManager() throws Exception |
| 263 |
|
{ |
| 264 |
1 |
final States state = getMockery().states("test"); |
| 265 |
|
|
| 266 |
1 |
getMockery().checking(new Expectations() |
| 267 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
| 268 |
1 |
{... |
| 269 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 270 |
1 |
when(state.isNot("otherspace")); |
| 271 |
1 |
will(returnValue("wiki1")); |
| 272 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 273 |
1 |
when(state.isNot("otherspace")); |
| 274 |
1 |
will(returnValue(new SpaceReference("space1", new WikiReference("wiki1")))); |
| 275 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 276 |
1 |
when(state.isNot("otherspace")); |
| 277 |
1 |
will(returnValue(new DocumentReference("wiki1", "space1", "document1"))); |
| 278 |
1 |
allowing(mockDocumentAccessBridge).getCurrentUserReference(); |
| 279 |
1 |
when(state.isNot("otherspace")); |
| 280 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user"))); |
| 281 |
|
} |
| 282 |
|
}); |
| 283 |
|
|
| 284 |
1 |
ComponentManager userCM = getComponentManager().getInstance(ComponentManager.class, "space"); |
| 285 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
| 286 |
1 |
cd.setRole(Role.class); |
| 287 |
1 |
cd.setImplementation(RoleImpl.class); |
| 288 |
|
|
| 289 |
|
|
| 290 |
1 |
userCM.registerComponent(cd); |
| 291 |
|
|
| 292 |
|
|
| 293 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 294 |
1 |
Assert.assertNotNull(contextCM.getInstance(Role.class)); |
| 295 |
|
|
| 296 |
|
|
| 297 |
1 |
state.become("otherspace"); |
| 298 |
1 |
getMockery().checking(new Expectations() |
| 299 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 300 |
1 |
{... |
| 301 |
1 |
exactly(1).of(mockDocumentAccessBridge).getCurrentUserReference(); |
| 302 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user"))); |
| 303 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 304 |
1 |
will(returnValue("wiki2")); |
| 305 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 306 |
1 |
will(returnValue(new SpaceReference("space2", new WikiReference("wiki2")))); |
| 307 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 308 |
1 |
will(returnValue(new DocumentReference("wiki2", "space2", "document2"))); |
| 309 |
|
} |
| 310 |
|
}); |
| 311 |
|
|
| 312 |
1 |
try { |
| 313 |
1 |
contextCM.getInstance(Role.class); |
| 314 |
0 |
Assert.fail("Should have raised an exception"); |
| 315 |
|
} catch (ComponentLookupException expected) { |
| 316 |
|
|
| 317 |
|
} |
| 318 |
|
} |
| 319 |
|
|
| |
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 2 |
Complexity Density: 0.14 |
1PASS
|
|
| 320 |
1 |
@Test... |
| 321 |
|
public void testRegisterComponentInWikiComponentManager() throws Exception |
| 322 |
|
{ |
| 323 |
1 |
final States state = getMockery().states("test"); |
| 324 |
|
|
| 325 |
1 |
getMockery().checking(new Expectations() |
| 326 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
| 327 |
1 |
{... |
| 328 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 329 |
1 |
when(state.isNot("otherwiki")); |
| 330 |
1 |
will(returnValue("wiki1")); |
| 331 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 332 |
1 |
when(state.isNot("otherwiki")); |
| 333 |
1 |
will(returnValue(new SpaceReference("space1", new WikiReference("wiki1")))); |
| 334 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 335 |
1 |
when(state.isNot("otherwiki")); |
| 336 |
1 |
will(returnValue(new DocumentReference("wiki1", "space1", "document1"))); |
| 337 |
1 |
allowing(mockDocumentAccessBridge).getCurrentUserReference(); |
| 338 |
1 |
when(state.isNot("otherwiki")); |
| 339 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user"))); |
| 340 |
|
} |
| 341 |
|
}); |
| 342 |
|
|
| 343 |
|
|
| 344 |
1 |
ComponentManager wikiCM = getComponentManager().getInstance(ComponentManager.class, "wiki"); |
| 345 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
| 346 |
1 |
cd.setRole(Role.class); |
| 347 |
1 |
cd.setImplementation(RoleImpl.class); |
| 348 |
1 |
wikiCM.registerComponent(cd); |
| 349 |
|
|
| 350 |
|
|
| 351 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 352 |
1 |
Assert.assertNotNull(contextCM.getComponentDescriptor(Role.class, "default")); |
| 353 |
|
|
| 354 |
|
|
| 355 |
1 |
state.become("otherwiki"); |
| 356 |
|
|
| 357 |
1 |
getMockery().checking(new Expectations() |
| 358 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 359 |
1 |
{... |
| 360 |
1 |
exactly(1).of(mockDocumentAccessBridge).getCurrentUserReference(); |
| 361 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user"))); |
| 362 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 363 |
1 |
will(returnValue("wiki2")); |
| 364 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 365 |
1 |
will(returnValue(new SpaceReference("space2", new WikiReference("wiki2")))); |
| 366 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 367 |
1 |
will(returnValue(new DocumentReference("wiki2", "space2", "document2"))); |
| 368 |
|
} |
| 369 |
|
}); |
| 370 |
|
|
| 371 |
1 |
try { |
| 372 |
1 |
contextCM.getInstance(Role.class); |
| 373 |
0 |
Assert.fail("Should have raised an exception"); |
| 374 |
|
} catch (ComponentLookupException expected) { |
| 375 |
|
|
| 376 |
|
} |
| 377 |
|
} |
| 378 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 379 |
1 |
@Test... |
| 380 |
|
public void testDeleteWiki() throws ComponentLookupException, Exception |
| 381 |
|
{ |
| 382 |
1 |
getMockery().checking(new Expectations() |
| 383 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 384 |
1 |
{... |
| 385 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 386 |
1 |
will(returnValue("wiki")); |
| 387 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 388 |
1 |
will(returnValue(new SpaceReference("space", new WikiReference("wiki")))); |
| 389 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 390 |
1 |
will(returnValue(new DocumentReference("wiki", "space", "document"))); |
| 391 |
1 |
allowing(mockDocumentAccessBridge).getCurrentUserReference(); |
| 392 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user"))); |
| 393 |
|
} |
| 394 |
|
}); |
| 395 |
|
|
| 396 |
|
|
| 397 |
1 |
ComponentManager wikiCM = getComponentManager().getInstance(ComponentManager.class, "wiki"); |
| 398 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
| 399 |
1 |
cd.setRoleType(Role.class); |
| 400 |
1 |
cd.setImplementation(RoleImpl.class); |
| 401 |
1 |
wikiCM.registerComponent(cd); |
| 402 |
|
|
| 403 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 404 |
1 |
Assert.assertNotNull(contextCM.getComponentDescriptor(Role.class, "default")); |
| 405 |
|
|
| 406 |
1 |
ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class); |
| 407 |
|
|
| 408 |
1 |
observationManager.notify(new WikiDeletedEvent("wiki"), null, null); |
| 409 |
|
|
| 410 |
1 |
Assert.assertNull(contextCM.getComponentDescriptor(Role.class, "default")); |
| 411 |
|
} |
| 412 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 413 |
1 |
@Test... |
| 414 |
|
public void testRegisterComponentInRootComponentManager() throws Exception |
| 415 |
|
{ |
| 416 |
1 |
final States state = getMockery().states("test"); |
| 417 |
|
|
| 418 |
1 |
getMockery().checking(new Expectations() |
| 419 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
| 420 |
1 |
{... |
| 421 |
1 |
allowing(mockWikiDescriptorManager).getCurrentWikiId(); |
| 422 |
1 |
when(state.isNot("otherwiki")); |
| 423 |
1 |
will(returnValue("wiki")); |
| 424 |
1 |
allowing(mockCurrentSpaceReferenceProvider).get(); |
| 425 |
1 |
when(state.isNot("otherwiki")); |
| 426 |
1 |
will(returnValue(new SpaceReference("space", new WikiReference("wiki")))); |
| 427 |
1 |
allowing(mockCurrentDocumentReferenceProvider).get(); |
| 428 |
1 |
when(state.isNot("otherwiki")); |
| 429 |
1 |
will(returnValue(new DocumentReference("wiki", "space", "document"))); |
| 430 |
1 |
allowing(mockDocumentAccessBridge).getCurrentUserReference(); |
| 431 |
1 |
when(state.isNot("otherwiki")); |
| 432 |
1 |
will(returnValue(new DocumentReference("wiki", "XWiki", "user"))); |
| 433 |
|
} |
| 434 |
|
}); |
| 435 |
|
|
| 436 |
|
|
| 437 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
| 438 |
1 |
cd.setRole(Role.class); |
| 439 |
1 |
cd.setImplementation(RoleImpl.class); |
| 440 |
1 |
getComponentManager().registerComponent(cd); |
| 441 |
|
|
| 442 |
|
|
| 443 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 444 |
1 |
Assert.assertNotNull(contextCM.getInstance(Role.class)); |
| 445 |
|
} |
| 446 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 447 |
1 |
@Test... |
| 448 |
|
public void testCreateDocumentComponentManager() throws Exception |
| 449 |
|
{ |
| 450 |
1 |
ComponentManagerManager manager = getComponentManager().getInstance(ComponentManagerManager.class); |
| 451 |
|
|
| 452 |
1 |
NamespacedComponentManager componentManager = |
| 453 |
|
(NamespacedComponentManager) manager.getComponentManager("document:wiki1:space1.space2.document1", true); |
| 454 |
|
|
| 455 |
1 |
assertNotNull(componentManager); |
| 456 |
1 |
assertEquals("document:wiki1:space1.space2.document1", componentManager.getNamespace()); |
| 457 |
1 |
assertEquals("space:wiki1:space1.space2", ((NamespacedComponentManager)componentManager.getParent()).getNamespace()); |
| 458 |
1 |
assertEquals("space:wiki1:space1", ((NamespacedComponentManager)componentManager.getParent().getParent()).getNamespace()); |
| 459 |
1 |
assertEquals("wiki:wiki1", ((NamespacedComponentManager)componentManager.getParent().getParent().getParent()).getNamespace()); |
| 460 |
|
} |
| 461 |
|
|
| 462 |
|
|
| 463 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
| 464 |
1 |
@Test... |
| 465 |
|
public void testRegisterComponentInContextComponentManagerThrowsException() throws Exception |
| 466 |
|
{ |
| 467 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 468 |
1 |
try { |
| 469 |
1 |
contextCM.registerComponent(new DefaultComponentDescriptor<Role>()); |
| 470 |
0 |
Assert.fail("Should have thrown an exception error"); |
| 471 |
|
} catch (RuntimeException expected) { |
| 472 |
1 |
Assert.assertEquals("The Context Component Manager should only be used for read access. Write operations " |
| 473 |
|
+ "should be done against specific Component Managers.", expected.getMessage()); |
| 474 |
|
} |
| 475 |
|
} |
| 476 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 477 |
1 |
@Test(expected = RuntimeException.class)... |
| 478 |
|
public void testRegisterComponentInstance() throws ComponentLookupException, Exception |
| 479 |
|
{ |
| 480 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 481 |
|
|
| 482 |
1 |
contextCM.registerComponent(null, null); |
| 483 |
|
} |
| 484 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 485 |
1 |
@Test(expected = RuntimeException.class)... |
| 486 |
|
public void testRegisterComponentDesciptor() throws ComponentLookupException, Exception |
| 487 |
|
{ |
| 488 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 489 |
|
|
| 490 |
1 |
contextCM.registerComponent(null); |
| 491 |
|
} |
| 492 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 493 |
1 |
@Test(expected = RuntimeException.class)... |
| 494 |
|
public void testSetComponentEventManager() throws ComponentLookupException, Exception |
| 495 |
|
{ |
| 496 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 497 |
|
|
| 498 |
1 |
contextCM.setComponentEventManager(null); |
| 499 |
|
} |
| 500 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 501 |
1 |
@Test(expected = RuntimeException.class)... |
| 502 |
|
public void testSetParent() throws ComponentLookupException, Exception |
| 503 |
|
{ |
| 504 |
1 |
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context"); |
| 505 |
|
|
| 506 |
1 |
contextCM.setParent(null); |
| 507 |
|
} |
| 508 |
|
} |