Search in sources :

Example 16 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeExporterTest method testExportToNativeWithUpdatedContacts_deletedDetails.

/**
     * Tests export to native with added details to a existing contacts.
     */
@Suppress
public void testExportToNativeWithUpdatedContacts_deletedDetails() {
    // add contacts on People side and sync them to native side
    final int NEW_CONTACTS_COUNT = 30;
    final NativeContactsApiMockup nativeMockup = new NativeContactsApiMockup();
    final PeopleContactsApiMockup peopleMockup = new PeopleContactsApiMockup(null);
    // add new contacts syncable contact on People side
    feedPeopleContactsApiWithNewSyncableContacts(peopleMockup, NEW_CONTACTS_COUNT);
    long[] nativeIdsFromPeople = peopleMockup.getNativeContactsIds();
    // shall be null because our PeopleContactsApiMockup will add them once synced
    assertEquals(null, nativeIdsFromPeople);
    long[] localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(NEW_CONTACTS_COUNT, localIds.length);
    long[] nativeIds = nativeMockup.getContactIds(null);
    assertEquals(null, nativeIds);
    // perform the export to native
    runNativeExporter(nativeMockup, peopleMockup);
    // check both sides are updated correctly
    nativeIdsFromPeople = peopleMockup.getNativeContactsIds();
    assertEquals(NEW_CONTACTS_COUNT, nativeIdsFromPeople.length);
    nativeIds = nativeMockup.getContactIds(null);
    assertEquals(NEW_CONTACTS_COUNT, nativeIds.length);
    localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(null, localIds);
    assertTrue(NativeImporterTest.compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
    // pick few contacts and add details to them
    ContactChange[][] addedDetails = new ContactChange[3][];
    addedDetails[0] = getNewDetails(peopleMockup, 1);
    peopleMockup.updateNativeContact(addedDetails[0]);
    addedDetails[1] = getNewDetails(peopleMockup, 2);
    peopleMockup.updateNativeContact(addedDetails[1]);
    addedDetails[2] = getNewDetails(peopleMockup, 5);
    peopleMockup.updateNativeContact(addedDetails[2]);
    // perform the export to native
    runNativeExporter(nativeMockup, peopleMockup);
    // check both sides are equivalent
    localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(null, localIds);
    assertTrue(NativeImporterTest.compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
    // remove the previously added details
    for (int i = 0; i < addedDetails.length; i++) {
        forceDetailsAsDeleteType(addedDetails[i]);
        peopleMockup.updateNativeContact(addedDetails[i]);
    }
    // perform the export to native
    runNativeExporter(nativeMockup, peopleMockup);
    // check both sides are equivalent
    localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(null, localIds);
    assertTrue(NativeImporterTest.compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
}
Also used : NativeContactsApiMockup(com.vodafone360.people.tests.engine.contactsync.NativeImporterTest.NativeContactsApiMockup) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 17 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeImporterTest method addDetails.

/**
     * Adds details to the provided contact.
     * 
     * @param contact
     * @return
     */
private ContactChange[] addDetails(NativeContactsApiMockup ncam, ContactChange[] contact) {
    long nativeId = contact[0].getNabContactId();
    int index = contact.length;
    // create the new Contact
    ContactChange[] newContact = new ContactChange[contact.length + 2];
    // copy original info into it
    System.arraycopy(contact, 0, newContact, 0, contact.length);
    // add extra details
    newContact[index] = new ContactChange(ContactChange.KEY_VCARD_EMAIL, "xxxxx@xxxxx.xx", ContactChange.FLAG_WORK);
    newContact[index].setNabContactId(nativeId);
    newContact[index].setNabDetailId(ncam.getAndIncNabDetailId());
    index++;
    newContact[index] = new ContactChange(ContactChange.KEY_VCARD_PHONE, "+9912345678", ContactChange.FLAG_WORK);
    newContact[index].setNabContactId(nativeId);
    newContact[index].setNabDetailId(ncam.getAndIncNabDetailId());
    index++;
    return newContact;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 18 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeImporterTest method testMultipleImportsFromNativeWithUpdatedContact_updatedDetails.

/**
     * Tests multiple imports from native with an updated contact via updated details.
     */
public void testMultipleImportsFromNativeWithUpdatedContact_updatedDetails() {
    final NativeContactsApiMockup nativeMockup = new NativeContactsApiMockup();
    final PeopleContactsApiMockup peopleMockup = new PeopleContactsApiMockup(null);
    // add new contacts on native side
    feedNativeContactsApi(nativeMockup, 20, null);
    long[] nativeIds = nativeMockup.getContactIds(null);
    assertEquals(20, nativeIds.length);
    // import the new contacts
    runNativeImporter(nativeMockup, peopleMockup);
    // compare contacts on both sides
    assertTrue(compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
    // pick an existing contact
    final ContactChange[] originalContact = nativeMockup.getContact(10);
    // modify its details
    for (int i = 0; i < originalContact.length; i++) {
        final ContactChange originalChange = originalContact[i];
        originalContact[i] = alterContactChangeValue(originalChange, originalChange.getValue() + "x9x");
    }
    nativeMockup.setContact(10, originalContact);
    // import the new contacts
    runNativeImporter(nativeMockup, peopleMockup);
    // compare contacts on both sides
    assertTrue(compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 19 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeImporterTest method alterContactChangeValue.

/**
     * Alter the given ContactChange value.
     * 
     * @param change the change to modify
     * @param newValue the new value to set to the provided ContactChange
     * @return a new ContactChange with the modified value
     */
public static ContactChange alterContactChangeValue(ContactChange change, String newValue) {
    final ContactChange alteredContactChange = new ContactChange(change.getKey(), newValue, change.getFlags());
    alteredContactChange.setBackendContactId(change.getBackendContactId());
    alteredContactChange.setBackendDetailId(change.getBackendDetailId());
    alteredContactChange.setInternalContactId(change.getInternalContactId());
    alteredContactChange.setInternalDetailId(change.getInternalDetailId());
    alteredContactChange.setNabContactId(change.getNabContactId());
    alteredContactChange.setNabDetailId(change.getNabDetailId());
    return alteredContactChange;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 20 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeImporterTest method performNativeImport.

/**
     * Performs a native import and checks that the needed ticks are as expected.
     * 
     * @param ncam the NativeContactsApiMockup instance
     * @param pcam the PeopleContactsApiMockup instance
     * @param contactsCount the number of native contacts to setup and import
     */
private void performNativeImport(NativeContactsApiMockup ncam, PeopleContactsApiMockup pcam, float contactsCount) {
    final NativeImporter nativeImporter = new NativeImporter(pcam, ncam, false);
    final float requiredTicks = 1 + (contactsCount / NATIVE_IMPORTER_MAX_OPERATION_COUNT) + (contactsCount % NATIVE_IMPORTER_MAX_OPERATION_COUNT > 0 ? 1 : 0);
    // feed the native side
    feedNativeContactsApi(ncam, contactsCount, null);
    final long[] nativeIds = ncam.getContactIds(null);
    assertEquals(contactsCount, nativeIds.length);
    // setup the people client side
    long[] peopleIds = pcam.getNativeContactsIds();
    assertNull(peopleIds);
    for (int i = 0; i < requiredTicks; i++) {
        // check the importer state
        assertEquals(NativeImporter.RESULT_UNDEFINED, nativeImporter.getResult());
        assertTrue(!nativeImporter.isDone());
        // perform an import tick
        nativeImporter.tick();
    }
    // check the importer state, it shall have finished the import
    assertEquals(NativeImporter.RESULT_OK, nativeImporter.getResult());
    assertTrue(nativeImporter.isDone());
    // check that all the native contacts are on the people client side
    peopleIds = pcam.getNativeContactsIds();
    assertEquals(contactsCount, peopleIds.length);
    for (int i = 0; i < peopleIds.length; i++) {
        final ContactChange[] peopleContact = pcam.getContact(peopleIds[i]);
        final ContactChange[] nativeContact = pcam.getContact(nativeIds[i]);
        assertTrue(ContactChangeHelper.areChangeListsEqual(peopleContact, nativeContact, false));
    }
}
Also used : NativeImporter(com.vodafone360.people.engine.contactsync.NativeImporter) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Aggregations

ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)33 Name (com.vodafone360.people.datatypes.VCardHelper.Name)6 Organisation (com.vodafone360.people.datatypes.VCardHelper.Organisation)6 PeopleContactsApi (com.vodafone360.people.engine.contactsync.PeopleContactsApi)6 Cursor (android.database.Cursor)5 Suppress (android.test.suitebuilder.annotation.Suppress)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 ArrayList (java.util.ArrayList)5 SQLException (android.database.SQLException)4 SQLiteException (android.database.sqlite.SQLiteException)4 Uri (android.net.Uri)4 PostalAddress (com.vodafone360.people.datatypes.VCardHelper.PostalAddress)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 Contact (com.vodafone360.people.datatypes.Contact)3 ContentValues (android.content.ContentValues)2 StructuredName (android.provider.ContactsContract.CommonDataKinds.StructuredName)2 MediumTest (android.test.suitebuilder.annotation.MediumTest)2 SmallTest (android.test.suitebuilder.annotation.SmallTest)2 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)2 NativeContactsApi (com.vodafone360.people.engine.contactsync.NativeContactsApi)2