use of org.xwiki.component.descriptor.DefaultComponentDescriptor in project xwiki-platform by xwiki.
the class ContextComponentManagerTest method testRegisterComponentInRootComponentManager.
@Test
public void testRegisterComponentInRootComponentManager() throws Exception {
final States state = getMockery().states("test");
getMockery().checking(new Expectations() {
{
allowing(mockWikiDescriptorManager).getCurrentWikiId();
when(state.isNot("otherwiki"));
will(returnValue("wiki"));
allowing(mockCurrentSpaceReferenceProvider).get();
when(state.isNot("otherwiki"));
will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
allowing(mockCurrentDocumentReferenceProvider).get();
when(state.isNot("otherwiki"));
will(returnValue(new DocumentReference("wiki", "space", "document")));
allowing(mockDocumentAccessBridge).getCurrentUserReference();
when(state.isNot("otherwiki"));
will(returnValue(new DocumentReference("wiki", "XWiki", "user")));
}
});
// Register in the current wiki.
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>();
cd.setRoleType(Role.class);
cd.setImplementation(RoleImpl.class);
getComponentManager().registerComponent(cd);
// Verify we can lookup the component from the context CM.
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
Assert.assertNotNull(contextCM.getInstance(Role.class));
}
use of org.xwiki.component.descriptor.DefaultComponentDescriptor in project xwiki-platform by xwiki.
the class ContextComponentManagerTest method testDeleteDocument.
@Test
public void testDeleteDocument() throws Exception {
getMockery().checking(new Expectations() {
{
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")));
allowing(mockDocumentAccessBridge).getCurrentUserReference();
will(returnValue(new DocumentReference("wiki", "XWiki", "user")));
}
});
ComponentManager documentCM = getComponentManager().getInstance(ComponentManager.class, "document");
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>();
cd.setRoleType(Role.class);
cd.setImplementation(RoleImpl.class);
// Register component for the current user
documentCM.registerComponent(cd);
// Verify we can lookup the component from the Context CM
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
Assert.assertNotNull(contextCM.getComponentDescriptor(Role.class, "default"));
ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class);
observationManager.notify(new DocumentDeletedEvent(new DocumentReference("wiki", "space", "document")), null, null);
Assert.assertNull(contextCM.getComponentDescriptor(Role.class, "default"));
}
use of org.xwiki.component.descriptor.DefaultComponentDescriptor in project xwiki-platform by xwiki.
the class ContextComponentManagerTest method testRegisterComponentInSpaceComponentManager.
@Test
public void testRegisterComponentInSpaceComponentManager() throws Exception {
final States state = getMockery().states("test");
getMockery().checking(new Expectations() {
{
allowing(mockWikiDescriptorManager).getCurrentWikiId();
when(state.isNot("otherspace"));
will(returnValue("wiki1"));
allowing(mockCurrentSpaceReferenceProvider).get();
when(state.isNot("otherspace"));
will(returnValue(new SpaceReference("space1", new WikiReference("wiki1"))));
allowing(mockCurrentDocumentReferenceProvider).get();
when(state.isNot("otherspace"));
will(returnValue(new DocumentReference("wiki1", "space1", "document1")));
allowing(mockDocumentAccessBridge).getCurrentUserReference();
when(state.isNot("otherspace"));
will(returnValue(new DocumentReference("wiki", "XWiki", "user")));
}
});
ComponentManager userCM = getComponentManager().getInstance(ComponentManager.class, "space");
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>();
cd.setRoleType(Role.class);
cd.setImplementation(RoleImpl.class);
// Register component for the current user
userCM.registerComponent(cd);
// Verify we can lookup the component from the Context CM
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
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("otherspace");
getMockery().checking(new Expectations() {
{
exactly(1).of(mockDocumentAccessBridge).getCurrentUserReference();
will(returnValue(new DocumentReference("wiki", "XWiki", "user")));
allowing(mockWikiDescriptorManager).getCurrentWikiId();
will(returnValue("wiki2"));
allowing(mockCurrentSpaceReferenceProvider).get();
will(returnValue(new SpaceReference("space2", new WikiReference("wiki2"))));
allowing(mockCurrentDocumentReferenceProvider).get();
will(returnValue(new DocumentReference("wiki2", "space2", "document2")));
}
});
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.descriptor.DefaultComponentDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiComponentManager method createComponentDescriptor.
/**
* Helper method to create a component descriptor from role and hint.
*
* @param roleType the component role type of the descriptor to create
* @param roleHint the hint of the implementation for the descriptor to create
* @return the constructed {@link ComponentDescriptor}
*/
private ComponentDescriptor createComponentDescriptor(Type roleType, String roleHint) {
DefaultComponentDescriptor cd = new DefaultComponentDescriptor();
cd.setRoleType(roleType);
cd.setRoleHint(roleHint);
return cd;
}
Aggregations