Search in sources :

Example 6 with EntityReferenceResolver

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

the class XWikiLinkLabelGeneratorTest method generateWhenNestedPage.

@Test
public void generateWhenNestedPage() throws Exception {
    ResourceReference resourceReference = new DocumentResourceReference("WebHome");
    DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("space1", "NestedPage"), "WebHome");
    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", "NestedPage"))).thenReturn("space1.NestedPage");
    assertEquals("%l%la%n%na%N%NA " + "[wiki:space1.NestedPage.WebHome] NestedPage NestedPage Web Home Nested Page (My title) " + "[wiki:space1.NestedPage.WebHome] NestedPage NestedPage Web Home Nested Page (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 7 with EntityReferenceResolver

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

the class XWikiLinkLabelGeneratorTest method generateWhenDocumentFailsToLoad.

@Test
public void generateWhenDocumentFailsToLoad() 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);
    when(dab.getTranslatedDocumentInstance(documentReference)).thenThrow(new Exception("error"));
    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 : 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)

Aggregations

DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)7 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)7 Test (org.junit.Test)6 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)6 DocumentReference (org.xwiki.model.reference.DocumentReference)6 SpaceReference (org.xwiki.model.reference.SpaceReference)6 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)6 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)6 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)5 DefaultComponentDependency (org.xwiki.component.descriptor.DefaultComponentDependency)1 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)1 ComponentRepositoryException (org.xwiki.component.manager.ComponentRepositoryException)1 InitializationException (org.xwiki.component.phase.InitializationException)1 EntityReference (org.xwiki.model.reference.EntityReference)1 ResourceReferenceResolver (org.xwiki.resource.ResourceReferenceResolver)1 EntityResourceActionLister (org.xwiki.resource.internal.entity.EntityResourceActionLister)1 ExtendedURL (org.xwiki.url.ExtendedURL)1 BinEntityResourceReferenceResolver (org.xwiki.url.internal.standard.entity.BinEntityResourceReferenceResolver)1 WikiEntityResourceReferenceResolver (org.xwiki.url.internal.standard.entity.WikiEntityResourceReferenceResolver)1