use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method testGetNativeContactsIdsMerge.
/**
* Tests the getNativeContactsIds() method when a merge has to be performed.
*/
public void testGetNativeContactsIdsMerge() {
final long[] NATIVE_IDS = { 10, 85, 12, 103, 44, 38 };
final long[] DELETED_IDS = { NATIVE_IDS[0], NATIVE_IDS[5], NATIVE_IDS[3] };
PeopleContactsApi pca = new PeopleContactsApi(mDatabaseHelper);
// the database is empty, it shall not return any ids
assertNull(pca.getNativeContactsIds());
// let's add the contacts
for (int i = 0; i < NATIVE_IDS.length; i++) {
ContactChange[] contact = filterContactChanges(ContactChangeHelper.randomContact(ContactChange.INVALID_ID, ContactChange.INVALID_ID, NATIVE_IDS[i]));
assertTrue(pca.addNativeContact(contact));
}
// check that they exist and in the right order (ascending)
long[] ids = pca.getNativeContactsIds();
assertEquals(NATIVE_IDS.length, ids.length);
assertTrue(checkExistAndAscendingOrder(NATIVE_IDS, ids));
// delete them from CAB as it was coming from backend or user
// this has to be done without PeopleContactsApi wrapper as it does not support
// operations for Contacts not related to the native address book
List<ContactIdInfo> ciiList = new ArrayList<ContactIdInfo>(DELETED_IDS.length);
final SQLiteDatabase readableDb = mDatabaseHelper.getReadableDatabase();
try {
final SQLiteStatement nativeToLocalId = ContactsTable.fetchLocalFromNativeIdStatement(readableDb);
for (int i = 0; i < DELETED_IDS.length; i++) {
final ContactIdInfo cii = new ContactIdInfo();
cii.localId = ContactsTable.fetchLocalFromNativeId((int) DELETED_IDS[i], nativeToLocalId);
cii.nativeId = (int) DELETED_IDS[i];
ciiList.add(cii);
}
} finally {
readableDb.close();
}
mDatabaseHelper.syncDeleteContactList(ciiList, false, true);
// check the returned list of ids which should be similar as before
ids = pca.getNativeContactsIds();
assertEquals(NATIVE_IDS.length, ids.length);
assertTrue(checkExistAndAscendingOrder(NATIVE_IDS, ids));
// check that the deleted ids have the deleted flag
for (int i = 0; i < DELETED_IDS.length; i++) {
final ContactChange[] cc = pca.getContact(DELETED_IDS[i]);
assertEquals(cc[0].getType(), ContactChange.TYPE_DELETE_CONTACT);
}
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method checkContactUpdates.
/**
* Checks that the updated ContactChange array matches the original ContactChange
* array with the performed ContactChange updates.
*
* @param original the original ContactChange array
* @param updates the array of ContacChange updates that have been applied
* @param updatedContact the array of ContactChange representing the original contact after having performed the updates
* @return true if the new ContactChange reflect the updates, false if not
*/
private void checkContactUpdates(ContactChange[] original, ContactChange[] updates, ContactChange[] updatedContact) {
int addedCount = 0;
int deletedCount = 0;
int updatedCount = 0;
int index;
for (int i = 0; i < updates.length; i++) {
final ContactChange cc = updates[i];
switch(cc.getType()) {
case ContactChange.TYPE_ADD_DETAIL:
index = findContactChangeIndex(updatedContact, cc);
assertTrue(index != -1);
addedCount++;
break;
case ContactChange.TYPE_UPDATE_DETAIL:
index = findContactChangeIndex(updatedContact, cc);
assertTrue(index != -1);
updatedCount++;
break;
case ContactChange.TYPE_DELETE_DETAIL:
index = findContactChangeIndex(updatedContact, cc);
assertTrue(index == -1);
deletedCount++;
break;
}
}
assertEquals(original.length + addedCount - deletedCount, updatedContact.length);
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method testAddNativeContact.
/**
* Tests the addNativeContact() method.
*/
public void testAddNativeContact() {
final long NATIVE_ID = 15;
PeopleContactsApi pca = new PeopleContactsApi(mDatabaseHelper);
// the database is empty, it shall not return any ids
assertNull(pca.getNativeContactsIds());
// let's add a contact
final ContactChange[] contact = ContactChangeHelper.randomContact(ContactChange.INVALID_ID, ContactChange.INVALID_ID, NATIVE_ID);
assertTrue(pca.addNativeContact(contact));
// check that it exists
final long[] ids = pca.getNativeContactsIds();
assertEquals(1, ids.length);
assertEquals(NATIVE_ID, ids[0]);
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method testAddDeleteNativeContact.
/**
* Tests the methods sequence addNativeContact() then deleteNativeContact().
*/
public void testAddDeleteNativeContact() {
final long NATIVE_ID = 15;
PeopleContactsApi pca = new PeopleContactsApi(mDatabaseHelper);
// the database is empty, it shall not return any ids
assertNull(pca.getNativeContactsIds());
// let's add a contact
final ContactChange[] contact = ContactChangeHelper.randomContact(ContactChange.INVALID_ID, ContactChange.INVALID_ID, NATIVE_ID);
assertTrue(pca.addNativeContact(contact));
// check that it exists
long[] ids = pca.getNativeContactsIds();
assertEquals(1, ids.length);
assertEquals(NATIVE_ID, ids[0]);
// now let's remove it
assertTrue(pca.deleteNativeContact(NATIVE_ID, false));
// check that it no longer exists
ids = pca.getNativeContactsIds();
assertNull(ids);
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class UpdateNativeContactsTest method compareContactWithContactChange.
/**
* Compares a Contact details with an array of ContactChange.
*
* @param contact the Contact to compare
* @param contactChange the array of ContactChange to compare
* @return true if the Contact is equivalent to the array of ContactChange, false otherwise
*/
private boolean compareContactWithContactChange(Contact contact, ContactChange[] contactChanges) {
final NativeContactsApi nca = NativeContactsApi.getInstance();
final List<ContactDetail> details = contact.details;
for (int i = 0; i < details.size(); i++) {
final ContactDetail detail = details.get(i);
if (nca.isKeySupported(ContactDetailsTable.mapInternalKeyToContactChangeKey(detail.key.ordinal()))) {
// check if there is a corresponding ContactChange
if (!hasEquivalentContactChange(contactChanges, detail)) {
return false;
}
}
}
return true;
}
Aggregations