Search in sources :

Example 1 with MockListener

use of com.zimbra.cs.mailbox.MailboxTest.MockListener in project zm-mailbox by Zimbra.

the class TagTest method notifications.

@Test
public void notifications() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MockListener ml = new MockListener();
    MailboxListener.register(ml);
    try {
        // new implicit tags should not be included in notifications
        DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD).setTags(new String[] { tag2 });
        mbox.addMessage(null, ThreaderTest.getRootMessage(), dopt, null);
        for (MailItem item : ml.pms.created.values()) {
            Assert.assertFalse("implicit tags should not be notified", item instanceof Tag);
        }
        ml.clear();
        // new real tags *should* be included in notifications
        mbox.createTag(null, tag1, (byte) 0);
        Assert.assertFalse("explicit tag create must produce notifications", ml.pms.created.isEmpty());
        Assert.assertTrue("explicit tags must be notified", ml.pms.created.values().iterator().next() instanceof Tag);
        ml.clear();
        // changes to implicit tags should not be included in notifications
        int msgId = mbox.addMessage(null, ThreaderTest.getRootMessage(), dopt, null).getId();
        for (Change chg : ml.pms.modified.values()) {
            Assert.assertFalse("implicit tag changes should not be notified", chg.what instanceof Tag);
        }
        ml.clear();
        // changes to real tags *should* be included in notifications
        mbox.alterTag(null, msgId, MailItem.Type.MESSAGE, tag1, true, null);
        Assert.assertFalse("explicit tag apply must produce notifications", ml.pms.modified == null || ml.pms.modified.isEmpty());
        boolean found = false;
        for (Change chg : ml.pms.modified.values()) {
            found |= chg.what instanceof Tag;
        }
        Assert.assertTrue("explicit tag apply must be notified", found);
    } finally {
        MailboxListener.unregister(ml);
    }
}
Also used : DbTag(com.zimbra.cs.db.DbTag) Change(com.zimbra.cs.session.PendingModifications.Change) MockListener(com.zimbra.cs.mailbox.MailboxTest.MockListener) Test(org.junit.Test)

Aggregations

DbTag (com.zimbra.cs.db.DbTag)1 MockListener (com.zimbra.cs.mailbox.MailboxTest.MockListener)1 Change (com.zimbra.cs.session.PendingModifications.Change)1 Test (org.junit.Test)1