📄 rmscontactmanagertest.java
字号:
testAddContactArray();
break;
case 7:
testGetContactArrayList();
break;
case 8:
testSearchContactArrayList();
break;
case 9:
testSearchBigContactArrayList();
break;
case 10:
testRFC2426();
break;
case 11:
Cache.getContactSnapShot(Cache.VCARD);
testSlowSync();
Contact[] c = getContactArray();
Cache.saveContactSnapShot(Cache.VCARD, c);
break;
case 12:
testGetItemFromQueue();
testRemoveAllContacts();
break;
case 13:
testGetItemFromQueue();
break;
case 14:
testSimulateFastSync('N');
testSimulateFastSync('D');
break;
case 15:
Cache.getContactSnapShot(Cache.VCARD);
testFastSync();
c = getContactArray();
Cache.saveContactSnapShot(Cache.VCARD, c);
break;
default:
break;
}
}
private void createTestObjects() throws ContactManagerException {
System.gc();
vCard = new Vector();
RecordStore rs = null;
try {
cm = ContactManagerFactory.getContactManager(ContactManager.RMS_TYPE);
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
c = new Contact(
"JDoe",
"Jhon",
"Doe",
"email@1",
"email@2",
"email@3",
"032348259",
"023458989",
"333245990");
contactList = new Contact[5];
contactList[0] = new Contact(
"Kate",
"Katy",
"Jhones",
"katyemail@1",
"katyemail@2",
"katyemail@3",
"032348259",
"023458989",
"333245990");
contactList[1] = new Contact(
"Tommmy",
"Tom",
"Bombadil",
"Tomemail@1",
"Tomemail@2",
"Tomemail@3",
"032348259",
"023458989",
"333245990");
contactList[2] = new Contact(
"Timmmy",
"Tim",
"Gerald",
"Timemai@l0",
"Timemai@l2",
"Timemai@l3",
"032348259",
"023458989",
"333245990");
contactList[3] = new Contact(
null,
"",
null,
"Timedmail@12",
"",
"",
"2223399339",
"",
"");
contactList[4] = new Contact(
"Anybody",
null,
"",
"anonymousmail@1",
"",
null,
"00001111",
"",
"");
bigContactList = new Contact[CONTACT_NUMBER];
for (int i=0; i<CONTACT_NUMBER; i++) {
bigContactList[i] = new Contact(
"NickName"+i,
"FirstName"+i,
"LastName"+i,
"defaultemail@"+i,
"email_2_@"+i,
"email_3_@"+i,
"032348259" + i,
"023458989" + i,
"333245990" + i);
}
}
private void testAddNoMailContacts() throws AssertionFailedException {
int counter = 0;
try {
noMailContact1 = new Contact(
null,
null,
null,
null,
null,
"",
"00000001",
"",
"");
} catch (ContactManagerException ex) {
counter++;
Log.info("Cannot add null mail contact");
}
try {
noMailContact2 = new Contact(
null,
"",
"",
null,
"",
"",
"123489859",
"",
"");
} catch (ContactManagerException ex) {
counter++;
Log.info("Cannot add empty string mail contact");
}
assertEquals(counter, 2);
}
public void testRFC2426() throws Exception {
Log.info("11.Test for RFC2426 parser");
String str = c.format();
vCard.addElement(str);
//Log.info(str);
Contact expected = new Contact();
expected.setContactId(c.getContactId());
expected.parse(str);
//Log.info(c.toString());
//Log.info(expected.toString());
assertTrue(expected.toString().equals(c.toString()));
for (int i=0; i<contactList.length; i++) {
str = contactList[i].format();
vCard.addElement(str);
Log.debug(contactList[i].format());
}
for (int i=0; i<bigContactList.length; i++) {
str = bigContactList[i].format();
vCard.addElement(str);
//Log.info(str);
}
Log.info("11.Test for RFC2426 parser Succesfull");
}
private void showResult() {
Enumeration e = null;
try {
e = cm.getContactList();
} catch (ContactManagerException ex) {
ex.printStackTrace();
}
while (e.hasMoreElements()) {
Contact c = (Contact) e.nextElement();
}
}
private void testSlowSync() {
Log.info("12.Test for Slow Sync");
try {
cm.sync(SyncML.ALERT_CODE_SLOW);
} catch (MailClientException ex) {
ex.printStackTrace();
} catch (ConfigException ex) {
ex.printStackTrace();
} catch (SyncException ex) {
ex.printStackTrace();
} catch (ContactManagerException ex) {
ex.printStackTrace();
Log.info("Some existent contact were not added");
}
Log.info("12.Test for Slow Sync succesfull");
}
private void testRemoveAllContacts() throws Exception{
Log.info("13.Test Remove all contact");
Enumeration addressbook = cm.getContactList();
while (addressbook.hasMoreElements()) {
Contact c = (Contact) addressbook.nextElement();
cm.removeContact(c.getContactId());
}
vCard.removeAllElements();
Log.info("14.Test Remove all contact");
}
private void testGetItemFromQueue() {
Log.info("15.Test Item Queue");
Enumeration e = cm.getSyncItems('N');
int counter = 0;
while(e.hasMoreElements()) {
PimItem ii = (PimItem) e.nextElement();
counter++;
}
e = null;
Log.info("******** Total new Items: " + counter);
e = cm.getSyncItems('U');
counter = 0;
while(e.hasMoreElements()) {
PimItem ii = (PimItem) e.nextElement();
counter++;
}
e = null;
Log.info("******** Total Updated Items: " + counter);
e = cm.getSyncItems('D');
counter = 0;
while(e.hasMoreElements()) {
PimItem ii = (PimItem) e.nextElement();
counter++;
}
e = null;
Log.info("******** Total Deleted Items: " + counter);
Log.info("15.Test Item Queue Successfull");
}
private void testSimulateFastSync(char c) {
Log.info("16.Test Remove Item from Queue");
Enumeration e = null;
switch (c) {
case 'N':
e = cm.getSyncItems('N');
if (e.hasMoreElements()) {
PimItem ii = (PimItem) e.nextElement();
cm.removeSyncItem(ii.getKey());
}
break;
case 'D':
e = cm.getSyncItems('D');
if (e.hasMoreElements()) {
PimItem ii = (PimItem) e.nextElement();
cm.removeSyncItem(ii.getKey());
}
break;
default:
break;
}
testGetItemFromQueue();
Log.info("16.Test Remove Item from Queue");
}
private void testFastSync() {
Log.info("17.Test for Fast Sync");
try {
cm.sync(SyncML.ALERT_CODE_FAST);
} catch (MailClientException ex) {
ex.printStackTrace();
} catch (ConfigException ex) {
ex.printStackTrace();
} catch (SyncException ex) {
ex.printStackTrace();
} catch (ContactManagerException ex) {
ex.printStackTrace();
Log.info("Some existent contact were not added");
}
Log.info("17.Test for Fast Sync succesfull");
testGetItemFromQueue();
}
private Contact[] getContactArray() {
Enumeration e = null;
try {
e = cm.getContactList();
} catch (ContactManagerException ex) {
ex.printStackTrace();
}
Vector v = new Vector();
while (e.hasMoreElements()) {
v.addElement((Contact)e.nextElement());
}
Contact[] c = new Contact[v.size()];
v.copyInto(c);
return c;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -