Search in sources :

Example 1 with JobProgressManager

use of org.xwiki.job.event.status.JobProgressManager in project xwiki-platform by xwiki.

the class DefaultModelBridgeTest method updateParentFieldsNoChildren.

@Test
public void updateParentFieldsNoChildren() throws Exception {
    DocumentReference oldParentReference = new DocumentReference("wiki", "Space", "Old");
    DocumentReference newParentReference = new DocumentReference("wiki", "Space", "New");
    XWikiDocument oldParentDocument = mock(XWikiDocument.class);
    when(this.xcontext.getWiki().getDocument(oldParentReference, this.xcontext)).thenReturn(oldParentDocument);
    when(oldParentDocument.getChildrenReferences(this.xcontext)).thenReturn(Collections.<DocumentReference>emptyList());
    JobProgressManager mockProgressManager = mocker.getInstance(JobProgressManager.class);
    this.mocker.getComponentUnderTest().updateParentField(oldParentReference, newParentReference);
    verify(mockProgressManager, never()).pushLevelProgress(anyInt(), any());
    verify(this.xcontext.getWiki(), never()).saveDocument(any(XWikiDocument.class), eq("Updated parent field."), eq(true), eq(this.xcontext));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) JobProgressManager(org.xwiki.job.event.status.JobProgressManager) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with JobProgressManager

use of org.xwiki.job.event.status.JobProgressManager in project xwiki-platform by xwiki.

the class DefaultModelBridgeTest method updateParentFields.

@Test
public void updateParentFields() throws Exception {
    DocumentReference oldParentReference = new DocumentReference("wiki", "Space", "Old");
    DocumentReference newParentReference = new DocumentReference("wiki", "Space", "New");
    XWikiDocument oldParentDocument = mock(XWikiDocument.class);
    when(this.xcontext.getWiki().getDocument(oldParentReference, this.xcontext)).thenReturn(oldParentDocument);
    DocumentReference child1Reference = new DocumentReference("wiki", "Space", "Child1");
    DocumentReference child2Reference = new DocumentReference("wiki", "Space", "Child2");
    when(oldParentDocument.getChildrenReferences(this.xcontext)).thenReturn(Arrays.asList(child1Reference, child2Reference));
    JobProgressManager mockProgressManager = mocker.getInstance(JobProgressManager.class);
    XWikiDocument child1Document = mock(XWikiDocument.class);
    when(this.xcontext.getWiki().getDocument(child1Reference, this.xcontext)).thenReturn(child1Document);
    XWikiDocument child2Document = mock(XWikiDocument.class);
    when(this.xcontext.getWiki().getDocument(child2Reference, this.xcontext)).thenReturn(child2Document);
    this.mocker.getComponentUnderTest().updateParentField(oldParentReference, newParentReference);
    verify(mockProgressManager).pushLevelProgress(2, this.mocker.getComponentUnderTest());
    verify(child1Document).setParentReference(newParentReference);
    verify(this.xcontext.getWiki()).saveDocument(child1Document, "Updated parent field.", true, this.xcontext);
    verify(child2Document).setParentReference(newParentReference);
    verify(this.xcontext.getWiki()).saveDocument(child1Document, "Updated parent field.", true, this.xcontext);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) JobProgressManager(org.xwiki.job.event.status.JobProgressManager) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 Test (org.junit.Test)2 JobProgressManager (org.xwiki.job.event.status.JobProgressManager)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2