use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class ContextComponentManagerTest method testRegisterComponentInContextComponentManagerThrowsException.
// Failures
@Test
public void testRegisterComponentInContextComponentManagerThrowsException() throws Exception {
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
try {
contextCM.registerComponent(new DefaultComponentDescriptor<Role>());
Assert.fail("Should have thrown an exception error");
} catch (RuntimeException expected) {
Assert.assertEquals("The Context Component Manager should only be used for read access. Write operations " + "should be done against specific Component Managers.", expected.getMessage());
}
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class ContextComponentManagerTest method testRegisterComponentInUserComponentManager.
@Test
public void testRegisterComponentInUserComponentManager() throws Exception {
final States state = getMockery().states("test");
getMockery().checking(new Expectations() {
{
allowing(mockDocumentAccessBridge).getCurrentUserReference();
when(state.isNot("otheruser"));
will(returnValue(new DocumentReference("wiki", "XWiki", "user1")));
allowing(mockWikiDescriptorManager).getCurrentWikiId();
will(returnValue("wiki"));
allowing(mockCurrentSpaceReferenceProvider).get();
will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
allowing(mockCurrentDocumentReferenceProvider).get();
will(returnValue(new DocumentReference("wiki", "space", "document")));
}
});
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
try {
contextCM.getInstance(Role.class);
Assert.fail("Should have raised an exception");
} catch (ComponentLookupException expected) {
// No need to assert the message, we just want to ensure an exception is raised.
}
// Register component for the current user
ComponentManager userCM = getComponentManager().getInstance(ComponentManager.class, "user");
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>();
cd.setRoleType(Role.class);
cd.setImplementation(RoleImpl.class);
userCM.registerComponent(cd);
// Verify we can lookup the component from the Context CM
Assert.assertNotNull(contextCM.getInstance(Role.class));
// Now verify that we cannot look it up anymore if there's another user in the context
state.become("otheruser");
getMockery().checking(new Expectations() {
{
allowing(mockDocumentAccessBridge).getCurrentUserReference();
will(returnValue(new DocumentReference("wiki", "XWiki", "user2")));
allowing(mockWikiDescriptorManager).getCurrentWikiId();
will(returnValue("wiki"));
allowing(mockCurrentSpaceReferenceProvider).get();
will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
allowing(mockCurrentDocumentReferenceProvider).get();
will(returnValue(new DocumentReference("wiki", "space", "document")));
}
});
try {
contextCM.getInstance(Role.class);
Assert.fail("Should have raised an exception");
} catch (ComponentLookupException expected) {
// No need to assert the message, we just want to ensure an exception is raised.
}
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class ContextComponentManagerTest method testRegisterComponentDesciptor.
@Test(expected = RuntimeException.class)
public void testRegisterComponentDesciptor() throws ComponentLookupException, Exception {
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
contextCM.registerComponent(null);
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class ContextComponentManagerTest method testSetParent.
@Test(expected = RuntimeException.class)
public void testSetParent() throws ComponentLookupException, Exception {
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
contextCM.setParent(null);
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class ContextComponentManagerTest method testSetComponentEventManager.
@Test(expected = RuntimeException.class)
public void testSetComponentEventManager() throws ComponentLookupException, Exception {
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
contextCM.setComponentEventManager(null);
}
Aggregations