Search in sources :

Example 1 with Mailbox

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

the class AbstractStoreManagerTest method incoming.

@Test
public void incoming() throws Exception {
    Random rand = new Random();
    byte[] bytes = new byte[1000000];
    rand.nextBytes(bytes);
    StoreManager sm = StoreManager.getInstance();
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    IncomingBlob incoming = sm.newIncomingBlob("foo", null);
    OutputStream out = incoming.getAppendingOutputStream();
    out.write(bytes);
    Assert.assertEquals(bytes.length, incoming.getCurrentSize());
    Blob blob = incoming.getBlob();
    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()));
    mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
    Assert.assertEquals("mblob size = staged size", staged.getSize(), mblob.getSize());
    Assert.assertTrue("mailboxblob content = mime content", TestUtil.bytesEqual(bytes, mblob.getLocalBlob().getInputStream()));
    sm.delete(mblob);
}
Also used : Random(java.util.Random) Mailbox(com.zimbra.cs.mailbox.Mailbox) OutputStream(java.io.OutputStream) ExternalStoreManager(com.zimbra.cs.store.external.ExternalStoreManager) Test(org.junit.Test) ThreaderTest(com.zimbra.cs.mailbox.ThreaderTest)

Example 2 with Mailbox

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

the class AbstractStoreManagerTest method nonExistingBlob.

@Test
public void nonExistingBlob() throws Exception {
    StoreManager sm = StoreManager.getInstance();
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MailboxBlob blob = sm.getMailboxBlob(mbox, 999, 1, "1");
    Assert.assertNull("expect null blob", blob);
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ExternalStoreManager(com.zimbra.cs.store.external.ExternalStoreManager) Test(org.junit.Test) ThreaderTest(com.zimbra.cs.mailbox.ThreaderTest)

Example 3 with Mailbox

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

the class AbstractStoreManagerTest method store.

@Test
public void store() 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());
    Assert.assertEquals("blob size = message size", pm.getRawData().length, blob.getRawSize());
    Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(mimeBytes, 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(mimeBytes, mblob.getLocalBlob().getInputStream()));
    mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
    Assert.assertEquals("mblob size = staged size", staged.getSize(), mblob.getSize());
    Assert.assertTrue("mailboxblob content = mime content", TestUtil.bytesEqual(mimeBytes, mblob.getLocalBlob().getInputStream()));
    InputStream stream = sm.getContent(mblob);
    Assert.assertTrue("stream content = mime content", TestUtil.bytesEqual(mimeBytes, stream));
    sm.delete(mblob);
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExternalStoreManager(com.zimbra.cs.store.external.ExternalStoreManager) Test(org.junit.Test) ThreaderTest(com.zimbra.cs.mailbox.ThreaderTest)

Example 4 with Mailbox

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

the class ExternalBlobConsistencyCheckTest method createUnexpectedBlob.

@Override
protected String createUnexpectedBlob(int index) throws ServiceException, IOException {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    SimpleStoreManager sm = (SimpleStoreManager) StoreManager.getInstance();
    String dir = sm.dirName(mbox);
    File file = new File(dir + "/foo" + index + ".txt");
    file.createNewFile();
    return file.getCanonicalPath();
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) File(java.io.File)

Example 5 with Mailbox

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

the class StoreManagerNegativeTest method nullLocator.

@Test
public void nullLocator() throws Exception {
    Random rand = new Random();
    byte[] bytes = new byte[10000];
    rand.nextBytes(bytes);
    StoreManager sm = StoreManager.getInstance();
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    IncomingBlob incoming = sm.newIncomingBlob("foo", null);
    OutputStream out = incoming.getAppendingOutputStream();
    out.write(bytes);
    Blob blob = incoming.getBlob();
    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());
    try {
        mblob.getLocalBlob().getInputStream();
        Assert.fail("Expected IOException since locator is not handled correctly");
    } catch (IOException io) {
    //expected
    } finally {
        sm.delete(mblob);
    }
}
Also used : Blob(com.zimbra.cs.store.Blob) IncomingBlob(com.zimbra.cs.store.IncomingBlob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) Random(java.util.Random) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailboxBlob(com.zimbra.cs.store.MailboxBlob) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) IncomingBlob(com.zimbra.cs.store.IncomingBlob) StoreManager(com.zimbra.cs.store.StoreManager) 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