use of com.zimbra.cs.db.DbResults in project zm-mailbox by Zimbra.
the class FolderTest method testEmptyFolderRecursive.
/**
* Confirms that emptying a folder removes subfolders only when requested.
*/
@Test
public void testEmptyFolderRecursive() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Folder parent = mbox.createFolder(null, "/" + "parent", new Folder.FolderOptions());
int parentId = parent.getId();
Folder child = mbox.createFolder(null, "child", parent.getId(), new Folder.FolderOptions());
int childId = child.getId();
mbox.emptyFolder(null, parent.getId(), true);
// Look up parent by id
mbox.getFolderById(null, parentId);
// Look up parent by query
String sql = "SELECT id " + "FROM " + DbMailItem.getMailItemTableName(mbox) + " WHERE mailbox_id = " + mbox.getId() + " AND id = " + parentId;
DbResults results = DbUtil.executeQuery(sql);
Assert.assertEquals("Parent folder query returned no data. id=" + parentId, 1, results.size());
// Look up child by id
try {
mbox.getFolderById(null, childId);
Assert.fail("Child folder lookup by id should have not succeeded");
} catch (NoSuchItemException e) {
}
// Look up child by query
sql = "SELECT id " + "FROM " + DbMailItem.getMailItemTableName(mbox) + " WHERE mailbox_id = " + mbox.getId() + " AND id = " + childId;
results = DbUtil.executeQuery(sql);
Assert.assertEquals("Child folder query returned data. id=" + childId, 0, results.size());
}
use of com.zimbra.cs.db.DbResults in project zm-mailbox by Zimbra.
the class TestMailItem method testListItemIds.
@Test
public void testListItemIds() throws Exception {
Account account = TestUtil.createAccount(USER_NAME);
// Mailbox.ID_FOLDER_INBOX;
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
TestUtil.addMessage(mbox, testInfo.getMethodName() + "missive 1");
TestUtil.addMessage(mbox, testInfo.getMethodName() + "missive 2");
TestUtil.addMessage(mbox, testInfo.getMethodName() + "missive 3");
TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_DRAFTS, testInfo.getMethodName() + "draft 1", System.currentTimeMillis());
TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_DRAFTS, testInfo.getMethodName() + "draft 2", System.currentTimeMillis());
// Get item count per folder/type
String sql = "SELECT folder_id, type, count(*) AS item_count " + "FROM " + DbMailItem.getMailItemTableName(mbox) + " WHERE mailbox_id = " + mbox.getId() + " GROUP BY folder_id, type";
DbResults results = DbUtil.executeQuery(sql);
Assert.assertTrue("No results returned", results.size() > 0);
boolean foundInDrafts = false;
boolean foundInInbox = false;
// Confirm that listItemIds() returns the right count for each folder/type
while (results.next()) {
int folderId = results.getInt("folder_id");
MailItem.Type type = MailItem.Type.of((byte) results.getInt("type"));
// XXX bburtin: Work around incompatibility between JDBC driver version
// 5.0.3 and MySQL 5.0.67, where the column name returned for an alias
// is an empty string.
// int count = results.getInt("item_count");
int count = results.getInt(3);
ZimbraLog.test.debug("Confirming that folder '%s' has %s items of type %s", folderId, count, type);
Folder folder = mbox.getFolderById(null, folderId);
Assert.assertNotNull(String.format("Folder with ID='%s' not found", folderId), folder);
List<Integer> ids = mbox.listItemIds(null, type, folderId);
Assert.assertEquals(String.format("Item count does not match for Folder with ID='%s'", folderId), count, ids.size());
if (Mailbox.ID_FOLDER_INBOX == folderId) {
foundInInbox = true;
Assert.assertEquals("Item count does not match for INBOX", 3, count);
}
if (Mailbox.ID_FOLDER_DRAFTS == folderId) {
foundInDrafts = true;
Assert.assertEquals("Item count does not match for DRAFTS", 2, count);
}
}
Assert.assertTrue("No items reported for INBOX", foundInInbox);
Assert.assertTrue("No items reported for DRAFTS", foundInDrafts);
}
use of com.zimbra.cs.db.DbResults in project zm-mailbox by Zimbra.
the class TestUnread method verifyUnreadFlag.
private void verifyUnreadFlag(MailItem item) throws Exception {
String flagString = item.getFlagString();
if (item.isUnread()) {
Assert.assertTrue("unread bit test: " + item.getFlagBitmask(), (item.getFlagBitmask() & Flag.BITMASK_UNREAD) > 0);
Assert.assertTrue("unread flag string: " + flagString, flagString.indexOf(Flag.toChar(Flag.ID_UNREAD)) >= 0);
} else {
Assert.assertTrue("read bit test: " + item.getFlagBitmask(), (item.getFlagBitmask() & Flag.BITMASK_UNREAD) == 0);
Assert.assertTrue("read flag string: " + flagString, flagString.indexOf(Flag.toChar(Flag.ID_UNREAD)) == -1);
}
// if (item.getType() == MailItem.TYPE_MESSAGE || item.getType() == MailItem.TYPE_INVITE) {
if (item.getType() == MailItem.Type.MESSAGE) {
DbResults results = DbUtil.executeQuery("SELECT unread " + "FROM " + DbMailItem.getMailItemTableName(item) + " WHERE mailbox_id = " + item.getMailboxId() + " AND id = " + item.getId());
Assert.assertEquals("Verify unread flag in the database", item.isUnread(), results.getBoolean(1));
}
}
use of com.zimbra.cs.db.DbResults in project zm-mailbox by Zimbra.
the class TestScheduledTaskManager method checkNumPersistedTasks.
private void checkNumPersistedTasks(int expected) throws Exception {
DbResults results = DbUtil.executeQuery("SELECT COUNT(*) FROM " + DbScheduledTask.TABLE_SCHEDULED_TASK + " WHERE class_name = '" + TestTask.class.getName() + "'");
assertEquals("Unexpected number of persisted tasks", expected, results.getInt(1));
}
use of com.zimbra.cs.db.DbResults in project zm-mailbox by Zimbra.
the class TestAccount method testDeleteAccount.
public void testDeleteAccount() throws Exception {
ZimbraLog.test.debug("testDeleteAccount()");
// Get the account and mailbox
Account account = TestUtil.getAccount(USER_NAME);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
String dbName = DbMailbox.getDatabaseName(mbox);
ZimbraLog.test.debug("Account=" + account.getId() + ", mbox=" + mbox.getId());
// Confirm that the mailbox database exists
DbResults results = DbUtil.executeQuery("SELECT COUNT(*) FROM mailbox WHERE id = " + mbox.getId());
assertEquals("Could not find row in mailbox table", 1, results.getInt(1));
results = DbUtil.executeQuery("SHOW DATABASES LIKE '" + dbName + "'");
assertEquals("Could not find mailbox database", 1, results.size());
// Add a message to the account and confirm that the message directory exists
TestUtil.addMessage(mbox, "TestAccount testDeleteAccount");
String storePath = VolumeManager.getInstance().getCurrentMessageVolume().getMessageRootDir(mbox.getId());
File storeDir = new File(storePath);
if (TestUtil.checkLocalBlobs()) {
assertTrue(storePath + " does not exist", storeDir.exists());
assertTrue(storePath + " is not a directory", storeDir.isDirectory());
}
// Delete the account
LmcSession session = TestUtil.getAdminSoapSession();
LmcDeleteAccountRequest req = new LmcDeleteAccountRequest(account.getId());
req.setSession(session);
req.invoke(TestUtil.getAdminSoapUrl());
// Confirm that the mailbox was deleted
results = DbUtil.executeQuery("SELECT COUNT(*) FROM mailbox WHERE id = " + mbox.getId());
assertEquals("Unexpected row in mailbox table", 0, results.getInt(1));
if (TestUtil.checkLocalBlobs()) {
// Confirm that the message directory was deleted
assertFalse(storePath + " exists", storeDir.exists());
}
}
Aggregations