use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class NowPlusContactSummaryTest method testUpdateDisplayName.
/**
* Tests updating a contact's display name.
*/
@SmallTest
public void testUpdateDisplayName() {
Log.i(LOG_TAG, "***** EXECUTING testtestUpdateDisplayName *****");
Log.i(LOG_TAG, "Create ContactSummaryTable");
ContactSummaryTable.create(mTestDatabase.getWritableDatabase());
Log.i(LOG_TAG, "Create also a ContactDetailsTable");
ContactDetailsTable.create(mTestDatabase.getWritableDatabase());
Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
final Contact contact = new Contact();
contact.localContactID = new Long(10);
contact.nativeContactId = new Integer(11);
ServiceStatus serviceStatus = ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
assertEquals(ServiceStatus.SUCCESS, serviceStatus);
// Name
ContactDetail nameDetail = new ContactDetail();
nameDetail.localContactID = contact.localContactID;
VCardHelper.Name name = new VCardHelper.Name();
name.firstname = "John";
name.surname = "Doe";
nameDetail.setName(name);
// ORG
ContactDetail orgDetail = new ContactDetail();
nameDetail.localContactID = contact.localContactID;
VCardHelper.Organisation org = new VCardHelper.Organisation();
org.name = "VF";
org.unitNames.add("Dev");
orgDetail.setOrg(org, ContactDetail.DetailKeyTypes.WORK);
ContactDetail emailDetail = new ContactDetail();
emailDetail.localContactID = contact.localContactID;
emailDetail.setEmail("dev@vf.com", ContactDetail.DetailKeyTypes.WORK);
ContactDetail phoneDetail = new ContactDetail();
phoneDetail.localContactID = contact.localContactID;
phoneDetail.setTel("+123456789", ContactDetail.DetailKeyTypes.HOME);
contact.details.add(nameDetail);
contact.details.add(orgDetail);
contact.details.add(emailDetail);
contact.details.add(phoneDetail);
// Loop for number of details + 1
final int numLoopCycles = contact.details.size() + 1;
int loopCycles = numLoopCycles;
boolean isMe = false;
while (loopCycles-- > 0) {
assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
if (contact.details.size() > 0) {
contact.details.remove(0);
}
}
final Contact meContact = new Contact();
meContact.localContactID = new Long(11);
meContact.nativeContactId = new Integer(12);
isMe = true;
Log.i(LOG_TAG, "Add me Contact to ContactSummaryTable");
serviceStatus = ContactSummaryTable.addContact(meContact, mTestDatabase.getWritableDatabase());
assertEquals(ServiceStatus.SUCCESS, serviceStatus);
meContact.details.add(nameDetail);
meContact.details.add(orgDetail);
meContact.details.add(emailDetail);
meContact.details.add(phoneDetail);
loopCycles = numLoopCycles;
while (loopCycles-- > 0) {
assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
if (contact.details.size() > 0) {
contact.details.remove(0);
}
}
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class NowPlusContactSummaryTest method testModifyingContactDetails.
/**
* Tests modifying a contact detail of an existing contact.
*/
@SmallTest
public void testModifyingContactDetails() {
Log.i(LOG_TAG, "***** EXECUTING testModifyingContactDetails *****");
Log.i(LOG_TAG, "Create ContactSummaryTable");
ContactSummaryTable.create(mTestDatabase.getWritableDatabase());
Log.i(LOG_TAG, "Create also a ContactDetailsTable");
ContactDetailsTable.create(mTestDatabase.getWritableDatabase());
Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
final Contact contact = new Contact();
contact.localContactID = new Long(10);
contact.nativeContactId = new Integer(11);
ServiceStatus serviceStatus = ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
assertEquals(ServiceStatus.SUCCESS, serviceStatus);
Log.i(LOG_TAG, "Add a contact detail to the previous contact");
ContactDetail contactDetail = new ContactDetail();
contactDetail.localContactID = contact.localContactID;
contactDetail.setEmail("toto@mail.co.uk", ContactDetail.DetailKeyTypes.HOME);
boolean isMe = false;
assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
Log.i(LOG_TAG, "Modify a contact detail to the previous contact");
contactDetail = new ContactDetail();
contactDetail.localContactID = contact.localContactID;
final String eMail2 = "toto2@mail.co.uk";
contactDetail.setEmail(eMail2, ContactDetail.DetailKeyTypes.HOME);
assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class NowPlusContactSummaryTest method testModifyingingContactSummary.
/**
* Tests modifying a contact summary.
*/
@SmallTest
public void testModifyingingContactSummary() {
Log.i(LOG_TAG, "***** EXECUTING testModifyingingContactSummary *****");
Log.i(LOG_TAG, "Create ContactSummaryTable");
ContactSummaryTable.create(mTestDatabase.getWritableDatabase());
Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
final Contact contact = mTestModule.createDummyContactData();
contact.localContactID = new Long(10);
contact.nativeContactId = new Integer(11);
ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
Log.i(LOG_TAG, "Fetching a ContactSummary from ContactSummaryTable");
ContactSummary contactSummary = new ContactSummary();
ServiceStatus serviceStatus = ContactSummaryTable.fetchSummaryItem(contact.localContactID, contactSummary, mTestDatabase.getReadableDatabase());
assertEquals(ServiceStatus.SUCCESS, serviceStatus);
compareContactWithContactSummary(contact, contactSummary);
Log.i(LOG_TAG, "Modify a contact");
final Contact contact2 = copyContact(contact);
contact2.synctophone = !contact.synctophone;
serviceStatus = ContactSummaryTable.modifyContact(contact2, mTestDatabase.getWritableDatabase());
assertEquals(ServiceStatus.SUCCESS, serviceStatus);
Log.i(LOG_TAG, "Fetching a ContactSummary from ContactSummaryTable");
contactSummary = new ContactSummary();
serviceStatus = ContactSummaryTable.fetchSummaryItem(contact.localContactID, contactSummary, mTestDatabase.getReadableDatabase());
assertEquals(ServiceStatus.SUCCESS, serviceStatus);
// by doing so, we should get back to the original if it was correctly
// modified
contactSummary.synctophone = !contactSummary.synctophone;
compareContactWithContactSummary(contact, contactSummary);
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class NowPlusContactsTest method testAddDeleteContacts.
@MediumTest
public void testAddDeleteContacts() {
Log.i(LOG_TAG, "***** EXECUTING testAddDeleteContacts *****");
Log.i(LOG_TAG, "Test contact functionality (add delete contacts)");
Log.i(LOG_TAG, "Test 1a: Initialise test environment and load database");
assertTrue(initialise());
Log.i(LOG_TAG, "Test 1b: Remove user data");
mDatabaseHelper.removeUserData();
ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
assertEquals(ServiceStatus.SUCCESS, status);
Log.i(LOG_TAG, "Test 1c: Add " + NUM_OF_CONTACTS + " random contacts");
// add contacts and check if added contacts are the same as fetched
Contact[] inputContacts = new Contact[NUM_OF_CONTACTS];
Contact addedContact = new Contact();
for (int i = 0; i < NUM_OF_CONTACTS; i++) {
inputContacts[i] = mTestModule.createDummyContactData();
status = mDatabaseHelper.addContact(inputContacts[i]);
assertEquals(ServiceStatus.SUCCESS, status);
status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, addedContact);
assertEquals(ServiceStatus.SUCCESS, status);
assertTrue(TestModule.doContactsMatch(addedContact, inputContacts[i]));
}
Log.i(LOG_TAG, "Test 1d: Delete contacts and check if deletion was correct");
for (int i = 0; i < inputContacts.length; i++) {
// check if deletion works good
status = mDatabaseHelper.deleteContact(inputContacts[i].localContactID);
assertEquals(ServiceStatus.SUCCESS, status);
Contact removedContact = new Contact();
status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, removedContact);
// contact was deleted so it shouldn't be found
assertEquals(ServiceStatus.ERROR_NOT_FOUND, status);
}
shutdown();
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class NowPlusContactsTest method testAddDeleteContactsDetails.
@MediumTest
public void testAddDeleteContactsDetails() {
Log.i(LOG_TAG, "***** EXECUTING testAddDeleteContactsDetails *****");
Log.i(LOG_TAG, "Test contact functionality (add delete contacts details)");
Log.i(LOG_TAG, "Test 1a: Initialise test environment and load database");
assertTrue(initialise());
Log.i(LOG_TAG, "Test 1b: Remove user data");
mDatabaseHelper.removeUserData();
ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
assertEquals(ServiceStatus.SUCCESS, status);
Log.i(LOG_TAG, "Test 1c: Add " + NUM_OF_CONTACTS + " random contacts");
// add contacts and check if added contacts are the same as fetched
Contact[] inputContacts = new Contact[NUM_OF_CONTACTS];
Contact addedContact = new Contact();
for (int i = 0; i < NUM_OF_CONTACTS; i++) {
inputContacts[i] = mTestModule.createDummyContactData();
status = mDatabaseHelper.addContact(inputContacts[i]);
assertEquals(ServiceStatus.SUCCESS, status);
status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, addedContact);
assertEquals(ServiceStatus.SUCCESS, status);
assertTrue(TestModule.doContactsMatch(addedContact, inputContacts[i]));
}
Log.i(LOG_TAG, "Test 1d: Delete contacts detatils and check if deletion was correct");
for (int i = 0; i < inputContacts.length; i++) {
for (int j = 0; j < inputContacts[i].details.size(); j++) {
ContactDetail detail = inputContacts[i].details.get(j);
status = mDatabaseHelper.deleteContactDetail(detail.localDetailID);
assertEquals(ServiceStatus.SUCCESS, status);
}
// check if deletion works good
Contact modifiedContact = new Contact();
status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, modifiedContact);
assertEquals(ServiceStatus.SUCCESS, status);
assertTrue(TestModule.doContactsMatch(modifiedContact, inputContacts[i]));
}
shutdown();
}
Aggregations