use of com.vodafone360.people.engine.contactsync.PeopleContactsApi in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method testUpdateGetNativeContact.
/**
* Tests the updateNativeContact() and getContact() methods.
*/
@Suppress
public void testUpdateGetNativeContact() {
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
ContactChange[] contact = filterContactChanges(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]);
// perform some updates to the contact
final ContactChange[] updatedDetails = ContactChangeHelper.randomContactUpdate(contact);
pca.updateNativeContact(updatedDetails);
// get the contact back
final ContactChange[] savedContact = pca.getContact(NATIVE_ID);
assertNotNull(savedContact);
// check that the needed updates have been performed
checkContactUpdates(contact, updatedDetails, savedContact);
}
use of com.vodafone360.people.engine.contactsync.PeopleContactsApi 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.PeopleContactsApi 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.PeopleContactsApi 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);
}
Aggregations