use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestImapImport method setUp.
@Override
public void setUp() throws Exception {
cleanUp();
mDisplayMailFoldersOnly = Provisioning.getInstance().getLocalServer().isImapDisplayMailFoldersOnly();
Provisioning.getInstance().getLocalServer().setImapDisplayMailFoldersOnly(false);
// Get mailbox references
if (!TestUtil.accountExists(LOCAL_USER_NAME)) {
TestUtil.createAccount(LOCAL_USER_NAME);
}
if (!TestUtil.accountExists(REMOTE_USER_NAME)) {
TestUtil.createAccount(REMOTE_USER_NAME);
}
mRemoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
mLocalMbox = TestUtil.getZMailbox(LOCAL_USER_NAME);
// Get or create folder
ZFolder folder = mLocalMbox.getFolderByPath(DS_FOLDER_ROOT);
if (folder == null) {
folder = TestUtil.createFolder(mLocalMbox, NAME_PREFIX);
}
// Create data source
int port = Integer.parseInt(TestUtil.getServerAttr(Provisioning.A_zimbraImapBindPort));
mDataSource = new ZImapDataSource(NAME_PREFIX, true, "localhost", port, REMOTE_USER_NAME, TestUtil.DEFAULT_PASSWORD, folder.getId(), ConnectionType.cleartext);
String id = mLocalMbox.createDataSource(mDataSource);
mDataSource = null;
for (ZDataSource ds : mLocalMbox.getAllDataSources()) {
if (ds.getId().equals(id)) {
mDataSource = ds;
}
}
assertNotNull(mDataSource);
// Turn on cleartext login
mOriginalCleartextValue = TestUtil.getServerAttr(Provisioning.A_zimbraImapCleartextLoginEnabled);
TestUtil.setServerAttr(Provisioning.A_zimbraImapCleartextLoginEnabled, ProvisioningConstants.TRUE);
// Turn off STARTTLS support so that unit tests don't bomb on Linux (see bug 33683).
mOriginalEnableStarttls = LC.javamail_imap_enable_starttls.booleanValue();
LC.javamail_imap_enable_starttls.setDefault(Boolean.toString(false));
}
use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestImapSync method createDataSource.
private ZDataSource createDataSource() throws Exception {
ConnectionType ctype = config.getSecurity() == MailConfig.Security.SSL ? ConnectionType.ssl : ConnectionType.cleartext;
String id = localMailbox.createDataSource(new ZImapDataSource("TestImapSync", true, config.getHost(), config.getPort(), config.getAuthenticationId(), pass, "1", ctype));
for (ZDataSource ds : localMailbox.getAllDataSources()) {
if (ds.getId().equals(id)) {
return ds;
}
}
Assert.fail("Could not find data source");
return null;
}
use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestDataSource method disabledTestCal.
// XXX bburtin: disabled test due to bug 37222 (unable to parse Google calendar).
public void disabledTestCal() throws Exception {
// Create folder.
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String parentId = Integer.toString(Mailbox.ID_FOLDER_USER_ROOT);
String urlString = "http://www.google.com/calendar/ical/k2kh7ncij3s05dog63g0o0n254%40group.calendar.google.com/public/basic.ics";
ZFolder folder;
try {
folder = mbox.createFolder(parentId, NAME_PREFIX + " testCal", ZFolder.View.appointment, null, null, urlString);
} catch (ServiceException e) {
assertEquals(ServiceException.RESOURCE_UNREACHABLE, e.getCode());
ZimbraLog.test.warn("Unable to test calendar data source for %s: %s", urlString, e.toString());
return;
}
// Get the data source that was implicitly created.
ZCalDataSource ds = (ZCalDataSource) getDataSource(mbox, folder.getId());
assertNotNull(ds);
// Test data source. If the test fails, skip validation so we don't
// get false positives when the feed is down or the test
// is running on a box that's not connected to the internet.
String error = mbox.testDataSource(ds);
if (error != null) {
ZimbraLog.test.warn("Unable to test iCal data source for %s: %s.", urlString, error);
return;
}
// Import data and confirm that the folder is not empty.
List<ZDataSource> list = new ArrayList<ZDataSource>();
list.add(ds);
mbox.importData(list);
waitForData(mbox, folder);
// Delete folder, import data, and make sure that the data source was deleted.
mbox.deleteFolder(folder.getId());
mbox.importData(list);
ds = (ZCalDataSource) getDataSource(mbox, folder.getId());
assertNull(ds);
}
use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestDataSource method testRss.
/**
* Creates a folder that syncs to another folder via RSS, and verifies that an
* RSS data source was implicitly created.
*/
@Test
public void testRss() throws Exception {
// Create source folder, make it publicly readable, and add a message to it.
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String parentId = Integer.toString(Mailbox.ID_FOLDER_USER_ROOT);
ZFolder sourceFolder = TestUtil.createFolder(mbox, "/" + NAME_PREFIX + " testRss source");
mbox.modifyFolderGrant(sourceFolder.getId(), GranteeType.pub, null, "r", null);
String subject = NAME_PREFIX + " testRss";
TestUtil.addMessage(mbox, subject, sourceFolder.getId());
// Create destination folder that syncs to the source folder via RSS.
String urlString = String.format("https://%s:%s/home/%s%s.rss", TestUtil.getServerAttr(Provisioning.A_zimbraServiceHostname), TestUtil.getServerAttr(Provisioning.A_zimbraMailSSLPort), USER_NAME, sourceFolder.getPath());
urlString = HttpUtil.encodePath(urlString);
ZFolder rssFolder = mbox.createFolder(parentId, NAME_PREFIX + " testRss destination", null, null, null, urlString);
// Get the data source that was implicitly created.
ZRssDataSource ds = (ZRssDataSource) getDataSource(mbox, rssFolder.getId());
assertNotNull(ds);
assertNull(mbox.testDataSource(ds));
// Import data and validate the synced message.
List<ZDataSource> list = new ArrayList<ZDataSource>();
list.add(ds);
mbox.importData(list);
waitForData(mbox, rssFolder);
ZMessage syncedMsg = TestUtil.getMessage(mbox, "in:\"" + rssFolder.getPath() + "\"");
assertEquals(subject, syncedMsg.getSubject());
/*
* Bug 102261 - simulate ZWC deleting an item from the folder
*/
ConvActionSelector sel = ConvActionSelector.createForIdsAndOperation(syncedMsg.getConversationId(), "trash");
sel.setConstraint("-dtjs");
sel.setFolder(syncedMsg.getFolderId());
try {
mbox.invokeJaxb(new ConvActionRequest(sel));
} catch (SoapFaultException sfe) {
fail("SoapFaultException caught when deleting item from RSS datasource folder - " + sfe.getMessage());
}
// Delete folder, import data, and make sure that the data source was deleted.
// Data source import runs asynchronously, so poll until the data source is gone.
mbox.deleteFolder(rssFolder.getId());
//JBF - do not do the import; it will fail if DS is already deleted
//mbox.importData(list);
// XXX bburtin: disabled check to avoid false positives (bug 54816). Some sort
// of race condition is causing this check to fail intermittently. I was unable
// to consistently repro.
/*
for (int i = 1; i <= 10; i++) {
ds = (ZRssDataSource) getDataSource(mbox, rssFolder.getId());
if (ds == null) {
break;
}
Thread.sleep(500);
}
assertNull(ds);
*/
}
use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestUtil method deleteTestData.
/**
* Delete all messages, tags and folders in the user's mailbox whose subjects contain the given substring. For
* messages, the subject must contain subjectString as a separate word. Tags and folders can have the string
* anywhere in the name.
*/
public static void deleteTestData(String userName, String subjectSubstring) throws ServiceException {
ZMailbox mbox = getZMailbox(userName);
deleteMessages(mbox, "is:anywhere " + subjectSubstring);
// Workaround for bug 15160 (is:anywhere is busted)
deleteMessages(mbox, "in:trash " + subjectSubstring);
deleteMessages(mbox, "in:junk " + subjectSubstring);
deleteMessages(mbox, "in:sent " + subjectSubstring);
// Workaround for bug 31370
deleteMessages(mbox, "subject: " + subjectSubstring);
// Delete tags
for (ZTag tag : mbox.getAllTags()) {
if (tag.getName().contains(subjectSubstring)) {
mbox.deleteTag(tag.getId());
}
}
// Delete folders
for (ZFolder folder : mbox.getAllFolders()) {
if (folder.getName().contains(subjectSubstring)) {
mbox.deleteFolder(folder.getId());
}
}
// Delete contacts
for (ZContact contact : mbox.getAllContacts(null, ContactSortBy.nameAsc, false, null)) {
String fullName = contact.getAttrs().get("fullName");
if (fullName != null && fullName.contains(subjectSubstring)) {
mbox.deleteContact(contact.getId());
}
}
// Delete data sources
List<ZDataSource> dataSources = mbox.getAllDataSources();
for (ZDataSource ds : dataSources) {
if (ds.getName().contains(subjectSubstring)) {
mbox.deleteDataSource(ds);
}
}
// Delete appointments
List<String> ids = search(mbox, subjectSubstring, ZSearchParams.TYPE_APPOINTMENT);
if (!ids.isEmpty()) {
mbox.deleteItem(StringUtil.join(",", ids), null);
}
// Delete documents
ids = search(mbox, subjectSubstring, ZSearchParams.TYPE_DOCUMENT);
if (!ids.isEmpty()) {
mbox.deleteItem(StringUtil.join(",", ids), null);
}
ZMailbox adminMbox = getZMailboxAsAdmin(userName);
adminMbox.emptyDumpster();
}
Aggregations