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);
}
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);
}
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);
}
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();
}
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);
}
}
Aggregations