use of org.xwiki.model.reference.SpaceReference 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.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultStringEntityReferenceResolverTest method testResolveSpaceReference.
/**
* Tests resolving space references.
*/
@Test
public void testResolveSpaceReference() {
SpaceReference reference = new SpaceReference(this.resolver.resolve("space", EntityType.SPACE));
assertEquals("space", reference.getName());
// several spaces
reference = new SpaceReference(this.resolver.resolve("space1.space2", EntityType.SPACE));
assertEquals("space2", reference.getName());
assertEquals("space1", reference.getParent().getName());
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultStringSpaceReferenceResolverTest method resolveWithExplicitSpaceReference.
@Test
public void resolveWithExplicitSpaceReference() {
SpaceReference reference = this.resolver.resolve("", new SpaceReference("space", new WikiReference("wiki")));
Assert.assertEquals("space", reference.getName());
Assert.assertEquals("wiki", reference.getWikiReference().getName());
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class ModelScriptServiceTest method resolveSpaceWithHintAndParameters.
@Test
public void resolveSpaceWithHintAndParameters() throws Exception {
when(this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, "custom")).thenReturn(this.stringEntityReferenceResolver);
SpaceReference reference = new SpaceReference("Foo", new WikiReference("bar"));
Object[] parameters = new Object[] { new DocumentReference("wiki", "Space", "Page"), "extra" };
when(this.stringEntityReferenceResolver.resolve("reference", EntityType.SPACE, parameters)).thenReturn(reference);
Assert.assertEquals(reference, this.service.resolveSpace("reference", "custom", parameters[0], parameters[1]));
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class ModelScriptServiceTest method resolveSpace.
@Test
public void resolveSpace() throws Exception {
when(this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, "current")).thenReturn(this.stringEntityReferenceResolver);
SpaceReference reference = new SpaceReference("Space", new WikiReference("wiki"));
when(this.stringEntityReferenceResolver.resolve("x", EntityType.SPACE, new Object[] {})).thenReturn(reference);
Assert.assertEquals(reference, this.service.resolveSpace("x"));
}
Aggregations