use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestAccessKeyGrant method getZMailboxByKey.
private ZMailbox getZMailboxByKey() throws Exception {
Map<String, String> authAttrs = new HashMap<String, String>();
authAttrs.put(AUTH_K_ATTR, ACCESS_KEY);
authAttrs.put(AUTH_H_ATTR, getAccountId(OWNER_NAME));
ZAuthToken zat = new ZAuthToken(DUMMY_AUTH_PROVIDER, null, authAttrs);
ZMailbox.Options options = new ZMailbox.Options(zat, TestUtil.getSoapUrl());
return ZMailbox.getMailbox(options);
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class SharedImapNotificationTests method testDeleteMessageBySubjectNotifications.
@Test
public void testDeleteMessageBySubjectNotifications() throws Exception {
String folderName = "testDeleteMessageBySubjectNotifications-folder";
String subject1 = "testDeleteMessageBySubjectNotifications-msg1";
String subject2 = "testDeleteMessageBySubjectNotifications-msg2";
ZMailbox zmbox = TestUtil.getZMailbox(USER);
ZFolder folder = TestUtil.createFolder(zmbox, folderName);
TestUtil.addMessage(zmbox, subject1, folder.getId(), null);
TestUtil.addMessage(zmbox, subject2, folder.getId(), null);
connection = connect();
connection.login(PASS);
connection.select(folderName);
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
assertEquals("Size of map returned by fetch 1", 2, mdMap.size());
MailboxOperation deleteBySubject = new MailboxOperation() {
@Override
protected void run(ZMailbox zmbox) throws Exception {
TestUtil.deleteMessages(zmbox, "subject: " + subject2);
}
@Override
protected String checkResult() throws Exception {
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE)");
mdMap.entrySet().removeIf(e -> e.getValue().getEnvelope() == null || e.getValue().getEnvelope().getSubject() == null);
if (mdMap.size() != 1) {
return String.format("Size of map returned by fetch should be 1. Getting %d", mdMap.size());
}
return null;
}
};
runOp(deleteBySubject, zmbox, folder);
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class SharedImapNotificationTests method testDeleteFolderNotificationActiveFolder.
@Test
public void testDeleteFolderNotificationActiveFolder() throws Exception {
String folderName = "TestRemoteImapNotifications-folder";
String subject = "TestRemoteImapNotifications-testMessage";
ZMailbox zmbox = TestUtil.getZMailbox(USER);
ZFolder folder = TestUtil.createFolder(zmbox, folderName);
TestUtil.addMessage(zmbox, subject, folder.getId(), null);
connection = connect();
connection.login(PASS);
connection.select(folderName);
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
assertEquals("Size of map returned by initial fetch", 1, mdMap.size());
MailboxOperation deleteFolder = new MailboxOperation() {
@Override
protected void run(ZMailbox zmbox) throws Exception {
zmbox.deleteFolder(folder.getId());
}
@Override
protected String checkResult() throws Exception {
try {
connection.fetch("1:*", "(ENVELOPE BODY)");
return "should not be able to connect; connection should be closed";
}// connection is force closed
catch (SocketException | CommandFailedException e) {
}
return null;
}
};
runOp(deleteFolder, zmbox, folder);
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class SharedImapNotificationTests method testNotificationsEmptyActiveFolder.
@Test
public void testNotificationsEmptyActiveFolder() throws Exception {
String folderName = "testNotificationsEmptyActiveFolder-folder";
String subject1 = "testNotificationsEmptyActiveFolder-msg";
ZMailbox zmbox = TestUtil.getZMailbox(USER);
ZFolder folder = TestUtil.createFolder(zmbox, folderName);
connection = connect();
connection.login(PASS);
connection.select(folderName);
MailboxOperation addMessage = new MailboxOperation() {
@Override
protected void run(ZMailbox zmbox) throws Exception {
TestUtil.addMessage(zmbox, subject1, folder.getId(), null);
}
@Override
protected String checkResult() throws Exception {
try {
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
if (mdMap.size() != 1) {
return String.format("Size of map returned by fetch should be 1. Getting %d", mdMap.size());
}
} catch (CommandFailedException cfe) {
return cfe.getError();
}
return null;
}
};
runOp(addMessage, zmbox, folder);
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestCardDav method appleStyleGroup.
@Test
public void appleStyleGroup() throws ServiceException, IOException {
String contactsFolderUrl = TestCalDav.getFolderUrl(dav1, "Contacts");
HttpClient client = HttpClientBuilder.create().build();
HttpPost postMethod = new HttpPost(contactsFolderUrl);
TestCalDav.addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addHeader("Content-Type", "text/vcard");
postMethod.setEntity(new ByteArrayEntity(rachelVcard.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
postMethod = new HttpPost(contactsFolderUrl);
TestCalDav.addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addHeader("Content-Type", "text/vcard");
postMethod.setEntity(new ByteArrayEntity(blueGroupCreate.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
HttpMethodExecutor exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
exe.getNonNullHeaderValue("Location", "When creating Group");
postMethod = new HttpPost(contactsFolderUrl);
TestCalDav.addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addHeader("Content-Type", "text/vcard");
postMethod.setEntity(new ByteArrayEntity(parisVcard.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String url = String.format("%s%s", contactsFolderUrl, "F53A6F96-566F-46CC-8D48-A5263FAB5E38.vcf");
HttpPut putMethod = new HttpPut(url);
TestCalDav.addBasicAuthHeaderForUser(putMethod, dav1);
putMethod.addHeader("Content-Type", "text/vcard");
putMethod.setEntity(new ByteArrayEntity(blueGroupModify.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_NO_CONTENT);
HttpGet getMethod = new HttpGet(url);
TestCalDav.addBasicAuthHeaderForUser(getMethod, dav1);
getMethod.addHeader("Content-Type", "text/vcard");
exe = HttpMethodExecutor.execute(client, getMethod, HttpStatus.SC_OK);
String respBody = exe.getResponseAsString();
String[] expecteds = { "X-ADDRESSBOOKSERVER-KIND:group", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:BE43F16D-336E-4C3E-BAE6-22B8F245A986", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:07139DE2-EA7B-46CB-A970-C4DF7F72D9AE" };
for (String expected : expecteds) {
assertTrue(String.format("GET should contain '%s'\nBODY=%s", expected, respBody), respBody.contains(expected));
}
// members are actually stored in a different way. Make sure it isn't a fluke
// that the GET response contained the correct members by checking that the members
// appear where expected in a search hit.
SearchRequest searchRequest = new SearchRequest();
searchRequest.setSortBy("dateDesc");
searchRequest.setLimit(8);
searchRequest.setSearchTypes("contact");
searchRequest.setQuery("in:Contacts");
ZMailbox mbox = TestUtil.getZMailbox(DAV1);
SearchResponse searchResp = mbox.invokeJaxb(searchRequest);
assertNotNull("JAXB SearchResponse object", searchResp);
List<SearchHit> hits = searchResp.getSearchHits();
assertNotNull("JAXB SearchResponse hits", hits);
assertEquals("JAXB SearchResponse hits", 3, hits.size());
boolean seenGroup = false;
for (SearchHit hit : hits) {
ContactInfo contactInfo = (ContactInfo) hit;
if ("BlueGroup".equals(contactInfo.getFileAs())) {
seenGroup = true;
assertEquals("Number of members of group in search hit", 2, contactInfo.getContactGroupMembers().size());
}
ZimbraLog.test.info("Hit %s class=%s", hit, hit.getClass().getName());
}
assertTrue("Seen group", seenGroup);
}
Aggregations