Search in sources :

Example 31 with SpaceReference

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.
    }
}
Also used : States(org.jmock.States) Expectations(org.jmock.Expectations) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) SpaceReference(org.xwiki.model.reference.SpaceReference) ComponentManager(org.xwiki.component.manager.ComponentManager) NamespacedComponentManager(org.xwiki.component.manager.NamespacedComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 32 with SpaceReference

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());
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) Test(org.junit.Test)

Example 33 with SpaceReference

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());
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 34 with SpaceReference

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]));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 35 with SpaceReference

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"));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Aggregations

SpaceReference (org.xwiki.model.reference.SpaceReference)142 DocumentReference (org.xwiki.model.reference.DocumentReference)96 Test (org.junit.Test)83 WikiReference (org.xwiki.model.reference.WikiReference)58 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)21 ArrayList (java.util.ArrayList)11 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)11 XWikiException (com.xpn.xwiki.XWikiException)9 QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)8 Expectations (org.jmock.Expectations)8 XWikiContext (com.xpn.xwiki.XWikiContext)7 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)7 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)7 ComponentManager (org.xwiki.component.manager.ComponentManager)7 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)7 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)7 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)7 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)7 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)7