Search in sources :

Example 51 with ContactChange

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

the class ContactChangeHelper method areUnsortedChangeListsEqual.

public static boolean areUnsortedChangeListsEqual(ContactChange[] a, ContactChange[] b, boolean compareAll) {
    final int aLength = a.length;
    final int bLength = b.length;
    if (aLength != bLength) {
        printContactChangeList(a);
        printContactChangeList(b);
        return false;
    }
    for (int i = 0; i < aLength; i++) {
        final ContactChange ccA = a[i];
        boolean matchFound = false;
        for (int j = 0; j < bLength; j++) {
            final ContactChange ccB = a[j];
            if (ccA.getKey() == ccB.getKey() && ccA.getNabDetailId() == ccB.getNabDetailId()) {
                if (areChangesEqual(ccA, ccB, compareAll)) {
                    matchFound = true;
                    break;
                }
            }
        }
        if (!matchFound) {
            Log.e("CONTACT COMPARISON", "Contact List Unsorted comparison because of mismatch, List A to follow:");
            printContactChangeList(a);
            Log.e("CONTACT COMPARISON", "Contact List Unsorted comparison because of mismatch, List B to follow:");
            printContactChangeList(b);
            return false;
        }
    }
    return true;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 52 with ContactChange

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

the class ContactChangeTest method testConstructors.

@SmallTest
public void testConstructors() {
    String value = new String("value");
    int type = ContactChange.TYPE_ADD_CONTACT;
    long nabContactId = 100;
    long internalContactId = 200;
    long backendContactId = 300;
    //----------------------------------------
    ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_PHONE, value, ContactChange.FLAG_HOME);
    assertEquals(ContactChange.KEY_VCARD_PHONE, cc.getKey());
    assertEquals("vcard.phone", cc.getKeyToString());
    assertEquals(value, cc.getValue());
    assertEquals(ContactChange.FLAG_HOME, cc.getFlags());
    assertEquals(ContactChange.TYPE_UNKNOWN, cc.getType());
    assertEquals(-1L, cc.getBackendContactId());
    assertEquals(-1L, cc.getBackendDetailId());
    assertEquals(-1L, cc.getInternalContactId());
    assertEquals(-1L, cc.getInternalDetailId());
    assertEquals(-1L, cc.getNabContactId());
    assertEquals(-1L, cc.getNabDetailId());
    //----------------------------------------
    cc = new ContactChange(type);
    assertEquals(type, cc.getType());
    assertEquals(ContactChange.FLAG_NONE, cc.getFlags());
    assertEquals(-1L, cc.getBackendContactId());
    assertEquals(-1L, cc.getBackendDetailId());
    assertEquals(-1L, cc.getInternalContactId());
    assertEquals(-1L, cc.getInternalDetailId());
    assertEquals(-1L, cc.getNabContactId());
    assertEquals(-1L, cc.getNabDetailId());
    assertEquals(null, cc.getValue());
    assertEquals(ContactChange.KEY_UNKNOWN, cc.getKey());
    //----------------------------------------
    cc = new ContactChange(Long.MAX_VALUE);
    assertEquals(Long.MAX_VALUE, cc.getNabContactId());
    assertEquals(ContactChange.FLAG_NONE, cc.getFlags());
    assertEquals(ContactChange.TYPE_UNKNOWN, cc.getType());
    assertEquals(-1L, cc.getBackendContactId());
    assertEquals(-1L, cc.getBackendDetailId());
    assertEquals(-1L, cc.getInternalContactId());
    assertEquals(-1L, cc.getInternalDetailId());
    assertEquals(-1L, cc.getNabDetailId());
    assertEquals(null, cc.getValue());
    assertEquals(ContactChange.KEY_UNKNOWN, cc.getKey());
    //----------------------------------------
    cc = new ContactChange(Long.MAX_VALUE, Long.MIN_VALUE);
    assertEquals(Long.MAX_VALUE, cc.getNabContactId());
    assertEquals(Long.MIN_VALUE, cc.getNabDetailId());
    assertEquals(ContactChange.FLAG_NONE, cc.getFlags());
    assertEquals(ContactChange.TYPE_UNKNOWN, cc.getType());
    assertEquals(-1L, cc.getBackendContactId());
    assertEquals(-1L, cc.getBackendDetailId());
    assertEquals(-1L, cc.getInternalContactId());
    assertEquals(-1L, cc.getInternalDetailId());
    assertEquals(null, cc.getValue());
    assertEquals(ContactChange.KEY_UNKNOWN, cc.getKey());
    //----------------------------------------
    ContactChange original = new ContactChange();
    original.setNabContactId(nabContactId);
    original.setBackendContactId(backendContactId);
    original.setInternalContactId(internalContactId);
    cc = ContactChange.createIdsChange(original, type);
    assertEquals(nabContactId, cc.getNabContactId());
    assertEquals(backendContactId, cc.getBackendContactId());
    assertEquals(internalContactId, cc.getInternalContactId());
    assertEquals(type, cc.getType());
    assertEquals(ContactChange.FLAG_NONE, cc.getFlags());
    assertEquals(-1L, cc.getBackendDetailId());
    assertEquals(-1L, cc.getInternalDetailId());
    assertEquals(-1L, cc.getNabDetailId());
    assertEquals(null, cc.getValue());
    assertEquals(ContactChange.KEY_UNKNOWN, cc.getKey());
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 53 with ContactChange

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

the class NativeContactsApiTest method verifyNewContactIds.

/**
	 * Utility method to verify that received Ids for a new Contact are as expected 
	 */
private void verifyNewContactIds(long expectedNabId, ContactChange[] originalCcList, ContactChange[] ids) {
    assertNotNull(ids);
    final int idsCount = ids.length;
    final int originalCount = originalCcList.length;
    assertEquals(originalCount + 1, idsCount);
    final long expectedInternalContactId = originalCcList[0].getInternalContactId();
    long previousDetailId = ContactChange.INVALID_ID;
    long orgAndTitleNabDetailId = ContactChange.INVALID_ID;
    for (int i = 0; i < idsCount; i++) {
        final ContactChange idCc = ids[i];
        if (!VersionUtils.is2XPlatform() && i > 0) {
            final int originalKey = originalCcList[i - 1].getKey();
            if (originalKey == ContactChange.KEY_VCARD_NAME || originalKey == ContactChange.KEY_VCARD_NOTE || originalKey == ContactChange.KEY_VCARD_NICKNAME || originalKey == ContactChange.KEY_VCARD_URL) {
                // These fields don't get written to 1.X NAB and so correspond to a null idCc
                assertNull(idCc);
                continue;
            }
        }
        assertNotNull(idCc);
        // Internal Contact ID check
        assertEquals(expectedInternalContactId, idCc.getInternalContactId());
        if (i > 0) {
            // Internal Detail ID check
            final ContactChange originalCc = originalCcList[i - 1];
            assertEquals(originalCcList[i - 1].getInternalDetailId(), ids[i].getInternalDetailId());
            // NAB Detail ID check
            assertEquals(ContactChange.TYPE_UPDATE_NAB_DETAIL_ID, ids[i].getType());
            long currentDetailId = ids[i].getNabDetailId();
            if (previousDetailId != ContactChange.INVALID_ID) {
                if (originalCc.getKey() != ContactChange.KEY_VCARD_ORG && originalCc.getKey() != ContactChange.KEY_VCARD_TITLE) {
                    if (VersionUtils.is2XPlatform()) {
                        // Only checking on 2.X because 1.X does not guarantee sequential ids 
                        // for the details (diff tables)
                        assertEquals(previousDetailId + 1, currentDetailId);
                    }
                } else {
                    // Org and title share nab detail id on both 1.X and 2.X!
                    if (orgAndTitleNabDetailId == ContactChange.INVALID_ID) {
                        orgAndTitleNabDetailId = currentDetailId;
                    } else {
                        assertEquals(orgAndTitleNabDetailId, currentDetailId);
                    }
                }
            }
            previousDetailId = currentDetailId;
        } else {
            assertEquals(ContactChange.TYPE_UPDATE_NAB_CONTACT_ID, ids[i].getType());
            // NAB Contact ID check
            if (expectedNabId != ContactChange.INVALID_ID) {
                assertEquals(expectedNabId, ids[0].getNabContactId());
            }
        }
    }
}
Also used : 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