Search in sources :

Example 6 with NativeContactsApi

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);
}
Also used : UpdateNativeContacts(com.vodafone360.people.engine.contactsync.UpdateNativeContacts) NativeContactsApi(com.vodafone360.people.engine.contactsync.NativeContactsApi)

Example 7 with NativeContactsApi

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;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) NativeContactsApi(com.vodafone360.people.engine.contactsync.NativeContactsApi)

Example 8 with NativeContactsApi

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);
}
Also used : NativeContactsApi(com.vodafone360.people.engine.contactsync.NativeContactsApi)

Example 9 with NativeContactsApi

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);
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) NativeContactsApi(com.vodafone360.people.engine.contactsync.NativeContactsApi) NativeContactsApi1(com.vodafone360.people.engine.contactsync.NativeContactsApi1) NativeContactsApi2(com.vodafone360.people.engine.contactsync.NativeContactsApi2) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

NativeContactsApi (com.vodafone360.people.engine.contactsync.NativeContactsApi)7 UpdateNativeContacts (com.vodafone360.people.engine.contactsync.UpdateNativeContacts)3 Cursor (android.database.Cursor)1 SmallTest (android.test.suitebuilder.annotation.SmallTest)1 Suppress (android.test.suitebuilder.annotation.Suppress)1 MainApplication (com.vodafone360.people.MainApplication)1 Contact (com.vodafone360.people.datatypes.Contact)1 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)1 Name (com.vodafone360.people.datatypes.VCardHelper.Name)1 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)1 NativeContactsApi1 (com.vodafone360.people.engine.contactsync.NativeContactsApi1)1 NativeContactsApi2 (com.vodafone360.people.engine.contactsync.NativeContactsApi2)1 NetworkAgent (com.vodafone360.people.service.agent.NetworkAgent)1 UserDataProtection (com.vodafone360.people.service.utils.UserDataProtection)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1