use of com.xpn.xwiki.doc.XWikiDeletedDocument 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));
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class UndeleteActionTest method showBatch.
/**
* Show the "restore" UI with the option to include the batch when restoring and to see the contents of the batch of
* the current deleted document.
*/
@Test
public void showBatch() throws Exception {
long id = 13;
when(request.getParameter("id")).thenReturn(String.valueOf(id));
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getLocale()).thenReturn(Locale.ROOT);
when(deletedDocument.getId()).thenReturn(id);
when(xwiki.getDeletedDocument(anyLong(), any(XWikiContext.class))).thenReturn(deletedDocument);
when(request.getParameter("showBatch")).thenReturn("true");
when(rightsService.hasAccessLevel(any(), any(), any(), any())).thenReturn(true);
assertTrue(undeleteAction.action(context));
// Render the "restore" template.
assertEquals("restore", undeleteAction.render(context));
// Just make sure that we stop to the display, since the "confirm=true" parameter was not passed.
verify(refactoringScriptService, never()).createRestoreRequest(Arrays.asList(id));
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class UndeleteActionTest method restoreBatch.
/**
* Launches a RestoreJob with the batchId of the current deleted document.
*/
@Test
public void restoreBatch() throws Exception {
CSRFToken csrfToken = mocker.getInstance(CSRFToken.class);
when(csrfToken.isTokenValid(null)).thenReturn(true);
long id = 13;
String batchId = "abc123";
when(request.getParameter("id")).thenReturn(String.valueOf(id));
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getLocale()).thenReturn(Locale.ROOT);
when(deletedDocument.getId()).thenReturn(id);
when(deletedDocument.getBatchId()).thenReturn(batchId);
when(xwiki.getDeletedDocument(anyLong(), any(XWikiContext.class))).thenReturn(deletedDocument);
// Go through the screen showing the option to include the batch and displaying its contents.
when(request.getParameter("showBatch")).thenReturn("true");
// Option to include the entire batch when restoring is enabled.
when(request.getParameter("includeBatch")).thenReturn("true");
// Confirmation button pressed.
when(request.getParameter("confirm")).thenReturn("true");
when(rightsService.hasAccessLevel(any(), any(), any(), any())).thenReturn(true);
assertFalse(undeleteAction.action(context));
verify(refactoringScriptService).createRestoreRequest(batchId);
verify(jobExecutor).execute(RefactoringJobs.RESTORE, jobRequest);
verify(job).join();
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class UndeleteActionTest method notAllowedToRestoreSinglePage.
/**
* When trying to restore, rights are checked on the current deleted document, regardless if single or batch
* restore.
*/
@Test
public void notAllowedToRestoreSinglePage() throws Exception {
CSRFToken csrfToken = mocker.getInstance(CSRFToken.class);
when(csrfToken.isTokenValid(null)).thenReturn(true);
long id = 13;
when(request.getParameter("id")).thenReturn(String.valueOf(id));
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getLocale()).thenReturn(Locale.ROOT);
when(deletedDocument.getId()).thenReturn(id);
when(xwiki.getDeletedDocument(anyLong(), any(XWikiContext.class))).thenReturn(deletedDocument);
when(rightsService.hasAccessLevel(any(), any(), any(), any())).thenReturn(false);
assertTrue(undeleteAction.action(context));
// Render the "accessdenied" template.
assertEquals("accessdenied", undeleteAction.render(context));
// Just make sure we don`t go any further.
verify(refactoringScriptService, never()).createRestoreRequest(Arrays.asList(id));
}
Aggregations