Search in sources :

Example 21 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class XWikiLinkLabelGeneratorTest method generateWhenTerminalPage.

@Test
public void generateWhenTerminalPage() throws Exception {
    ResourceReference resourceReference = new DocumentResourceReference("HelloWorld");
    DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("space1", "space2"), "HelloWorld");
    EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
    when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
    DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
    DocumentModelBridge dmb = mock(DocumentModelBridge.class);
    when(dab.getTranslatedDocumentInstance(documentReference)).thenReturn(dmb);
    when(dmb.getTitle()).thenReturn("My title");
    EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
    when(localSerializer.serialize(new SpaceReference("wiki", "space1", "space2"))).thenReturn("space1.space2");
    assertEquals("%l%la%n%na%N%NA " + "[wiki:space1.space2.HelloWorld] space2 HelloWorld Hello World Hello World (My title) " + "[wiki:space1.space2.HelloWorld] space2 HelloWorld Hello World Hello World (My title)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
Also used : DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) EntityReferenceResolver(org.xwiki.model.reference.EntityReferenceResolver) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 22 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class XWikiLinkLabelGeneratorTest method generateWhithRegexpSyntax.

@Test
public void generateWhithRegexpSyntax() throws Exception {
    ResourceReference resourceReference = new DocumentResourceReference("HelloWorld");
    DocumentReference documentReference = new DocumentReference("$0", "\\", "$0");
    EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
    when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
    DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
    DocumentModelBridge dmb = mock(DocumentModelBridge.class);
    when(dab.getTranslatedDocumentInstance(documentReference)).thenReturn(dmb);
    when(dmb.getTitle()).thenReturn("$0");
    EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
    when(localSerializer.serialize(new SpaceReference("$0", "\\"))).thenReturn("\\");
    assertEquals("%l%la%n%na%N%NA [$0:\\.$0] \\ $0 $0 $0 ($0) [$0:\\.$0] \\ $0 $0 $0 ($0)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
Also used : DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) EntityReferenceResolver(org.xwiki.model.reference.EntityReferenceResolver) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 23 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class DefaultResourceReferenceEntityReferenceResolverTest method resolveTypeSpace.

@Test
public void resolveTypeSpace() throws ComponentLookupException {
    assertEquals(new SpaceReference(WIKI, SPACE), this.mocker.getComponentUnderTest().resolve(spaceResource(WIKI + ':' + SPACE, true), null));
    assertEquals(new SpaceReference(CURRENT_WIKI, SPACE), this.mocker.getComponentUnderTest().resolve(spaceResource(SPACE, true), null));
    assertEquals(new SpaceReference(CURRENT_WIKI, CURRENT_SPACE), this.mocker.getComponentUnderTest().resolve(spaceResource("", true), null));
    when(this.currentEntityReferenceResolver.resolve(eq(WIKI + ':' + SPACE + '.' + PAGE), eq(EntityType.DOCUMENT), any())).thenReturn(new DocumentReference(WIKI, SPACE, PAGE));
    ResourceReference withBaseReference = spaceResource("", true);
    withBaseReference.addBaseReference(WIKI + ':' + SPACE + '.' + PAGE);
    assertEquals(new SpaceReference(WIKI, SPACE), this.mocker.getComponentUnderTest().resolve(withBaseReference, null));
    assertEquals(new SpaceReference(WIKI, SPACE), this.mocker.getComponentUnderTest().resolve(spaceResource("", true), null, new DocumentReference(WIKI, SPACE, PAGE)));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) SpaceResourceReference(org.xwiki.rendering.listener.reference.SpaceResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 24 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class Utils method getSpaceId.

/**
 * @param wikiName the name of the wiki that contains the space
 * @param spaces the spaces hierarchy
 * @return the space id
 * @throws org.xwiki.rest.XWikiRestException
 */
public static String getSpaceId(String wikiName, List<String> spaces) {
    EntityReferenceSerializer<String> defaultEntityReferenceSerializer = com.xpn.xwiki.web.Utils.getComponent(EntityReferenceSerializer.TYPE_STRING);
    SpaceReference spaceReference = getSpaceReference(spaces, wikiName);
    return defaultEntityReferenceSerializer.serialize(spaceReference);
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference)

Example 25 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class Utils method getSpaceReference.

/**
 * @param spaces the space hierarchy
 * @param wikiName the name of the wiki
 * @return the space reference
 */
public static SpaceReference getSpaceReference(List<String> spaces, String wikiName) {
    EntityReference parentReference = new WikiReference(wikiName);
    SpaceReference spaceReference = null;
    for (String space : spaces) {
        spaceReference = new SpaceReference(space, parentReference);
        parentReference = spaceReference;
    }
    return spaceReference;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference)

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