Search in sources :

Example 6 with DbResults

use of com.zimbra.cs.db.DbResults in project zm-mailbox by Zimbra.

the class FolderTest method emptyFolderNonrecursive.

/**
     * Confirms that emptying a folder removes subfolders only when requested.
     */
@Test
public void emptyFolderNonrecursive() 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(), false);
    // 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
    mbox.getFolderById(null, childId);
    // 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 no data.  id=" + childId, 1, results.size());
}
Also used : DbResults(com.zimbra.cs.db.DbResults) Test(org.junit.Test)

Example 7 with DbResults

use of com.zimbra.cs.db.DbResults in project zm-mailbox by Zimbra.

the class FolderTest method deleteParent.

/**
     * Confirms that deleting a parent folder also deletes the child.
     */
@Test
public void deleteParent() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Folder parent = mbox.createFolder(null, "/" + "deleteParent - parent", new Folder.FolderOptions());
    int parentId = parent.getId();
    Folder child = mbox.createFolder(null, "deleteParent - child", parent.getId(), new Folder.FolderOptions());
    int childId = child.getId();
    mbox.delete(null, parent.getId(), parent.getType());
    // Look up parent by id
    try {
        mbox.getFolderById(null, parentId);
        Assert.fail("Parent folder lookup by id should have not succeeded");
    } catch (NoSuchItemException e) {
    }
    // 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 data.  id=" + parentId, 0, 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());
}
Also used : DbResults(com.zimbra.cs.db.DbResults) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test)

Example 8 with DbResults

use of com.zimbra.cs.db.DbResults in project zm-mailbox by Zimbra.

the class ContactTest method locator.

/**
     * Confirms that locator is not set for contacts.
     */
@Test
public void locator() throws Exception {
    // Create contact.
    Map<String, String> attrs = Maps.newHashMap();
    attrs.put(ContactConstants.A_fullName, "Volume Id");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    mbox.createContact(null, new ParsedContact(attrs), Mailbox.ID_FOLDER_CONTACTS, null);
    // Check volume id in database.
    String sql = String.format("SELECT COUNT(*) FROM %s WHERE type = %d AND blob_digest IS NULL AND locator IS NOT NULL", DbMailItem.getMailItemTableName(mbox), MailItem.Type.CONTACT.toByte());
    DbResults results = DbUtil.executeQuery(sql);
    Assert.assertEquals("Found non-null locator values for contacts", 0, results.getInt(1));
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) DbResults(com.zimbra.cs.db.DbResults) Test(org.junit.Test)

Example 9 with DbResults

use of com.zimbra.cs.db.DbResults in project zm-mailbox by Zimbra.

the class TestUnread method verifyAllUnreadFlags.

private void verifyAllUnreadFlags() throws Exception {
    verifyUnreadFlag(getMessage1());
    verifyUnreadFlag(getMessage2());
    verifyUnreadFlag(getMessage3());
    verifyUnreadFlag(getConv());
    verifyUnreadFlag(getFolder1());
    verifyUnreadFlag(getFolder2());
    verifyUnreadFlag(getTag1());
    verifyUnreadFlag(getTag2());
    // Make sure we aren't still setting the old unread flag
    DbResults results = DbUtil.executeQuery("SELECT COUNT(*) " + "FROM " + DbMailItem.getMailItemTableName(mMbox) + " WHERE mailbox_id = " + mMbox.getId() + " AND flags & " + Flag.BITMASK_UNREAD + " > 0");
    int numRows = results.getInt(1);
    Assert.assertEquals("Found " + numRows + " items with old unread flag set", 0, numRows);
}
Also used : DbResults(com.zimbra.cs.db.DbResults)

Aggregations

DbResults (com.zimbra.cs.db.DbResults)9 Test (org.junit.Test)5 Account (com.zimbra.cs.account.Account)2 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 LmcSession (com.zimbra.cs.client.LmcSession)1 LmcDeleteAccountRequest (com.zimbra.cs.client.soap.LmcDeleteAccountRequest)1 DbMailItem (com.zimbra.cs.db.DbMailItem)1 DbMailbox (com.zimbra.cs.db.DbMailbox)1 Folder (com.zimbra.cs.mailbox.Folder)1 MailItem (com.zimbra.cs.mailbox.MailItem)1 ParsedContact (com.zimbra.cs.mime.ParsedContact)1 File (java.io.File)1