Search in sources :

Example 46 with EntityReference

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

the class DefaultReferenceEntityReferenceResolverTest method resolveAttachmentReferenceWhenMissingParentBetweenReferences.

@Test
public void resolveAttachmentReferenceWhenMissingParentBetweenReferences() {
    EntityReference reference = this.resolver.resolve(new EntityReference("filename", EntityType.ATTACHMENT, new EntityReference("wiki", EntityType.WIKI)), EntityType.ATTACHMENT);
    assertEquals(DEFAULT_PAGE, reference.getParent().getName());
    assertEquals(EntityType.DOCUMENT, reference.getParent().getType());
    assertEquals(DEFAULT_SPACE, reference.getParent().getParent().getName());
    assertEquals(EntityType.SPACE, reference.getParent().getParent().getType());
    assertEquals("wiki", reference.getParent().getParent().getParent().getName());
    assertEquals(EntityType.WIKI, reference.getParent().getParent().getParent().getType());
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 47 with EntityReference

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

the class DefaultReferenceEntityReferenceResolverTest method resolveObjectReferenceWhenMissingParents.

/**
 * Tests that a relative object reference is resolved correctly and completed with the default document parent.
 */
@Test
public void resolveObjectReferenceWhenMissingParents() {
    EntityReference reference = resolver.resolve(new EntityReference("object", EntityType.OBJECT), EntityType.OBJECT);
    assertEquals(EntityType.OBJECT, reference.getType());
    assertEquals("object", reference.getName());
    assertEquals(EntityType.DOCUMENT, reference.getParent().getType());
    assertEquals(DEFAULT_PAGE, reference.getParent().getName());
    assertEquals(EntityType.SPACE, reference.getParent().getParent().getType());
    assertEquals(DEFAULT_SPACE, reference.getParent().getParent().getName());
    assertEquals(EntityType.WIKI, reference.getParent().getParent().getParent().getType());
    assertEquals(DEFAULT_WIKI, reference.getParent().getParent().getParent().getName());
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 48 with EntityReference

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

the class DefaultStringEntityReferenceResolverTest method testResolveClassPropertyReference.

/**
 * Tests resolving object references.
 */
@Test
public void testResolveClassPropertyReference() {
    EntityReference reference = new ClassPropertyReference(resolver.resolve("wiki:space.page^ClassProp", EntityType.CLASS_PROPERTY));
    assertEquals("wiki", reference.extractReference(EntityType.WIKI).getName());
    assertEquals("space", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("ClassProp", reference.extractReference(EntityType.CLASS_PROPERTY).getName());
    // default values
    reference = new ClassPropertyReference(resolver.resolve("", EntityType.CLASS_PROPERTY));
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals(DEFAULT_PAGE, reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals(DEFAULT_CLASS_PROPERTY, reference.extractReference(EntityType.CLASS_PROPERTY).getName());
    // without some of the parents
    reference = new ClassPropertyReference(resolver.resolve("space.page^ClassProp", EntityType.CLASS_PROPERTY));
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals("space", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("ClassProp", reference.extractReference(EntityType.CLASS_PROPERTY).getName());
    reference = new ClassPropertyReference(resolver.resolve("page^ClassProp", EntityType.CLASS_PROPERTY));
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("ClassProp", reference.extractReference(EntityType.CLASS_PROPERTY).getName());
    reference = new ClassPropertyReference(resolver.resolve("XWiki.Class", EntityType.CLASS_PROPERTY));
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals(DEFAULT_PAGE, reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("XWiki.Class", reference.extractReference(EntityType.CLASS_PROPERTY).getName());
    // property without object
    reference = new ClassPropertyReference(resolver.resolve("wiki:space.page.property", EntityType.CLASS_PROPERTY));
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals(DEFAULT_PAGE, reference.extractReference(EntityType.DOCUMENT).getName());
    Assert.assertEquals("wiki:space.page.property", reference.extractReference(EntityType.CLASS_PROPERTY).getName());
    // object with no name
    reference = new ClassPropertyReference(resolver.resolve("wiki:space.page^", EntityType.CLASS_PROPERTY));
    assertEquals("wiki", reference.extractReference(EntityType.WIKI).getName());
    assertEquals("space", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals(DEFAULT_CLASS_PROPERTY, reference.extractReference(EntityType.CLASS_PROPERTY).getName());
    // test separator escape
    reference = new ClassPropertyReference(resolver.resolve("wiki:space.page^obje\\^ct", EntityType.CLASS_PROPERTY));
    assertEquals("wiki", reference.extractReference(EntityType.WIKI).getName());
    assertEquals("space", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("obje^ct", reference.extractReference(EntityType.CLASS_PROPERTY).getName());
    // and that separators don't need to be escaped other than in the object name
    reference = new ClassPropertyReference(resolver.resolve("wiki:spa^ce.page^ClassProp", EntityType.CLASS_PROPERTY));
    assertEquals("wiki", reference.extractReference(EntityType.WIKI).getName());
    assertEquals("spa^ce", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("ClassProp", reference.extractReference(EntityType.CLASS_PROPERTY).getName());
    reference = new ClassPropertyReference(resolver.resolve(":.\\^@", EntityType.CLASS_PROPERTY));
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals(DEFAULT_PAGE, reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals(":.^@", reference.extractReference(EntityType.CLASS_PROPERTY).getName());
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 49 with EntityReference

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

the class DefaultStringEntityReferenceResolverTest method testResolveDocumentReferenceWithExplicitReference.

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

Example 50 with EntityReference

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

the class DefaultStringEntityReferenceResolverTest method testResolveObjectReference.

/**
 * Tests resolving object references.
 */
@Test
public void testResolveObjectReference() {
    EntityReference reference = resolver.resolve("wiki:space.page^Object", EntityType.OBJECT);
    assertEquals("wiki", reference.extractReference(EntityType.WIKI).getName());
    assertEquals("space", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("Object", reference.getName());
    // default values
    reference = resolver.resolve("", EntityType.OBJECT);
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals(DEFAULT_PAGE, reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals(DEFAULT_OBJECT, reference.getName());
    // without some of the parents
    reference = resolver.resolve("space.page^Object", EntityType.OBJECT);
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals("space", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("Object", reference.getName());
    reference = resolver.resolve("page^Object", EntityType.OBJECT);
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("Object", reference.getName());
    reference = resolver.resolve("XWiki.Class", EntityType.OBJECT);
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals(DEFAULT_PAGE, reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("XWiki.Class", reference.getName());
    // property without object
    reference = resolver.resolve("wiki:space.page.property", EntityType.OBJECT);
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals(DEFAULT_PAGE, reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("wiki:space.page.property", reference.getName());
    // object with no name
    reference = resolver.resolve("wiki:space.page^", EntityType.OBJECT);
    assertEquals("wiki", reference.extractReference(EntityType.WIKI).getName());
    assertEquals("space", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals(DEFAULT_OBJECT, reference.getName());
    // test separator escape
    reference = resolver.resolve("wiki:space.page^obje\\^ct", EntityType.OBJECT);
    assertEquals("wiki", reference.extractReference(EntityType.WIKI).getName());
    assertEquals("space", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("obje^ct", reference.getName());
    // and that separators don't need to be escaped other than in the object name
    reference = resolver.resolve("wiki:spa^ce.page^Object", EntityType.OBJECT);
    assertEquals("wiki", reference.extractReference(EntityType.WIKI).getName());
    assertEquals("spa^ce", reference.extractReference(EntityType.SPACE).getName());
    assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals("Object", reference.getName());
    reference = resolver.resolve(":.\\^@", EntityType.OBJECT);
    assertEquals(DEFAULT_WIKI, reference.extractReference(EntityType.WIKI).getName());
    assertEquals(DEFAULT_SPACE, reference.extractReference(EntityType.SPACE).getName());
    assertEquals(DEFAULT_PAGE, reference.extractReference(EntityType.DOCUMENT).getName());
    assertEquals(":.^@", reference.getName());
}
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