Search in sources :

Example 1 with DocumentResourceReference

use of org.xwiki.rendering.listener.reference.DocumentResourceReference in project xwiki-platform by xwiki.

the class XWikiLinkLabelGeneratorTest method generateWhithPageNameWithPercent.

@Test
public void generateWhithPageNameWithPercent() throws Exception {
    ResourceReference resourceReference = new DocumentResourceReference("HelloWorld");
    DocumentReference documentReference = new DocumentReference("wiki", "space", "page%t");
    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", "space"))).thenReturn("space");
    assertEquals("%l%la%n%na%N%NA " + "[wiki:space.page%t] space page%t page%t page%t (my title) " + "[wiki:space.page%t] space page%t page%t page%t (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 2 with DocumentResourceReference

use of org.xwiki.rendering.listener.reference.DocumentResourceReference in project xwiki-platform by xwiki.

the class XWikiLinkLabelGeneratorTest method generateWhenDocumentTitleIsNull.

@Test
public void generateWhenDocumentTitleIsNull() throws Exception {
    ResourceReference resourceReference = new DocumentResourceReference("HelloWorld");
    DocumentReference documentReference = new DocumentReference("xwiki", "Main", "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(null);
    EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
    when(localSerializer.serialize(new SpaceReference("xwiki", "Main"))).thenReturn("Main");
    assertEquals("%l%la%n%na%N%NA " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld) " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld)", 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 3 with DocumentResourceReference

use of org.xwiki.rendering.listener.reference.DocumentResourceReference 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 4 with DocumentResourceReference

use of org.xwiki.rendering.listener.reference.DocumentResourceReference 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 5 with DocumentResourceReference

use of org.xwiki.rendering.listener.reference.DocumentResourceReference in project xwiki-platform by xwiki.

the class DefaultResourceReferenceEntityReferenceResolverTest method documentResource.

private DocumentResourceReference documentResource(String referenceString, boolean typed) {
    DocumentResourceReference reference = new DocumentResourceReference(referenceString);
    reference.setTyped(typed);
    return reference;
}
Also used : DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference)

Aggregations

DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)11 Test (org.junit.Test)9 DocumentReference (org.xwiki.model.reference.DocumentReference)7 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)7 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)6 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)6 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)6 SpaceReference (org.xwiki.model.reference.SpaceReference)6 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)5 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Expectations (org.jmock.Expectations)1 Block (org.xwiki.rendering.block.Block)1 BlockFilter (org.xwiki.rendering.block.BlockFilter)1 HeaderBlock (org.xwiki.rendering.block.HeaderBlock)1 IdBlock (org.xwiki.rendering.block.IdBlock)1 LinkBlock (org.xwiki.rendering.block.LinkBlock)1 NewLineBlock (org.xwiki.rendering.block.NewLineBlock)1 SectionBlock (org.xwiki.rendering.block.SectionBlock)1