Search in sources :

Example 11 with Mailbox

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

the class AbstractExternalStoreManagerTest method testUncachedSubstream.

@Test
public void testUncachedSubstream() throws Exception {
    ParsedMessage pm = ThreaderTest.getRootMessage();
    byte[] mimeBytes = TestUtil.readInputStream(pm.getRawInputStream());
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    StoreManager sm = StoreManager.getInstance();
    Blob blob = sm.storeIncoming(pm.getRawInputStream());
    StagedBlob staged = sm.stage(blob, mbox);
    MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
    mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
    Blob localBlob = mblob.getLocalBlob();
    InputStream stream = sm.getContent(localBlob);
    Assert.assertTrue("input stream external", stream instanceof BlobInputStream);
    if (sm instanceof ExternalStoreManager) {
        ((ExternalStoreManager) sm).clearCache();
    }
    blob.getFile().delete();
    Assert.assertFalse(blob.getFile().exists());
    //create new stream spanning the whole blob
    InputStream newStream = ((BlobInputStream) stream).newStream(0, -1);
    Assert.assertNotNull(newStream);
    Assert.assertTrue("stream content = mime content", TestUtil.bytesEqual(mimeBytes, newStream));
}
Also used : Blob(com.zimbra.cs.store.Blob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BlobInputStream(com.zimbra.cs.store.BlobInputStream) InputStream(java.io.InputStream) BlobInputStream(com.zimbra.cs.store.BlobInputStream) StoreManager(com.zimbra.cs.store.StoreManager) Test(org.junit.Test) AbstractStoreManagerTest(com.zimbra.cs.store.AbstractStoreManagerTest) ThreaderTest(com.zimbra.cs.mailbox.ThreaderTest)

Example 12 with Mailbox

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

the class TritonBlobStoreManagerTest method sisEmpty.

@Test
public void sisEmpty() throws Exception {
    TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
    Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
    byte[] bytes = new byte[0];
    Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
    //blob has not yet been finalized, so it shouldn't exist in remote system yet
    byte[] hash = sm.getHash(blob);
    Assert.assertNotNull("empty blob always exists", sm.getSisBlob(hash));
    Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
    StagedBlob staged = sm.stage(blob, mbox);
    Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
    MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
    Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
    Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(bytes, mblob.getLocalBlob().getInputStream()));
    //blob uploaded, now sis should return true and increment ref count
    Blob sisBlob = sm.getSisBlob(hash);
    Assert.assertNotNull("object created", sisBlob);
    Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.getInputStream()));
}
Also used : Blob(com.zimbra.cs.store.Blob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) Mailbox(com.zimbra.cs.mailbox.Mailbox) ContentAddressableStoreManager(com.zimbra.cs.store.external.ContentAddressableStoreManager) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test) AbstractStoreManagerTest(com.zimbra.cs.store.AbstractStoreManagerTest)

Example 13 with Mailbox

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

the class TritonBlobStoreManagerTest method sis.

@Test
public void sis() throws Exception {
    TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
    Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
    Random rand = new Random();
    byte[] bytes = new byte[10000];
    rand.nextBytes(bytes);
    Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
    //blob has not yet been finalized, so it shouldn't exist in remote system yet
    byte[] hash = sm.getHash(blob);
    Assert.assertNull("object not yet created", sm.getSisBlob(hash));
    Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
    StagedBlob staged = sm.stage(blob, mbox);
    Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
    MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
    Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
    Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(bytes, mblob.getLocalBlob().getInputStream()));
    //blob uploaded, now sis should return true and increment ref count
    Blob sisBlob = sm.getSisBlob(hash);
    Assert.assertNotNull("object created", sisBlob);
    Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.getInputStream()));
    //delete once, should still exist;
    sm.delete(mblob);
    Assert.assertNotNull("object still ref'd", sm.getSisBlob(hash));
    //delete twice (once for original, once since we just did a sisCheck above)
    sm.delete(mblob);
    sm.delete(mblob);
    Assert.assertNull("object deleted", sm.getSisBlob(hash));
}
Also used : Blob(com.zimbra.cs.store.Blob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) Mailbox(com.zimbra.cs.mailbox.Mailbox) ContentAddressableStoreManager(com.zimbra.cs.store.external.ContentAddressableStoreManager) Random(java.util.Random) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test) AbstractStoreManagerTest(com.zimbra.cs.store.AbstractStoreManagerTest)

Example 14 with Mailbox

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

the class TagActionTest method permissions.

@Test
public void permissions() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    Tag tag1 = mbox.createTag(null, name1, (byte) 0);
    Element request = new Element.XMLElement(MailConstants.TAG_ACTION_REQUEST);
    Element action = request.addElement(MailConstants.E_ACTION);
    action.addAttribute(MailConstants.A_OPERATION, ItemAction.OP_COLOR).addAttribute(MailConstants.A_COLOR, 4);
    action.addAttribute(MailConstants.A_TAG_NAMES, TagUtil.encodeTags(name1));
    try {
        new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct2, acct));
        Assert.fail("colored another user's tags without permissions");
    } catch (ServiceException e) {
        Assert.assertEquals("expected error code: " + ServiceException.PERM_DENIED, ServiceException.PERM_DENIED, e.getCode());
    }
    action.addAttribute(MailConstants.A_TAG_NAMES, (String) null).addAttribute(MailConstants.A_ID, tag1.getId());
    try {
        new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct2, acct));
        Assert.fail("colored another user's tags without permissions");
    } catch (ServiceException e) {
        Assert.assertEquals("expected error code: " + ServiceException.PERM_DENIED, ServiceException.PERM_DENIED, e.getCode());
    }
    action.addAttribute(MailConstants.A_TAG_NAMES, TagUtil.encodeTags(name2));
    try {
        new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct2, acct));
        Assert.fail("colored another user's tags without permissions");
    } catch (ServiceException e) {
        Assert.assertEquals("expected error code: " + ServiceException.PERM_DENIED, ServiceException.PERM_DENIED, e.getCode());
    }
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Element(com.zimbra.common.soap.Element) Tag(com.zimbra.cs.mailbox.Tag) Test(org.junit.Test)

Example 15 with Mailbox

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

the class TagActionTest method delete.

@Test
public void delete() throws Exception {
    Account acct = Provisioning.getInstance().getAccountByName("test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    // create the tag
    Element request = new Element.XMLElement(MailConstants.CREATE_TAG_REQUEST);
    request.addUniqueElement(MailConstants.E_TAG).addAttribute(MailConstants.A_COLOR, 4).addAttribute(MailConstants.A_NAME, "test");
    Element response = new CreateTag().handle(request, ServiceTestUtil.getRequestContext(acct));
    int tagId = response.getElement(MailConstants.E_TAG).getAttributeInt(MailConstants.A_ID);
    try {
        mbox.getTagById(null, tagId);
    } catch (ServiceException e) {
        Assert.fail("tag not created: " + e);
    }
    // delete the tag
    request = new Element.XMLElement(MailConstants.TAG_ACTION_REQUEST);
    request.addUniqueElement(MailConstants.E_ACTION).addAttribute(MailConstants.A_OPERATION, ItemAction.OP_HARD_DELETE).addAttribute(MailConstants.A_ID, tagId);
    new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct));
    try {
        mbox.getTagById(null, tagId);
        Assert.fail("tag not deleted");
    } catch (NoSuchItemException e) {
    }
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Element(com.zimbra.common.soap.Element) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test)

Aggregations

Mailbox (com.zimbra.cs.mailbox.Mailbox)817 Account (com.zimbra.cs.account.Account)389 Test (org.junit.Test)376 OperationContext (com.zimbra.cs.mailbox.OperationContext)365 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)306 Message (com.zimbra.cs.mailbox.Message)303 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)243 ItemId (com.zimbra.cs.service.util.ItemId)243 Element (com.zimbra.common.soap.Element)138 ServiceException (com.zimbra.common.service.ServiceException)127 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)127 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)106 MimeMessage (javax.mail.internet.MimeMessage)104 Folder (com.zimbra.cs.mailbox.Folder)82 ArrayList (java.util.ArrayList)81 ZMailbox (com.zimbra.client.ZMailbox)73 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)71 PreparedStatement (java.sql.PreparedStatement)67 SQLException (java.sql.SQLException)67 Header (javax.mail.Header)66