Search in sources :

Example 51 with EntityReference

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

the class DefaultStringEntityReferenceSerializerTest method serializeWikiReferences.

@Test
public void serializeWikiReferences() throws Exception {
    EntityReference reference = resolver.resolve("wiki", EntityType.WIKI);
    assertEquals("wiki", serializer.serialize(reference));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 52 with EntityReference

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

the class DefaultStringEntityReferenceSerializerTest method serializeObjectReferences.

/**
 * Tests resolving and re-serializing an object reference.
 */
@Test
public void serializeObjectReferences() {
    EntityReference reference = resolver.resolve("wiki:space.page^Object", EntityType.OBJECT);
    assertEquals("wiki:space.page^Object", serializer.serialize(reference));
    // default values
    reference = resolver.resolve("", EntityType.OBJECT);
    assertEquals("defwiki:defspace.defpage^defobject", serializer.serialize(reference));
    // property reference with no object
    reference = resolver.resolve("wiki:space.page.property", EntityType.OBJECT);
    assertEquals("defwiki:defspace.defpage^wiki:space.page.property", serializer.serialize(reference));
    // test escaping character
    reference = resolver.resolve("wiki:space.page^Obje\\^ct", EntityType.OBJECT);
    assertEquals("wiki:space.page^Obje\\^ct", serializer.serialize(reference));
    reference = resolver.resolve("wiki:spa^ce.page^Obje\\^ct", EntityType.OBJECT);
    assertEquals("wiki:spa^ce.page^Obje\\^ct", serializer.serialize(reference));
    reference = resolver.resolve(":.\\^@", EntityType.OBJECT);
    assertEquals("defwiki:defspace.defpage^:.\\^@", serializer.serialize(reference));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 53 with EntityReference

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

the class DefaultStringEntityReferenceSerializerTest method serializeReferencesWithChild.

@Test
public void serializeReferencesWithChild() {
    EntityReference reference = resolver.resolve("wiki:Space.Page", EntityType.DOCUMENT);
    assertEquals("wiki:Space", serializer.serialize(reference.getParent()));
    assertEquals("wiki", serializer.serialize(reference.getParent().getParent()));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 54 with EntityReference

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

the class ExplicitReferenceEntityReferenceResolverTest method testResolveWithExplicitEntityReference.

@Test
public void testResolveWithExplicitEntityReference() {
    EntityReference reference = this.resolver.resolve(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE)), EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI));
    Assert.assertEquals("page", reference.getName());
    Assert.assertEquals(EntityType.DOCUMENT, reference.getType());
    Assert.assertEquals("space", reference.getParent().getName());
    Assert.assertEquals(EntityType.SPACE, reference.getParent().getType());
    Assert.assertEquals("wiki", reference.getParent().getParent().getName());
    Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType());
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 55 with EntityReference

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

the class ExplicitReferenceEntityReferenceResolverTest method testResolveWithExplicitReferenceWithHoles.

@Test
public void testResolveWithExplicitReferenceWithHoles() {
    EntityReference reference = this.resolver.resolve(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE)), EntityType.DOCUMENT, new EntityReference("page", EntityType.DOCUMENT, new EntityReference("wiki", EntityType.WIKI)));
    Assert.assertEquals("page", reference.getName());
    Assert.assertEquals(EntityType.DOCUMENT, reference.getType());
    Assert.assertEquals("space", reference.getParent().getName());
    Assert.assertEquals(EntityType.SPACE, reference.getParent().getType());
    Assert.assertEquals("wiki", reference.getParent().getParent().getName());
    Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType());
}
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