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