@Test public void getDefaultReferenceWithContextDocument() throws IllegalAccessException { this.mockitoOldcore.getXWikiContext().setWikiId(CONTEXT_WIKI); XWikiDocument document = new XWikiDocument(new DocumentReference("docwiki", Arrays.asList("docspace1", "docspace2"), "docname")); FieldUtils.writeDeclaredField(document, "pageReferenceCache", new PageReference("docwiki", "docspace1", "docspace2", "docname"), true); this.mockitoOldcore.getXWikiContext().setDoc(document); assertEquals(new EntityReference(CONTEXT_WIKI, EntityType.WIKI), this.provider.getDefaultReference(EntityType.WIKI)); assertEquals( new EntityReference("docspace2", EntityType.SPACE, new EntityReference("docspace1", EntityType.SPACE)), this.provider.getDefaultReference(EntityType.SPACE)); assertEquals(new EntityReference("docname", EntityType.DOCUMENT), this.provider.getDefaultReference(EntityType.DOCUMENT)); assertEquals( new EntityReference("docname", EntityType.PAGE, new EntityReference("docspace2", EntityType.PAGE, new EntityReference("docspace1", EntityType.PAGE))), this.provider.getDefaultReference(EntityType.PAGE)); assertEquals(DEFAULT_ATTACHMENT_REFERENCE, this.provider.getDefaultReference(EntityType.ATTACHMENT)); assertEquals(DEFAULT_OBJECT_REFERENCE, this.provider.getDefaultReference(EntityType.OBJECT)); assertEquals(DEFAULT_OBJECT_PROPERTY_REFERENCE, this.provider.getDefaultReference(EntityType.OBJECT_PROPERTY)); assertEquals(DEFAULT_CLASS_PROPERTY_REFERENCE, this.provider.getDefaultReference(EntityType.CLASS_PROPERTY)); assertEquals(DEFAULT_PAGE_ATTACHMENT_REFERENCE, this.provider.getDefaultReference(EntityType.PAGE_ATTACHMENT)); assertEquals(DEFAULT_PAGE_OBJECT_REFERENCE, this.provider.getDefaultReference(EntityType.PAGE_OBJECT)); assertEquals(DEFAULT_PAGE_OBJECT_PROPERTY_REFERENCE, this.provider.getDefaultReference(EntityType.PAGE_OBJECT_PROPERTY)); assertEquals(DEFAULT_PAGE_CLASS_PROPERTY_REFERENCE, this.provider.getDefaultReference(EntityType.PAGE_CLASS_PROPERTY)); }
@Override public EntityReference getDefaultReference(EntityType type) { EntityReference result = null; XWikiContext xcontext = this.xcontextProvider.get(); if (xcontext != null) { if (type == EntityType.WIKI) { result = xcontext.getWikiReference(); } else if (type == EntityType.SPACE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { SpaceReference spaceReference = currentDoc.getDocumentReference().getLastSpaceReference(); result = spaceReference.removeParent(spaceReference.getWikiReference()); } } else if (type == EntityType.DOCUMENT) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { DocumentReference documentReference = currentDoc.getDocumentReference(); result = documentReference.removeParent(documentReference.getLastSpaceReference()); } } else if (type == EntityType.PAGE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { PageReference pageReference = currentDoc.getPageReference(); result = pageReference.removeParent(pageReference.getWikiReference()); } } } if (result == null) { result = super.getDefaultReference(type); } return result; }
CurrentEntityReferenceProvider extends DefaultEntityReferenceProvider { @Override public EntityReference getDefaultReference(EntityType type) { EntityReference result = null; XWikiContext xcontext = this.xcontextProvider.get(); if (xcontext != null) { if (type == EntityType.WIKI) { result = xcontext.getWikiReference(); } else if (type == EntityType.SPACE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { SpaceReference spaceReference = currentDoc.getDocumentReference().getLastSpaceReference(); result = spaceReference.removeParent(spaceReference.getWikiReference()); } } else if (type == EntityType.DOCUMENT) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { DocumentReference documentReference = currentDoc.getDocumentReference(); result = documentReference.removeParent(documentReference.getLastSpaceReference()); } } else if (type == EntityType.PAGE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { PageReference pageReference = currentDoc.getPageReference(); result = pageReference.removeParent(pageReference.getWikiReference()); } } } if (result == null) { result = super.getDefaultReference(type); } return result; } }
CurrentEntityReferenceProvider extends DefaultEntityReferenceProvider { @Override public EntityReference getDefaultReference(EntityType type) { EntityReference result = null; XWikiContext xcontext = this.xcontextProvider.get(); if (xcontext != null) { if (type == EntityType.WIKI) { result = xcontext.getWikiReference(); } else if (type == EntityType.SPACE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { SpaceReference spaceReference = currentDoc.getDocumentReference().getLastSpaceReference(); result = spaceReference.removeParent(spaceReference.getWikiReference()); } } else if (type == EntityType.DOCUMENT) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { DocumentReference documentReference = currentDoc.getDocumentReference(); result = documentReference.removeParent(documentReference.getLastSpaceReference()); } } else if (type == EntityType.PAGE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { PageReference pageReference = currentDoc.getPageReference(); result = pageReference.removeParent(pageReference.getWikiReference()); } } } if (result == null) { result = super.getDefaultReference(type); } return result; }  }
CurrentEntityReferenceProvider extends DefaultEntityReferenceProvider { @Override public EntityReference getDefaultReference(EntityType type) { EntityReference result = null; XWikiContext xcontext = this.xcontextProvider.get(); if (xcontext != null) { if (type == EntityType.WIKI) { result = xcontext.getWikiReference(); } else if (type == EntityType.SPACE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { SpaceReference spaceReference = currentDoc.getDocumentReference().getLastSpaceReference(); result = spaceReference.removeParent(spaceReference.getWikiReference()); } } else if (type == EntityType.DOCUMENT) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { DocumentReference documentReference = currentDoc.getDocumentReference(); result = documentReference.removeParent(documentReference.getLastSpaceReference()); } } else if (type == EntityType.PAGE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { PageReference pageReference = currentDoc.getPageReference(); result = pageReference.removeParent(pageReference.getWikiReference()); } } } if (result == null) { result = super.getDefaultReference(type); } return result; }  @Override EntityReference getDefaultReference(EntityType type); }
CurrentEntityReferenceProvider extends DefaultEntityReferenceProvider { @Override public EntityReference getDefaultReference(EntityType type) { EntityReference result = null; XWikiContext xcontext = this.xcontextProvider.get(); if (xcontext != null) { if (type == EntityType.WIKI) { result = xcontext.getWikiReference(); } else if (type == EntityType.SPACE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { SpaceReference spaceReference = currentDoc.getDocumentReference().getLastSpaceReference(); result = spaceReference.removeParent(spaceReference.getWikiReference()); } } else if (type == EntityType.DOCUMENT) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { DocumentReference documentReference = currentDoc.getDocumentReference(); result = documentReference.removeParent(documentReference.getLastSpaceReference()); } } else if (type == EntityType.PAGE) { XWikiDocument currentDoc = xcontext.getDoc(); if (currentDoc != null) { PageReference pageReference = currentDoc.getPageReference(); result = pageReference.removeParent(pageReference.getWikiReference()); } } } if (result == null) { result = super.getDefaultReference(type); } return result; }  @Override EntityReference getDefaultReference(EntityType type);  }