Search in sources :

Example 21 with XWikiDeletedDocument

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));
}
Also used : XWikiRecycleBinStoreInterface(com.xpn.xwiki.store.XWikiRecycleBinStoreInterface) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 22 with XWikiDeletedDocument

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));
}
Also used : XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) XWikiContext(com.xpn.xwiki.XWikiContext) Test(org.junit.Test)

Example 23 with XWikiDeletedDocument

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();
}
Also used : CSRFToken(org.xwiki.csrf.CSRFToken) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) XWikiContext(com.xpn.xwiki.XWikiContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 24 with XWikiDeletedDocument

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));
}
Also used : CSRFToken(org.xwiki.csrf.CSRFToken) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) XWikiContext(com.xpn.xwiki.XWikiContext) Test(org.junit.Test)

Aggregations

XWikiDeletedDocument (com.xpn.xwiki.doc.XWikiDeletedDocument)24 Test (org.junit.Test)13 XWikiContext (com.xpn.xwiki.XWikiContext)10 DocumentReference (org.xwiki.model.reference.DocumentReference)8 XWiki (com.xpn.xwiki.XWiki)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 XWikiException (com.xpn.xwiki.XWikiException)5 CSRFToken (org.xwiki.csrf.CSRFToken)5 DeletedDocument (com.xpn.xwiki.api.DeletedDocument)4 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 XWikiRecycleBinStoreInterface (com.xpn.xwiki.store.XWikiRecycleBinStoreInterface)4 XWikiRightService (com.xpn.xwiki.user.api.XWikiRightService)2 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)2 XWikiDeletedDocumentContent (com.xpn.xwiki.doc.XWikiDeletedDocumentContent)1 XWikiHibernateDeletedDocumentContent (com.xpn.xwiki.internal.store.hibernate.XWikiHibernateDeletedDocumentContent)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Map (java.util.Map)1 HasToString (org.hamcrest.object.HasToString)1