2010-07-01 08:47:57 -04:00
|
|
|
/*
|
|
|
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
|
|
|
* Copyright (C) 2010 Mickael Guessant
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
package davmail.exchange;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2010-07-06 06:54:04 -04:00
|
|
|
import java.util.UUID;
|
2010-07-01 08:47:57 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test ExchangeSession contact features.
|
|
|
|
*/
|
|
|
|
@SuppressWarnings({"UseOfSystemOutOrSystemErr"})
|
|
|
|
public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase {
|
2010-07-06 06:54:04 -04:00
|
|
|
static String itemName;
|
|
|
|
/*
|
2010-07-01 08:47:57 -04:00
|
|
|
public void testSearchContacts() throws IOException {
|
|
|
|
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, ExchangeSession.CONTACT_ATTRIBUTES, null);
|
|
|
|
for (ExchangeSession.Contact contact : contacts) {
|
|
|
|
System.out.println(session.getItem(ExchangeSession.CONTACTS, contact.getName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testSearchContactsUidOnly() throws IOException {
|
|
|
|
Set<String> attributes = new HashSet<String>();
|
|
|
|
attributes.add("uid");
|
|
|
|
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null);
|
|
|
|
for (ExchangeSession.Contact contact : contacts) {
|
|
|
|
System.out.println(contact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testSearchContactsByUid() throws IOException {
|
|
|
|
Set<String> attributes = new HashSet<String>();
|
|
|
|
attributes.add("uid");
|
|
|
|
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null);
|
|
|
|
for (ExchangeSession.Contact contact : contacts) {
|
|
|
|
System.out.println(session.searchContacts(ExchangeSession.CONTACTS, attributes, session.equals("uid", contact.get("uid"))));
|
|
|
|
}
|
2010-07-06 06:54:04 -04:00
|
|
|
} */
|
|
|
|
|
|
|
|
public void testCreateFolder() throws IOException {
|
|
|
|
// recreate empty folder
|
|
|
|
session.deleteFolder("testcontactfolder");
|
|
|
|
session.createContactFolder("testcontactfolder");
|
2010-07-01 08:47:57 -04:00
|
|
|
}
|
2010-07-06 06:20:52 -04:00
|
|
|
|
|
|
|
public void testCreateContact() throws IOException {
|
2010-07-06 06:54:04 -04:00
|
|
|
itemName = UUID.randomUUID().toString() + ".vcf";
|
2010-07-06 06:20:52 -04:00
|
|
|
VCardWriter vCardWriter = new VCardWriter();
|
|
|
|
vCardWriter.startCard();
|
2010-07-06 06:54:04 -04:00
|
|
|
vCardWriter.appendProperty("N", "sn", "givenName", "middlename", "personaltitle", "namesuffix");
|
|
|
|
vCardWriter.appendProperty("FN", "common name");
|
|
|
|
vCardWriter.appendProperty("NICKNAME", "nickname");
|
2010-07-06 06:20:52 -04:00
|
|
|
vCardWriter.endCard();
|
|
|
|
|
2010-07-06 06:54:04 -04:00
|
|
|
session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), null, null);
|
|
|
|
|
|
|
|
}
|
2010-07-06 06:20:52 -04:00
|
|
|
|
2010-07-06 06:54:04 -04:00
|
|
|
public void testGetContact() throws IOException {
|
|
|
|
ExchangeSession.Contact contact = (ExchangeSession.Contact) session.getItem("testcontactfolder", itemName);
|
|
|
|
assertEquals("common name", contact.get("cn"));
|
|
|
|
assertEquals("sn", contact.get("sn"));
|
|
|
|
assertEquals("givenName", contact.get("givenName"));
|
|
|
|
assertEquals("middlename", contact.get("middlename"));
|
|
|
|
assertEquals("personaltitle", contact.get("personaltitle"));
|
|
|
|
assertEquals("namesuffix", contact.get("namesuffix"));
|
|
|
|
assertNotNull("lastmodified");
|
|
|
|
assertEquals("nickname", contact.get("nickname"));
|
2010-07-06 06:20:52 -04:00
|
|
|
}
|
2010-07-01 08:47:57 -04:00
|
|
|
}
|