use of com.xpn.xwiki.store.XWikiRecycleBinStoreInterface in project xwiki-platform by xwiki.
the class DocumentEventConverter method unserializeDeletdDocument.
private XWikiDocument unserializeDeletdDocument(Serializable remoteData, XWikiContext xcontext) throws XWikiException {
Map<String, Serializable> remoteDataMap = (Map<String, Serializable>) remoteData;
DocumentReference docReference = (DocumentReference) remoteDataMap.get(DOC_NAME);
XWikiDocument doc = new XWikiDocument(docReference);
XWikiDocument origDoc = new XWikiDocument(docReference);
// We have to get deleted document from the trash (hoping it is in the trash...)
XWiki xwiki = xcontext.getWiki();
XWikiRecycleBinStoreInterface store = xwiki.getRecycleBinStore();
XWikiDeletedDocument[] deletedDocuments = store.getAllDeletedDocuments(origDoc, xcontext, true);
if (deletedDocuments != null && deletedDocuments.length > 0) {
long index = deletedDocuments[0].getId();
origDoc = store.restoreFromRecycleBin(index, xcontext, true);
}
doc.setOriginalDocument(origDoc);
return doc;
}
use of com.xpn.xwiki.store.XWikiRecycleBinStoreInterface in project xwiki-platform by xwiki.
the class XWikiMockitoTest method deleteAllDocumentsAndWithoutSendingToTrash.
@Test
public void deleteAllDocumentsAndWithoutSendingToTrash() throws Exception {
XWiki xwiki = new XWiki();
XWikiDocument document = mock(XWikiDocument.class);
DocumentReference reference = new DocumentReference("wiki", "space", "page");
when(document.getDocumentReference()).thenReturn(reference);
// Make sure we have a trash for the test.
XWikiRecycleBinStoreInterface recycleBinStoreInterface = mock(XWikiRecycleBinStoreInterface.class);
xwiki.setRecycleBinStore(recycleBinStoreInterface);
when(xwikiCfgConfigurationSource.getProperty("xwiki.recyclebin", "1")).thenReturn("1");
// Configure the mocked Store to later verify if it's called
XWikiStoreInterface storeInterface = mock(XWikiStoreInterface.class);
xwiki.setStore(storeInterface);
XWikiContext xwikiContext = mock(XWikiContext.class);
xwiki.deleteAllDocuments(document, false, xwikiContext);
// Verify that saveToRecycleBin is never called since otherwise it would mean the doc has been saved in the
// trash
verify(recycleBinStoreInterface, never()).saveToRecycleBin(any(XWikiDocument.class), any(String.class), any(Date.class), any(XWikiContext.class), any(Boolean.class));
// Verify that deleteXWikiDoc() is called
verify(storeInterface).deleteXWikiDoc(document, xwikiContext);
}
use of com.xpn.xwiki.store.XWikiRecycleBinStoreInterface in project xwiki-platform by xwiki.
the class DefaultModelBridgeTest method canRestoreDeletedDocument.
@Test
public void canRestoreDeletedDocument() throws Exception {
long deletedDocumentId = 42;
String deletedDocumentFullName = "Space.DeletedDocument";
DocumentReference userReferenceToCheck = new DocumentReference("wiki", "Space", "User");
DocumentReference currentUserReference = new DocumentReference("wiki", "Space", "CurrentUser");
when(xcontext.getUserReference()).thenReturn(currentUserReference);
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getFullName()).thenReturn(deletedDocumentFullName);
XWikiRecycleBinStoreInterface recycleBin = mock(XWikiRecycleBinStoreInterface.class);
when(recycleBin.getDeletedDocument(deletedDocumentId, xcontext, true)).thenReturn(deletedDocument);
when(xwiki.getRecycleBinStore()).thenReturn(recycleBin);
XWikiRightService rightService = mock(XWikiRightService.class);
when(xwiki.getRightService()).thenReturn(rightService);
when(rightService.hasAccessLevel(any(), any(), any(), any())).thenReturn(true);
assertTrue(mocker.getComponentUnderTest().canRestoreDeletedDocument(deletedDocumentId, userReferenceToCheck));
// Verify that the rights were checked with the specified user as context user.
verify(xcontext).setUserReference(userReferenceToCheck);
// Verify that the context user was restored. Note: We don`t know the order here, but maybe we don`t care that
// much.
verify(xcontext).setUserReference(currentUserReference);
}
use of com.xpn.xwiki.store.XWikiRecycleBinStoreInterface in project xwiki-platform by xwiki.
the class DefaultModelBridgeTest method restoreDeletedDocumentNoRights.
@Test
public void restoreDeletedDocumentNoRights() throws Exception {
long deletedDocumentId = 42;
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
String deletedDocumentFullName = "space.page";
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getDocumentReference()).thenReturn(documentReference);
when(deletedDocument.getId()).thenReturn(deletedDocumentId);
when(deletedDocument.getFullName()).thenReturn(deletedDocumentFullName);
when(xwiki.getDeletedDocument(deletedDocumentId, xcontext)).thenReturn(deletedDocument);
when(xwiki.exists(documentReference, xcontext)).thenReturn(false);
XWikiRecycleBinStoreInterface recycleBin = mock(XWikiRecycleBinStoreInterface.class);
when(recycleBin.getDeletedDocument(deletedDocumentId, xcontext, true)).thenReturn(deletedDocument);
when(xwiki.getRecycleBinStore()).thenReturn(recycleBin);
// No rights.
XWikiRightService rightService = mock(XWikiRightService.class);
when(xwiki.getRightService()).thenReturn(rightService);
when(rightService.hasAccessLevel(any(), any(), any(), any())).thenReturn(false);
assertFalse(mocker.getComponentUnderTest().restoreDeletedDocument(deletedDocumentId, true));
verify(mocker.getMockedLogger()).error("You are not allowed to restore document [{}] with ID [{}]", documentReference, deletedDocumentId);
verify(xwiki, never()).restoreFromRecycleBin(any(), any(), any());
}
use of com.xpn.xwiki.store.XWikiRecycleBinStoreInterface in project xwiki-platform by xwiki.
the class DefaultModelBridgeTest method getDeletedDocumentIds.
@Test
public void getDeletedDocumentIds() throws Exception {
String batchId = "abc123";
long id1 = 1;
long id2 = 2;
XWikiDeletedDocument deletedDocument1 = mock(XWikiDeletedDocument.class);
when(deletedDocument1.getId()).thenReturn(id1);
XWikiDeletedDocument deletedDocument2 = mock(XWikiDeletedDocument.class);
when(deletedDocument2.getId()).thenReturn(id2);
XWikiDeletedDocument[] deletedDocuments = { deletedDocument1, deletedDocument2 };
XWikiRecycleBinStoreInterface recycleBin = mock(XWikiRecycleBinStoreInterface.class);
when(recycleBin.getAllDeletedDocuments(batchId, false, xcontext, true)).thenReturn(deletedDocuments);
when(xwiki.getRecycleBinStore()).thenReturn(recycleBin);
List<Long> result = mocker.getComponentUnderTest().getDeletedDocumentIds(batchId);
assertNotNull(result);
assertEquals(deletedDocuments.length, result.size());
assertThat(result, containsInAnyOrder(id1, id2));
}
Aggregations