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);
}
}
Aggregations