Search in sources :

Example 71 with EntityReference

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

the class EntityReferenceConverterTest method convertSpaceFromString.

@Test
public void convertSpaceFromString() {
    EntityReference reference;
    reference = new EntityReference("space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI));
    assertEquals(reference, this.converterManager.convert(EntityReference.class, "space:wiki:space"));
    reference = new EntityReference("space", EntityType.SPACE);
    assertEquals(reference, this.converterManager.convert(EntityReference.class, "space:space"));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 72 with EntityReference

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

the class ModelScriptServiceTest method createDocumentReferenceWhenWikiAndSpaceParametersEmpty.

@Test
public void createDocumentReferenceWhenWikiAndSpaceParametersEmpty() throws Exception {
    when(this.componentManager.getInstance(DocumentReferenceResolver.TYPE_REFERENCE, "default")).thenReturn(this.resolver);
    DocumentReference reference = new DocumentReference("wiki", "defaultspace", "defaultpage");
    when(this.resolver.resolve(new EntityReference("wiki", EntityType.WIKI))).thenReturn(reference);
    Assert.assertEquals(reference, this.service.createDocumentReference("wiki", "", "", "default"));
    Assert.assertEquals(reference, this.service.createDocumentReference("wiki", Collections.<String>emptyList(), "", "default"));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 73 with EntityReference

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

the class ModelScriptServiceTest method createDocumentReferenceWhenPageParameterEmpty.

@Test
public void createDocumentReferenceWhenPageParameterEmpty() throws Exception {
    when(this.componentManager.getInstance(DocumentReferenceResolver.TYPE_REFERENCE, "default")).thenReturn(this.resolver);
    DocumentReference reference = new DocumentReference("wiki", "space", "defaultpage");
    when(this.resolver.resolve(new EntityReference("space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI)))).thenReturn(reference);
    Assert.assertEquals(reference, this.service.createDocumentReference("wiki", "space", "", "default"));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 74 with EntityReference

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

the class ModelScriptService method createSpaceReference.

/**
 * Creates a {@link SpaceReference} from a list of string representing the space name and the name of its parents.
 *
 * @param spaces the list of the spaces name (eg ["A", "B", "C"])
 * @param parent the wiki reference in which the space is located
 * @return the reference to the space
 * @since 7.2M2
 */
public SpaceReference createSpaceReference(List<String> spaces, WikiReference parent) {
    SpaceReference spaceReference = null;
    EntityReference parentReference = parent;
    for (String space : spaces) {
        spaceReference = new SpaceReference(space, parentReference);
        parentReference = spaceReference;
    }
    return spaceReference;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference)

Example 75 with EntityReference

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

the class RegexEntityReferenceTest method testWithOnlyWiki.

@Test
public void testWithOnlyWiki() {
    EntityReference reference = new RegexEntityReference(Pattern.compile(REFERENCETOMATCH.getWikiReference().getName(), Pattern.LITERAL), EntityType.WIKI);
    Assert.assertTrue(reference.equals(REFERENCETOMATCH));
}
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