Search in sources :

Example 21 with DocumentReference

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

the class DefaultModelBridgeTest method testAuthorReference.

@Test
public void testAuthorReference() throws Exception {
    XWikiContext context = mock(XWikiContext.class);
    XWiki xwiki = mock(XWiki.class);
    XWikiDocument document = mock(XWikiDocument.class);
    DocumentReference authorReference = mock(DocumentReference.class);
    EntityReference entityReference = mock(EntityReference.class);
    when(this.contextProvider.get()).thenReturn(context);
    when(context.getWiki()).thenReturn(xwiki);
    when(xwiki.getDocument(entityReference, context)).thenReturn(document);
    when(document.getAuthorReference()).thenReturn(authorReference);
    DocumentReference result = this.mocker.getComponentUnderTest().getAuthorReference(entityReference);
    assertEquals(authorReference, result);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test)

Example 22 with DocumentReference

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

the class DefaultModelBridgeTest method testCheckXObjectPresenceWithPresentXObject.

@Test
public void testCheckXObjectPresenceWithPresentXObject() throws Exception {
    XWikiDocument document = mock(XWikiDocument.class);
    List<String> xObjectTypes = Arrays.asList("type1");
    DocumentReference documentReferenceFromDocumentXObjects = mock(DocumentReference.class);
    Map<DocumentReference, List<BaseObject>> documentXObjects = new HashMap<DocumentReference, List<BaseObject>>() {

        {
            put(documentReferenceFromDocumentXObjects, Collections.EMPTY_LIST);
        }
    };
    DocumentReference resolvedType1 = mock(DocumentReference.class);
    LocalDocumentReference localDocumentReferenceType1 = mock(LocalDocumentReference.class);
    when(resolvedType1.getLocalDocumentReference()).thenReturn(localDocumentReferenceType1);
    when(this.documentReferenceResolver.resolve(eq("type1"))).thenReturn(resolvedType1);
    when(document.getXObjects()).thenReturn(documentXObjects);
    when(documentReferenceFromDocumentXObjects.getLocalDocumentReference()).thenReturn(localDocumentReferenceType1);
    assertTrue(this.mocker.getComponentUnderTest().checkXObjectPresence(xObjectTypes, document));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) HashMap(java.util.HashMap) List(java.util.List) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 23 with DocumentReference

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

the class UntypedRecordableEventDescriptorComponentBuilderTest method testBuildComponent.

@Test
public void testBuildComponent() throws Exception {
    BaseObject baseObject = mock(BaseObject.class);
    XWikiDocument parentDocument = mock(XWikiDocument.class);
    DocumentReference documentReference = mock(DocumentReference.class);
    when(baseObject.getOwnerDocument()).thenReturn(parentDocument);
    when(parentDocument.getDocumentReference()).thenReturn(documentReference);
    // Ensure that the user rights are correctly checked
    when(this.authorizationManager.hasAccess(any(), any(), any())).thenReturn(true);
    List<WikiComponent> result = this.mocker.getComponentUnderTest().buildComponents(baseObject);
    assertEquals(1, result.size());
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiComponent(org.xwiki.component.wiki.WikiComponent) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 24 with DocumentReference

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

the class DistributionInternalScriptService method getModifiedDocumentsTree.

/**
 * @return the document modified during the Distribution Wizard execution
 * @since 5.4RC1
 */
public Map<String, Map<String, Map<String, Map<String, DocumentStatus>>>> getModifiedDocumentsTree() {
    Map<DocumentReference, DocumentStatus> documents = ((DocumentsModifiedDuringDistributionListener) this.modifiedDocumentsListener).getDocuments().get(this.xcontextProvider.get().getWikiId());
    Map<String, Map<String, Map<String, Map<String, DocumentStatus>>>> tree = new TreeMap<>();
    if (documents != null) {
        for (Map.Entry<DocumentReference, DocumentStatus> document : documents.entrySet()) {
            DocumentReference reference = document.getKey();
            String wiki = reference.getWikiReference().getName();
            // TODO: add support for subspaces
            String space = reference.getLastSpaceReference().getName();
            String page = reference.getName();
            String locale = reference.getLocale() != null ? reference.getLocale().toString() : "";
            Map<String, Map<String, Map<String, DocumentStatus>>> spaces = tree.get(wiki);
            if (spaces == null) {
                spaces = new TreeMap<>();
                tree.put(wiki, spaces);
            }
            Map<String, Map<String, DocumentStatus>> pages = spaces.get(space);
            if (pages == null) {
                pages = new TreeMap<>();
                spaces.put(space, pages);
            }
            Map<String, DocumentStatus> locales = pages.get(page);
            if (locales == null) {
                locales = new TreeMap<>();
                pages.put(page, locales);
            }
            locales.put(locale, document.getValue());
        }
    }
    return tree;
}
Also used : DocumentStatus(org.xwiki.extension.distribution.internal.DocumentsModifiedDuringDistributionListener.DocumentStatus) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 25 with DocumentReference

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

the class DocumentsModifiedDuringDistributionListener method addDocument.

private void addDocument(String distributionWiki, XWikiDocument document, Action action, LocalExtension previousExtension, LocalExtension nextExtension) {
    Map<DocumentReference, DocumentStatus> wikiDocuments = this.documents.get(distributionWiki);
    if (wikiDocuments == null) {
        wikiDocuments = new HashMap<DocumentReference, DocumentsModifiedDuringDistributionListener.DocumentStatus>();
        this.documents.put(distributionWiki, wikiDocuments);
    }
    DocumentReference reference = document.getDocumentReferenceWithLocale();
    DocumentStatus currentStatus = wikiDocuments.get(reference);
    String previousVersion;
    if (currentStatus != null) {
        previousVersion = currentStatus.getPreviousVersion();
        if (action == Action.CREATED) {
            if (previousVersion != null) {
                action = Action.MODIFIED;
            }
        } else if (action == Action.DELETED) {
            if (previousVersion == null) {
                // Back to square one
                wikiDocuments.remove(reference);
                return;
            }
        } else if (action == Action.MODIFIED) {
            action = currentStatus.getAction();
        }
    } else {
        if (action != Action.CREATED) {
            previousVersion = document.getOriginalDocument().getVersion();
        } else {
            previousVersion = null;
        }
    }
    wikiDocuments.put(reference, new DocumentStatus(reference, previousVersion, action, previousExtension, nextExtension));
}
Also used : DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

DocumentReference (org.xwiki.model.reference.DocumentReference)1324 Test (org.junit.Test)711 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)482 BaseObject (com.xpn.xwiki.objects.BaseObject)250 XWikiContext (com.xpn.xwiki.XWikiContext)186 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)157 ArrayList (java.util.ArrayList)128 WikiReference (org.xwiki.model.reference.WikiReference)127 XWikiException (com.xpn.xwiki.XWikiException)121 EntityReference (org.xwiki.model.reference.EntityReference)113 SpaceReference (org.xwiki.model.reference.SpaceReference)96 XWiki (com.xpn.xwiki.XWiki)82 HashMap (java.util.HashMap)54 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)52 Expectations (org.jmock.Expectations)50 Before (org.junit.Before)50 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)46 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)45 AttachmentReference (org.xwiki.model.reference.AttachmentReference)44 Date (java.util.Date)42