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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations