use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFilterExisting method testSimultaneous.
/**
* Simultaneously flags and discards the same set of messages (bug 41609).
*/
@Test
public void testSimultaneous() throws Exception {
// Add messages.
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
List<String> msgIds = new ArrayList<String>();
for (int i = 1; i <= 10; i++) {
msgIds.add(TestUtil.addMessage(mbox, NAME_PREFIX + " discard flag " + i));
}
String idList = StringUtil.join(",", msgIds);
// Start two threads that simultaneously process the same set of messages.
RunRule runDiscard = new RunRule(DISCARD_RULE_NAME, idList);
RunRule runFlag = new RunRule(FLAG_RULE_NAME, idList);
Thread discardThread = new Thread(runDiscard);
Thread flagThread = new Thread(runFlag);
discardThread.start();
flagThread.start();
discardThread.join();
flagThread.join();
// Make sure there were no errors.
Exception e = runDiscard.getError();
if (e != null) {
Assert.fail(e.toString());
}
e = runFlag.getError();
if (e != null) {
Assert.fail(e.toString());
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFilterExisting method testFileIntoSameFolderAndFlag.
/**
* Confirms that a flag rule runs when a message is filed into the same
* folder (bug 44588).
*/
@Test
public void testFileIntoSameFolderAndFlag() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFolder folder1 = TestUtil.createFolder(mbox, FOLDER1_PATH);
String subject = NAME_PREFIX + " test folder1 and flag";
String id = TestUtil.addMessage(mbox, subject, folder1.getId(), null);
ZMessage msg = mbox.getMessageById(id);
Assert.assertTrue(StringUtil.isNullOrEmpty(msg.getFlags()));
// Run the rule, make sure the message was flagged but not moved.
Set<String> affectedIds = runRules(new String[] { FOLDER1_AND_FLAG_RULE_NAME }, id, null);
Assert.assertEquals(1, affectedIds.size());
msg = TestUtil.getMessage(mbox, "subject:\"" + subject + "\"");
Assert.assertEquals("f", msg.getFlags());
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFilterExisting method testMarkRead.
@Test
public void testMarkRead() throws Exception {
// Add message
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String subject = NAME_PREFIX + " test mark read";
String id = TestUtil.addMessage(mbox, subject);
mbox.markMessageRead(id, false);
ZMessage msg = mbox.getMessageById(id);
Assert.assertTrue(msg.isUnread());
// Run mark unread rule and validate.
Set<String> affectedIds = runRules(new String[] { MARK_READ_RULE_NAME }, id, null);
Assert.assertEquals(1, affectedIds.size());
mbox.noOp();
Assert.assertFalse(msg.isUnread());
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFolderACLCache method setUp.
@Before
public void setUp() throws Exception {
testName = testInfo.getMethodName();
userNamePrefix = "testfolderaclcache-" + testName + "-user-";
ownerName = userNamePrefix + "owner";
user2Name = userNamePrefix + "haswriteaccess";
user3Name = userNamePrefix + "hasreadwriteaccess";
cleanUp();
ownerAcct = createAcct(ownerName);
USER2 = createAcct(user2Name);
USER3 = createAcct(user3Name);
ZMailbox ownerMbx = TestUtil.getZMailbox(ownerAcct.getName());
ZFolder inbox = ownerMbx.getFolderByPath("inbox");
String sub1Path = "/inbox/sub1";
ZFolder sub1 = ownerMbx.getFolderByPath(sub1Path);
if (sub1 == null) {
sub1 = TestUtil.createFolder(ownerMbx, sub1Path);
ownerMbx.modifyFolderGrant(sub1.getId(), ZGrant.GranteeType.usr, USER2.getName(), "w", null);
ownerMbx.modifyFolderGrant(sub1.getId(), ZGrant.GranteeType.usr, USER3.getName(), "rw", null);
}
String sub2Path = "/inbox/sub1/sub2";
ZFolder sub2 = ownerMbx.getFolderByPath(sub2Path);
if (sub2 == null)
sub2 = TestUtil.createFolder(ownerMbx, sub2Path);
String sub3Path = "/inbox/sub3";
ZFolder sub3 = ownerMbx.getFolderByPath(sub3Path);
if (sub3 == null) {
sub3 = TestUtil.createFolder(ownerMbx, sub3Path);
ownerMbx.modifyFolderGrant(sub3.getId(), ZGrant.GranteeType.pub, null, "r", null);
}
OWNER_ACCT_ID = ownerAcct.getId();
INBOX_FID = Integer.valueOf(inbox.getId());
SUB1_FID = Integer.valueOf(sub1.getId());
SUB2_FID = Integer.valueOf(sub2.getId());
SUB3_FID = Integer.valueOf(sub3.getId());
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFolders method testEmptyLargeFolder.
@Test
public void testEmptyLargeFolder() throws Exception {
TestUtil.setServerAttr(Provisioning.A_zimbraMailEmptyFolderBatchSize, Integer.toString(3));
// Create folders.
String parentPath = "/parent";
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFolder parent = TestUtil.createFolder(mbox, parentPath);
ZFolder child = TestUtil.createFolder(mbox, parent.getId(), "child");
// Add messages.
for (int i = 1; i <= 5; i++) {
TestUtil.addMessage(mbox, "parent " + i, parent.getId());
TestUtil.addMessage(mbox, "child " + i, child.getId());
}
mbox.noOp();
assertEquals(5, parent.getMessageCount());
assertEquals(5, child.getMessageCount());
// Empty parent folder without deleting subfolders.
mbox.emptyFolder(parent.getId(), false);
mbox.noOp();
assertEquals(0, parent.getMessageCount());
assertEquals(5, child.getMessageCount());
// Add more messages to the parent folder.
for (int i = 6; i <= 10; i++) {
TestUtil.addMessage(mbox, "parent " + i, parent.getId());
}
mbox.noOp();
assertEquals(5, parent.getMessageCount());
assertEquals(5, child.getMessageCount());
// Empty parent folder and delete subfolders.
String childPath = child.getPath();
assertNotNull(mbox.getFolderByPath(childPath));
mbox.emptyFolder(parent.getId(), true);
mbox.noOp();
assertEquals(0, parent.getMessageCount());
assertNull(mbox.getFolderByPath(childPath));
}
Aggregations