Search in sources :

Example 66 with EntityReference

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

the class UidStringEntityReferenceSerializerTest method serializeAttachmentReference.

@Test
public void serializeAttachmentReference() throws Exception {
    EntityReference reference = resolver.resolve("wiki:space.page@filename", EntityType.ATTACHMENT);
    Assert.assertEquals("4:wiki5:space4:page8:filename", serializer.serialize(reference));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 67 with EntityReference

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

the class UidStringEntityReferenceSerializerTest method serializeObjectPropertyReference.

/**
 * Tests resolving and re-serializing an property reference.
 */
@Test
public void serializeObjectPropertyReference() {
    EntityReference reference = resolver.resolve("wiki:space.page^wiki:space.class[0].prop", EntityType.OBJECT_PROPERTY);
    Assert.assertEquals("4:wiki5:space4:page19:wiki:space.class[0]4:prop", serializer.serialize(reference));
    reference = resolver.resolve("wiki:space.page^xwiki:space.class[0].prop", EntityType.OBJECT_PROPERTY);
    Assert.assertEquals("4:wiki5:space4:page20:xwiki:space.class[0]4:prop", serializer.serialize(reference));
    // test escaping character
    reference = resolver.resolve("wiki:space.page^wiki:space.class[0].prop\\.erty", EntityType.OBJECT_PROPERTY);
    Assert.assertEquals("4:wiki5:space4:page19:wiki:space.class[0]9:prop.erty", serializer.serialize(reference));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 68 with EntityReference

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

the class UidStringEntityReferenceSerializerTest method serializeDocumentReference.

@Test
public void serializeDocumentReference() throws Exception {
    EntityReference reference = resolver.resolve("wiki:space.page", EntityType.DOCUMENT);
    Assert.assertEquals("4:wiki5:space4:page", serializer.serialize(reference));
    reference = resolver.resolve("wiki1.wiki2:wiki3:some.space.page", EntityType.DOCUMENT);
    Assert.assertEquals("17:wiki1.wiki2:wiki34:some5:space4:page", serializer.serialize(reference));
    // Verify that passing null doesn't throw a NPE
    Assert.assertNull(serializer.serialize(null));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 69 with EntityReference

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

the class UidStringEntityReferenceSerializerTest method serializeClassPropertyReference.

/**
 * Tests resolving and re-serializing an class property reference.
 */
@Test
public void serializeClassPropertyReference() {
    EntityReference reference = resolver.resolve("wiki:space.page^ClassProperty", EntityType.CLASS_PROPERTY);
    Assert.assertEquals("4:wiki5:space4:page13:ClassProperty", serializer.serialize(reference));
    // test escaping character
    reference = resolver.resolve("wiki:space.page^ClassPro\\^perty", EntityType.CLASS_PROPERTY);
    Assert.assertEquals("4:wiki5:space4:page14:ClassPro^perty", serializer.serialize(reference));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 70 with EntityReference

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

the class UidStringEntityReferenceSerializerTest method serializeRelativeReference.

@Test
public void serializeRelativeReference() {
    EntityReference reference = new EntityReference("page", EntityType.DOCUMENT);
    Assert.assertEquals("4:page", serializer.serialize(reference));
    reference = new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE));
    Assert.assertEquals("5:space4:page", serializer.serialize(reference));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Aggregations

EntityReference (org.xwiki.model.reference.EntityReference)338 Test (org.junit.Test)157 DocumentReference (org.xwiki.model.reference.DocumentReference)107 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)39 BaseObject (com.xpn.xwiki.objects.BaseObject)38 ArrayList (java.util.ArrayList)27 XWikiContext (com.xpn.xwiki.XWikiContext)24 WikiReference (org.xwiki.model.reference.WikiReference)24 SpaceReference (org.xwiki.model.reference.SpaceReference)23 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)18 XWikiException (com.xpn.xwiki.XWikiException)17 EntityType (org.xwiki.model.EntityType)11 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)10 EntityReferenceProvider (org.xwiki.model.reference.EntityReferenceProvider)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 XDOM (org.xwiki.rendering.block.XDOM)8 URL (java.net.URL)7 AttachmentReference (org.xwiki.model.reference.AttachmentReference)7 HashMap (java.util.HashMap)6 Before (org.junit.Before)6