Search in sources :

Example 1 with DocChangeRule

use of com.xpn.xwiki.notify.DocChangeRule in project xwiki-platform by xwiki.

the class XWikiNotificationTest method testSaveDocumentFromAPIUsesCorrectOriginalDocument.

/**
 * We only verify here that the saveDocument API calls the Notification Manager. Detailed tests of the notification
 * classes are implemented in the notification package.
 */
public void testSaveDocumentFromAPIUsesCorrectOriginalDocument() throws Exception {
    Mock mockRights = mock(XWikiRightService.class);
    mockRights.stubs().method("hasAccessLevel").will(returnValue(true));
    this.xwiki.setRightService((XWikiRightService) mockRights.proxy());
    TestListener listener = new TestListener();
    listener.expectedNewStatus = false;
    getNotificationManager().addGeneralRule(new DocChangeRule(listener));
    XWikiDocument original = new XWikiDocument(new DocumentReference("WikiDescriptor", "Space", "Page"));
    original.setNew(false);
    original.setContent("Old content");
    XWikiDocument document = new XWikiDocument(new DocumentReference("WikiDescriptor", "Space", "Page"));
    document.setContent("New content");
    document.setOriginalDocument(original);
    Document api = new Document(document, getContext());
    api.save();
    assertTrue("Listener not called", listener.hasListenerBeenCalled);
}
Also used : DocChangeRule(com.xpn.xwiki.notify.DocChangeRule) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Mock(org.jmock.Mock) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with DocChangeRule

use of com.xpn.xwiki.notify.DocChangeRule in project xwiki-platform by xwiki.

the class XWikiNotificationTest method testSaveDocumentSendNotifications.

/**
 * We only verify here that the saveDocument API calls the Notification Manager. Detailed tests of the notification
 * classes are implemented in the notification package.
 */
public void testSaveDocumentSendNotifications() throws Exception {
    TestListener listener = new TestListener();
    getNotificationManager().addGeneralRule(new DocChangeRule(listener));
    XWikiDocument document = new XWikiDocument(new DocumentReference("WikiDescriptor", "Space", "Page"));
    this.xwiki.saveDocument(document, getContext());
    assertTrue("Listener not called", listener.hasListenerBeenCalled);
}
Also used : DocChangeRule(com.xpn.xwiki.notify.DocChangeRule) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 DocChangeRule (com.xpn.xwiki.notify.DocChangeRule)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 Document (com.xpn.xwiki.api.Document)1 Mock (org.jmock.Mock)1