use of com.vodafone360.people.engine.contactsync.NativeContactsApi in project 360-Engine-for-Android by 360.
the class UpdateNativeContactsTest method testExportingNewContacts.
/**
* Tests the export of new syncable contacts.
*/
public void testExportingNewContacts() {
final int CONTACTS_COUNT = 10;
UpdateNativeContacts processor = new UpdateNativeContacts(mContactSyncCallback, mDatabaseHelper);
// check that there are no contacts to sync
long[] syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(null, syncableIds);
// put some contacts that need to be synchronized to native side
feedSyncableContactsInDatabase(CONTACTS_COUNT);
// check the count of the contacts to sync
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(CONTACTS_COUNT, syncableIds.length);
// run the UpdateNativeContacts processor until it finishes or it times out
runUpdateNativeContactsProcessor(processor);
// check the contacts count on native side
final NativeContactsApi nca = NativeContactsApi.getInstance();
long[] ids = null;
if (VersionUtils.is2XPlatform()) {
ids = nca.getContactIds(PEOPLE_ACCOUNT);
} else {
ids = nca.getContactIds(null);
}
assertEquals(CONTACTS_COUNT, ids.length);
// check that no more contact is syncable as the export is done
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(null, syncableIds);
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi 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;
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi in project 360-Engine-for-Android by 360.
the class SyncAdapter method forceSyncSettingsInCaseOfAppUpdate.
/**
* This method is essentially needed to force the sync settings
* to a consistent state in case of an Application Update.
* This is because old versions of the client do not set
* the sync adapter to syncable for the contacts authority.
*/
private void forceSyncSettingsInCaseOfAppUpdate() {
NativeContactsApi nabApi = NativeContactsApi.getInstance();
nabApi.setSyncable(true);
nabApi.setSyncAutomatically(mApplication.getInternetAvail() == InternetAvail.ALWAYS_CONNECT);
}
use of com.vodafone360.people.engine.contactsync.NativeContactsApi in project 360-Engine-for-Android by 360.
the class NativeContactsApiTest method testInstance.
/**
* Tests API functionality to do the following:
* - Create Instance
* - Get Instance
* - Destroy Instance
*/
@SmallTest
public void testInstance() {
// Need to destroy instance first for this test!
NativeContactsApi.destroyInstance();
NativeContactsApi nabApi = null;
boolean caughtException = false;
try {
nabApi = NativeContactsApi.getInstance();
} catch (InvalidParameterException ex) {
caughtException = true;
}
assertNull(nabApi);
assertTrue(caughtException);
NativeContactsApi.createInstance(getInstrumentation().getContext());
try {
nabApi = NativeContactsApi.getInstance();
caughtException = false;
} catch (InvalidParameterException ex) {
}
assertFalse(caughtException);
assertNotNull(nabApi);
NativeContactsApi.destroyInstance();
// Double Destroy
NativeContactsApi.destroyInstance();
try {
nabApi = NativeContactsApi.getInstance();
} catch (InvalidParameterException ex) {
caughtException = true;
}
assertTrue(caughtException);
NativeContactsApi.createInstance(getInstrumentation().getContext());
try {
nabApi = NativeContactsApi.getInstance();
caughtException = false;
} catch (InvalidParameterException ex) {
}
assertFalse(caughtException);
if (mUsing2xApi) {
assertTrue(nabApi instanceof NativeContactsApi2);
} else {
assertTrue(nabApi instanceof NativeContactsApi1);
}
}
Aggregations