use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class DbVolumeBlobsTest method blobsByMbox.
@Test
public void blobsByMbox() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
DeliveryOptions opt = new DeliveryOptions();
opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
ParsedMessage pm = new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false);
Message msg = mbox.addMessage(null, pm, opt, null);
Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
DbVolumeBlobs.addBlobReference(conn, mbox, vol, msg);
String digest = msg.getBlob().getDigest();
String path = msg.getBlob().getLocalBlob().getFile().getPath();
List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
Assert.assertEquals(1, blobs.size());
Assert.assertEquals(path, getPath(blobs.get(0)));
Account acct2 = Provisioning.getInstance().getAccount("test2@zimbra.com");
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
Message msg2 = mbox2.addMessage(null, pm, opt, null);
DbVolumeBlobs.addBlobReference(conn, mbox2, vol, msg2);
blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
Set<String> paths = new HashSet<String>();
paths.add(path);
paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
Assert.assertEquals(2, blobs.size());
for (BlobReference ref : blobs) {
Assert.assertTrue(paths.remove(getPath(ref)));
}
Assert.assertTrue(paths.isEmpty());
DbVolumeBlobs.deleteBlobRef(conn, mbox);
blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
Assert.assertEquals(1, blobs.size());
BlobReference ref = blobs.get(0);
path = msg2.getBlob().getLocalBlob().getFile().getPath();
Assert.assertEquals(path, getPath(ref));
Assert.assertEquals(mbox2.getId(), ref.getMailboxId());
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class DbVolumeBlobsTest method testDuplicateRow.
@Test
public void testDuplicateRow() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
DeliveryOptions opt = new DeliveryOptions();
opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
MailboxBlobInfo blobInfo = new MailboxBlobInfo(null, mbox.getId(), msg.getId(), msg.getSavedSequence(), String.valueOf(vol.getId()), null);
DbVolumeBlobs.addBlobReference(conn, blobInfo);
try {
DbVolumeBlobs.addBlobReference(conn, blobInfo);
Assert.fail("expected exception");
} catch (ServiceException e) {
// expected
}
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class ItemQueryTest method testInvalidRangeQuery.
@Test
public void testInvalidRangeQuery() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
Message msg1 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message msg2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
Message msg3 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject3"), dopt, null);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject4"), dopt, null);
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
String q = String.format("item:{%d--%d--%d}", msg1.getId(), msg2.getId(), msg3.getId());
sr.setQuery(q);
try {
doSearch(sr, acct);
Assert.fail("Should have thrown a PARSE_ERROR exception for " + q);
} catch (ServiceException e) {
Assert.assertEquals(e.getCode(), ServiceException.PARSE_ERROR);
}
sr.setSearchTypes("message");
q = String.format("item:{%d--%d,%d}", msg1.getId(), msg2.getId(), msg3.getId());
sr.setQuery(q);
try {
doSearch(sr, acct);
Assert.fail("Should have thrown an INVALID_REQUEST exception for " + q);
} catch (ServiceException e) {
Assert.assertEquals(e.getCode(), ServiceException.INVALID_REQUEST);
}
sr.setSearchTypes("message");
q = String.format("item:{%d,%d--%d}", msg1.getId(), msg2.getId(), msg3.getId());
sr.setQuery(q);
try {
doSearch(sr, acct);
Assert.fail("Should have thrown an INVALID_REQUEST exception for " + q);
} catch (ServiceException e) {
Assert.assertEquals(e.getCode(), ServiceException.INVALID_REQUEST);
}
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class ItemQueryTest method testOneItemQuery.
@Test
public void testOneItemQuery() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message msg2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject3"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery(String.format("item:{%d}", msg2.getId()));
sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 1, hits.size());
int msgId = Integer.parseInt(hits.get(0).getId());
Assert.assertEquals("correct hit 1", msg2.getId(), msgId);
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class ItemQueryTest method testAllItemsQuery.
@Test
public void testAllItemsQuery() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery("item:{all}");
sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 2, hits.size());
}
Aggregations