use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestMountpoint method testInvalidMountpoint.
/**
* Tests {@link ZMailbox#getValidFolderIds(String)}.
*/
@Test
public void testInvalidMountpoint() throws Exception {
TestUtil.createAccount(USER_NAME);
TestUtil.createAccount(REMOTE_USER_NAME);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
String remoteFolderPath = "/" + NAME_PREFIX + "-testInvalidMountpoint-remote";
ZFolder remoteFolder = TestUtil.createFolder(remoteMbox, remoteFolderPath);
ZMountpoint mountpoint = TestUtil.createMountpoint(remoteMbox, remoteFolderPath, mbox, NAME_PREFIX + "-mountpoint");
// Test valid mountpoint.
Set<String> folderIds = new HashSet<String>();
folderIds.add(mountpoint.getId());
String inboxId = Integer.toString(Mailbox.ID_FOLDER_INBOX);
folderIds.add(inboxId);
String idString = mbox.getValidFolderIds(StringUtil.join(",", folderIds));
List<String> returnedIds = Arrays.asList(idString.split(","));
Assert.assertEquals("Number of return IDs from mbox.getValidFolderIds", 2, returnedIds.size());
Assert.assertTrue("Returned IDs should contain ID of inbox", returnedIds.contains(inboxId));
Assert.assertTrue("Returned IDs should contain ID of mountpoint", returnedIds.contains(mountpoint.getId()));
Assert.assertEquals("Should be 1 comma in string returned by mbox.getValidFolderIds", 1, getNumCommas(idString));
// Delete remote folder and confirm that the id is no longer returned.
remoteMbox.deleteFolder(remoteFolder.getId());
idString = mbox.getValidFolderIds(StringUtil.join(",", folderIds));
returnedIds = Arrays.asList(idString.split(","));
Assert.assertEquals("Number of return IDs from mbox.getValidFolderIds after mountpoint delete", 1, returnedIds.size());
Assert.assertTrue("Returned IDs should contain ID of inbox after mp delete", returnedIds.contains(inboxId));
Assert.assertEquals("Should no commas in string returned by mbox.getValidFolderIds after mp delete", 0, getNumCommas(idString));
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestNoOp method testNoOpMany.
@Test
public void testNoOpMany() throws ServiceException {
Set<Thread> threads = new HashSet<Thread>();
final Set<Exception> exceptions = new HashSet<Exception>();
for (int i = 0; i < THREAD_COUNT; i++) {
Thread t = new Thread() {
@Override
public void run() {
ZMailbox mbox = null;
try {
mbox = TestUtil.getZMailbox(USER_NAME);
} catch (ServiceException e) {
exceptions.add(e);
return;
}
for (int j = 0; j < LOOP_COUNT; j++) {
try {
mbox.noOp(1000);
} catch (ServiceException se) {
exceptions.add(se);
}
}
}
};
threads.add(t);
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
try {
// note this test fails with normal timeout min limit in NoOp.java
t.join(THREAD_TIMEOUT);
} catch (InterruptedException e) {
}
Assert.assertFalse(t.isAlive());
}
if (!exceptions.isEmpty()) {
for (Exception e : exceptions) {
ZimbraLog.test.error("Exception during test", e);
}
Assert.fail(exceptions.size() + " exceptions during test");
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestLongSearchResultSets method testMessages.
@Test
public void testMessages() {
try {
Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT);
long timestamp = System.currentTimeMillis() - 3600 * 60 * 1000;
int numMessages = 2257;
int firstLimit = 100;
int incLimit = 50;
int offset = 0;
ArrayList<String> expectedIds = new ArrayList<String>();
for (int i = 0; i < numMessages; i++) {
Message msg = TestUtil.addMessage(recieverMbox, TestUtil.getAddress(RECIPIENT), TestUtil.getAddress(SENDER), NAME_PREFIX + " testing bug " + i, String.format("this message contains a search string %s which we are searching for and a number %d and timestamp %d", SEARCH_STRING, i, timestamp), timestamp);
expectedIds.add(Integer.toString(msg.getId()));
timestamp += 1000;
Thread.sleep(100);
}
Collections.reverse(expectedIds);
Thread.sleep(100);
ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT);
ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(firstLimit);
searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
List<String> msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
assertEquals(firstLimit, msgIds.size());
int gotMessages = msgIds.size();
List<String> seenIds = new ArrayList<String>();
seenIds.addAll(msgIds);
int recCount = 1;
offset += firstLimit;
while (gotMessages > 0) {
searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(incLimit);
searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
searchParams.setOffset(offset);
msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
recCount++;
gotMessages = msgIds.size();
int resCount = 0;
for (String szId : msgIds) {
assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, szId, seenIds.indexOf(szId)), seenIds.contains(szId));
seenIds.add(szId);
resCount++;
}
// jetty sometimes crashes on Mac when bombarded with request without a timeout
Thread.sleep(100);
offset += incLimit;
}
for (int i = 0; i < expectedIds.size(); i++) {
assertEquals("IDs at index " + i + " do not match", expectedIds.get(i), seenIds.get(i));
}
assertEquals("Returned incorrect number of messages", numMessages, seenIds.size());
} catch (ServiceException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestLongSearchResultSets method testConversations2.
@Test
public void testConversations2() {
try {
Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT2);
long timestamp = System.currentTimeMillis() - 3600 * 60 * 1000;
int numMessages = 3207;
int firstLimit = 100;
int incLimit = 50;
int offset = 0;
ArrayList<String> expectedIds = new ArrayList<String>();
for (int i = 0; i < numMessages; i++) {
Message msg = TestUtil.addMessage(recieverMbox, TestUtil.getAddress(RECIPIENT2), TestUtil.getAddress(SENDER), NAME_PREFIX + " testing bug " + i, String.format("this message contains a search string %s which we are searching for and a number %d and timestamp %d", SEARCH_STRING, i, timestamp), timestamp);
expectedIds.add(Integer.toString(msg.getId()));
timestamp += 1000;
Thread.sleep(100);
}
Collections.reverse(expectedIds);
Thread.sleep(100);
ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT2);
ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(firstLimit);
searchParams.setTypes(ZSearchParams.TYPE_CONVERSATION);
List<String> msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
assertEquals(firstLimit, msgIds.size());
int gotMessages = msgIds.size();
List<String> seenIds = new ArrayList<String>();
seenIds.addAll(msgIds);
int recCount = 1;
offset += firstLimit;
while (gotMessages > 0) {
searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(incLimit);
searchParams.setTypes(ZSearchParams.TYPE_CONVERSATION);
searchParams.setOffset(offset);
msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
recCount++;
gotMessages = msgIds.size();
int resCount = 0;
for (String szId : msgIds) {
assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, szId, seenIds.indexOf(szId)), seenIds.contains(szId));
seenIds.add(szId);
resCount++;
}
// jetty sometimes crashes on Mac when bombarded with request without a timeout
Thread.sleep(100);
offset += incLimit;
}
assertEquals("Returned incorrect number of conversations", numMessages, seenIds.size());
} catch (ServiceException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestMessageIntercept method testInterceptMultiValue.
/**
* Confirms that legal intercept works with multiple interceptor addresses (bug 30961).
*/
public void testInterceptMultiValue() throws Exception {
// Turn on legal intercept for recipient account.
String interceptor1Address = TestUtil.getAddress(INTERCEPTOR1_NAME);
String interceptor2Address = TestUtil.getAddress(INTERCEPTOR2_NAME);
String senderAddress = TestUtil.getAddress(SENDER_NAME);
String[] interceptorAddresses = new String[] { interceptor1Address, interceptor2Address };
TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptAddress, interceptorAddresses);
TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptSendHeadersOnly, LdapConstants.LDAP_FALSE);
// Send message to recipient account.
ZMailbox tappedMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
String tappedAddress = TestUtil.getAddress(RECIPIENT_NAME);
String subject = NAME_PREFIX + " testIntercept-receive";
TestUtil.addMessageLmtp(subject, tappedAddress, senderAddress);
// Make sure both interceptor accounts intercepted it.
ZMailbox interceptor1Mbox = TestUtil.getZMailbox(INTERCEPTOR1_NAME);
ZMailbox interceptor2Mbox = TestUtil.getZMailbox(INTERCEPTOR2_NAME);
ZMessage tappedMsg = TestUtil.getMessage(tappedMbox, "subject:\"" + subject + "\"");
ZMessage interceptMsg1 = TestUtil.waitForMessage(interceptor1Mbox, "subject:\"" + subject + "\"");
ZMessage interceptMsg2 = TestUtil.waitForMessage(interceptor2Mbox, "subject:\"" + subject + "\"");
verifyInterceptMessage(interceptMsg1, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
verifyInterceptMessage(interceptMsg2, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
compareContent(tappedMbox, tappedMsg, interceptor1Mbox, interceptMsg1);
compareContent(tappedMbox, tappedMsg, interceptor2Mbox, interceptMsg2);
}
Aggregations