Search in sources :

Example 1 with AttachmentRecycleBinStore

use of com.xpn.xwiki.store.AttachmentRecycleBinStore in project xwiki-platform by xwiki.

the class XWikiMockitoTest method rollbackDoesNotSaveUnchangedAttachment.

/**
 * @see "XWIKI-9399: Attachment version is incremented when a document is rolled back even if the attachment did not
 *      change"
 */
@Test
public void rollbackDoesNotSaveUnchangedAttachment() throws Exception {
    String version = "1.1";
    String fileName = "logo.png";
    Date date = new Date();
    XWikiAttachment currentAttachment = mock(XWikiAttachment.class);
    when(currentAttachment.getAttachmentRevision(version, context)).thenReturn(currentAttachment);
    when(currentAttachment.getDate()).thenReturn(new Timestamp(date.getTime()));
    when(currentAttachment.getVersion()).thenReturn(version);
    when(currentAttachment.getFilename()).thenReturn(fileName);
    XWikiAttachment oldAttachment = mock(XWikiAttachment.class);
    when(oldAttachment.getFilename()).thenReturn(fileName);
    when(oldAttachment.getVersion()).thenReturn(version);
    when(oldAttachment.getDate()).thenReturn(date);
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    XWikiDocument document = mock(XWikiDocument.class);
    when(document.getDocumentReference()).thenReturn(documentReference);
    when(document.getAttachmentList()).thenReturn(Arrays.asList(currentAttachment));
    when(document.getAttachment(fileName)).thenReturn(currentAttachment);
    XWikiDocument result = mock(XWikiDocument.class);
    when(result.clone()).thenReturn(result);
    when(result.getDocumentReference()).thenReturn(documentReference);
    when(result.getAttachmentList()).thenReturn(Arrays.asList(oldAttachment));
    when(result.getAttachment(fileName)).thenReturn(oldAttachment);
    String revision = "3.5";
    when(this.documentRevisionProvider.getRevision(document, revision)).thenReturn(result);
    AttachmentRecycleBinStore attachmentRecycleBinStore = mock(AttachmentRecycleBinStore.class);
    xwiki.setAttachmentRecycleBinStore(attachmentRecycleBinStore);
    DocumentReference reference = document.getDocumentReference();
    this.mocker.registerMockComponent(ContextualLocalizationManager.class);
    when(xwiki.getStore().loadXWikiDoc(any(XWikiDocument.class), same(context))).thenReturn(new XWikiDocument(reference));
    xwiki.rollback(document, revision, context);
    verify(attachmentRecycleBinStore, never()).saveToRecycleBin(same(currentAttachment), any(String.class), any(Date.class), same(context), eq(true));
    verify(oldAttachment, never()).setMetaDataDirty(true);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Timestamp(java.sql.Timestamp) Date(java.util.Date) DocumentReference(org.xwiki.model.reference.DocumentReference) AttachmentRecycleBinStore(com.xpn.xwiki.store.AttachmentRecycleBinStore) Test(org.junit.Test)

Aggregations

XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 AttachmentRecycleBinStore (com.xpn.xwiki.store.AttachmentRecycleBinStore)1 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1