Search in sources :

Example 6 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.

the class FetchNativeContactsTest method testRunConflictTests.

@MediumTest
@Suppress
public // Breaks tests.
void testRunConflictTests() {
    final String fnName = "testRunConflictTests";
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
    mTestStep = 1;
    startSubTest(fnName, "Checking people database is empty");
    Cursor peopleCursor = mDb.openContactSummaryCursor(null, null);
    assertEquals(0, peopleCursor.getCount());
    assertTrue(Settings.ENABLE_UPDATE_NATIVE_CONTACTS);
    startSubTest(fnName, "Checking native database is empty");
    Cursor nativeCursor = mCr.query(People.CONTENT_URI, new String[] { People._ID, People.NAME, People.NOTES }, null, null, null);
    assertEquals(0, nativeCursor.getCount());
    startSubTest(fnName, "Add one dummy native contact");
    ContentValues peopleValues = new ContentValues();
    peopleValues.put(Contacts.People.NAME, ADD_CONTACT_TEST_NAME);
    peopleValues.put(Contacts.People.NOTES, ADD_CONTACT_TEST_NOTE);
    Uri personUri1 = mCr.insert(Contacts.People.CONTENT_URI, peopleValues);
    assertTrue("Unable to insert contact into native people table", personUri1 != null);
    final long personId = ContentUris.parseId(personUri1);
    ContentValues phoneValues = new ContentValues();
    phoneValues.put(Contacts.Phones.PERSON_ID, personId);
    phoneValues.put(Contacts.Phones.NUMBER, ADD_PHONE_TEST1);
    phoneValues.put(Contacts.Phones.TYPE, ADD_PHONE_TYPE_TEST1);
    Uri phoneUri1 = mCr.insert(Contacts.Phones.CONTENT_URI, phoneValues);
    assertTrue("Unable to insert contact into native phone table 1", phoneUri1 != null);
    final long phoneId1 = (int) ContentUris.parseId(phoneUri1);
    phoneValues.put(Contacts.Phones.NUMBER, ADD_PHONE_TEST2);
    phoneValues.put(Contacts.Phones.TYPE, ADD_PHONE_TYPE_TEST2);
    phoneValues.put(Contacts.Phones.ISPRIMARY, 1);
    Uri phoneUri2 = mCr.insert(Contacts.Phones.CONTENT_URI, phoneValues);
    assertTrue("Unable to insert contact into native phone table 2", phoneUri2 != null);
    final long phoneId2 = ContentUris.parseId(phoneUri2);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking contact has been synced to people");
    peopleCursor.requery();
    assertEquals(1, peopleCursor.getCount());
    assertTrue(peopleCursor.moveToFirst());
    ContactSummary summary = ContactSummaryTable.getQueryData(peopleCursor);
    assertTrue(summary != null);
    Contact orgContact = new Contact();
    ServiceStatus status = mDb.fetchContact(summary.localContactID, orgContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Modifying phone detail in people and native");
    phoneValues.clear();
    phoneValues.put(Contacts.Phones.NUMBER, MODIFY_PHONE_TEST1);
    int rowsUpdated = mCr.update(phoneUri1, phoneValues, null, null);
    assertEquals(1, rowsUpdated);
    boolean donePhone1 = false;
    for (ContactDetail detail : orgContact.details) {
        if (detail.key == ContactDetail.DetailKeys.VCARD_PHONE && detail.nativeDetailId.longValue() == phoneId1) {
            detail.setTel(MODIFY_PHONE_TEST2, MODIFY_PHONE_PEOPLE_TYPE_TEST2);
            status = mDb.modifyContactDetail(detail);
            assertEquals(ServiceStatus.SUCCESS, status);
            donePhone1 = true;
            break;
        }
    }
    assertTrue("Phone was not synced", donePhone1);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking contact has not been changed");
    peopleCursor.requery();
    assertEquals(1, peopleCursor.getCount());
    assertTrue(peopleCursor.moveToFirst());
    summary = ContactSummaryTable.getQueryData(peopleCursor);
    assertTrue(summary != null);
    Contact newContact = new Contact();
    status = mDb.fetchContact(summary.localContactID, newContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    donePhone1 = false;
    boolean donePhone2 = false;
    for (ContactDetail detail : newContact.details) {
        if (detail.key == ContactDetail.DetailKeys.VCARD_PHONE) {
            if (detail.nativeDetailId.longValue() == phoneId1) {
                assertEquals(MODIFY_PHONE_TEST2, detail.getTel());
                assertEquals(MODIFY_PHONE_PEOPLE_TYPE_TEST2, detail.keyType);
                donePhone1 = true;
            } else {
                mDb.deleteContactDetail(detail.localDetailID);
                donePhone2 = true;
            }
        }
    }
    assertTrue("Phone detail 1 is now missing", donePhone1);
    assertTrue("Phone detail 2 is now missing", donePhone2);
    startSubTest(fnName, "Modifying phone detail in native when it has been deleted in people");
    phoneValues.clear();
    phoneValues.put(Contacts.Phones.NUMBER, MODIFY_PHONE_TEST1);
    rowsUpdated = mCr.update(phoneUri2, phoneValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking contact has not been changed");
    peopleCursor.requery();
    assertEquals(1, peopleCursor.getCount());
    assertTrue(peopleCursor.moveToFirst());
    summary = ContactSummaryTable.getQueryData(peopleCursor);
    assertTrue(summary != null);
    newContact = new Contact();
    status = mDb.fetchContact(summary.localContactID, newContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    donePhone2 = false;
    for (ContactDetail detail : newContact.details) {
        if (detail.key == ContactDetail.DetailKeys.VCARD_PHONE && detail.nativeDetailId.longValue() == phoneId2) {
            assertEquals(ADD_PHONE_TEST2, detail.getTel());
            assertEquals(ADD_PHONE_PEOPLE_TYPE_TEST2, detail.keyType);
            donePhone2 = true;
            break;
        }
    }
    startSubTest(fnName, "Deleting contact in people");
    status = mDb.deleteContact(summary.localContactID);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Checking people contact list is empty");
    peopleCursor.requery();
    assertEquals(0, peopleCursor.getCount());
    startSubTest(fnName, "Try adding detail in native");
    ContentValues cmValues = new ContentValues();
    cmValues.put(Contacts.ContactMethods.PERSON_ID, personId);
    cmValues.put(Contacts.ContactMethods.DATA, ADD_CM_TEST1);
    cmValues.put(Contacts.ContactMethods.TYPE, ADD_CM_TYPE_TEST1);
    cmValues.put(Contacts.ContactMethods.KIND, ADD_CM_KIND_TEST1);
    Uri cmUri1 = mCr.insert(Contacts.ContactMethods.CONTENT_URI, cmValues);
    assertTrue("Unable to insert contact into native contact methods table 1", cmUri1 != null);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking people contact list is still empty");
    peopleCursor.requery();
    assertEquals(0, peopleCursor.getCount());
    startSubTest(fnName, "Try modifying detail in native");
    phoneValues.clear();
    phoneValues.put(Contacts.Phones.NUMBER, MODIFY_PHONE_TEST1);
    rowsUpdated = mCr.update(phoneUri2, phoneValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking people contact list is still empty");
    peopleCursor.requery();
    assertEquals(0, peopleCursor.getCount());
    startSubTest(fnName, "Try deleting detail in native");
    rowsUpdated = mCr.delete(phoneUri1, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking people contact list is still empty");
    peopleCursor.requery();
    assertEquals(0, peopleCursor.getCount());
    nativeCursor.close();
    peopleCursor.close();
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContentValues(android.content.ContentValues) ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactSummary(com.vodafone360.people.datatypes.ContactSummary) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Cursor(android.database.Cursor) Uri(android.net.Uri) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 7 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.

the class FetchNativeContactsTest method testRunWithOneModifiedContact.

@MediumTest
@Suppress
public // Breaks tests.
void testRunWithOneModifiedContact() {
    final String fnName = "testRunWithOneModifiedContact";
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
    mTestStep = 1;
    startSubTest(fnName, "Checking people database is empty");
    Cursor peopleCursor = mDb.openContactSummaryCursor(null, null);
    assertEquals(0, peopleCursor.getCount());
    assertTrue(Settings.ENABLE_UPDATE_NATIVE_CONTACTS);
    startSubTest(fnName, "Checking native database is empty");
    Cursor nativeCursor = mCr.query(People.CONTENT_URI, new String[] { People._ID, People.NAME, People.NOTES }, null, null, null);
    assertEquals(0, nativeCursor.getCount());
    startSubTest(fnName, "Add one dummy native contact");
    ContentValues peopleValues = new ContentValues();
    peopleValues.put(Contacts.People.NAME, ADD_CONTACT_TEST_NAME);
    peopleValues.put(Contacts.People.NOTES, ADD_CONTACT_TEST_NOTE);
    Uri personUri1 = mCr.insert(Contacts.People.CONTENT_URI, peopleValues);
    assertTrue("Unable to insert contact into native people table", personUri1 != null);
    final long personId = ContentUris.parseId(personUri1);
    ContentValues phoneValues = new ContentValues();
    phoneValues.put(Contacts.Phones.PERSON_ID, personId);
    phoneValues.put(Contacts.Phones.NUMBER, ADD_PHONE_TEST1);
    phoneValues.put(Contacts.Phones.TYPE, ADD_PHONE_TYPE_TEST1);
    Uri phoneUri1 = mCr.insert(Contacts.Phones.CONTENT_URI, phoneValues);
    assertTrue("Unable to insert contact into native phone table 1", phoneUri1 != null);
    final long phoneId1 = (int) ContentUris.parseId(phoneUri1);
    ContentValues cmValues = new ContentValues();
    cmValues.put(Contacts.ContactMethods.PERSON_ID, personId);
    cmValues.put(Contacts.ContactMethods.DATA, ADD_CM_TEST1);
    cmValues.put(Contacts.ContactMethods.TYPE, ADD_CM_TYPE_TEST1);
    cmValues.put(Contacts.ContactMethods.KIND, ADD_CM_KIND_TEST1);
    cmValues.put(Contacts.ContactMethods.ISPRIMARY, 1);
    Uri cmUri1 = mCr.insert(Contacts.ContactMethods.CONTENT_URI, cmValues);
    assertTrue("Unable to insert contact into native contact methods table 1", cmUri1 != null);
    final long cmId1 = ContentUris.parseId(cmUri1);
    ContentValues orgValues = new ContentValues();
    orgValues.put(Contacts.Organizations.PERSON_ID, personId);
    orgValues.put(Contacts.Organizations.COMPANY, ADD_ORG_COMPANY_TEST1);
    orgValues.put(Contacts.Organizations.TITLE, ADD_ORG_TITLE_TEST1);
    orgValues.put(Contacts.Organizations.TYPE, ADD_ORG_TYPE_TEST1);
    orgValues.put(Contacts.Organizations.LABEL, ADD_ORG_LABEL_TEST1);
    Uri orgUri = mCr.insert(Contacts.Organizations.CONTENT_URI, orgValues);
    assertTrue("Unable to insert contact into native organizations table 1", orgUri != null);
    final long orgId1 = ContentUris.parseId(orgUri);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking contact has been synced to people");
    peopleCursor.requery();
    assertEquals(1, peopleCursor.getCount());
    startSubTest(fnName, "Modifying name");
    peopleValues.clear();
    peopleValues.put(Contacts.People.NAME, MODIFY_CONTACT_TEST_NAME);
    int rowsUpdated = mCr.update(personUri1, peopleValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Modifying phone number");
    phoneValues.clear();
    phoneValues.put(Contacts.Phones.NUMBER, MODIFY_PHONE_TEST1);
    rowsUpdated = mCr.update(phoneUri1, phoneValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Modifying email address");
    cmValues.clear();
    cmValues.put(Contacts.ContactMethods.DATA, MODIFY_EMAIL_TEST1);
    rowsUpdated = mCr.update(cmUri1, cmValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Modifying organization");
    orgValues.clear();
    orgValues.put(Contacts.Organizations.COMPANY, MODIFY_COMPANY_TEST1);
    rowsUpdated = mCr.update(orgUri, orgValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Adding phone number");
    phoneValues.clear();
    phoneValues.put(Contacts.Phones.PERSON_ID, personId);
    phoneValues.put(Contacts.Phones.NUMBER, MODIFY_PHONE_TEST2);
    phoneValues.put(Contacts.Phones.TYPE, MODIFY_PHONE_TYPE_TEST2);
    phoneValues.put(Contacts.Phones.ISPRIMARY, 1);
    Uri phoneUri2 = mCr.insert(Contacts.Phones.CONTENT_URI, phoneValues);
    assertTrue("Unable to insert contact into native phone table 2", phoneUri2 != null);
    final long phoneId2 = (int) ContentUris.parseId(phoneUri2);
    startSubTest(fnName, "Adding email address");
    cmValues.clear();
    cmValues.put(Contacts.ContactMethods.PERSON_ID, personId);
    cmValues.put(Contacts.ContactMethods.DATA, MODIFY_EMAIL_TEST2);
    cmValues.put(Contacts.ContactMethods.TYPE, MODIFY_EMAIL_TYPE_TEST2);
    cmValues.put(Contacts.ContactMethods.KIND, MODIFY_EMAIL_KIND_TEST2);
    Uri cmUri2 = mCr.insert(Contacts.ContactMethods.CONTENT_URI, cmValues);
    assertTrue("Unable to insert contact into native contact methods table 1", cmUri2 != null);
    final long cmId2 = (int) ContentUris.parseId(cmUri2);
    startSubTest(fnName, "Adding organization");
    orgValues.clear();
    orgValues.put(Contacts.Organizations.PERSON_ID, personId);
    orgValues.put(Contacts.Organizations.COMPANY, MODIFY_COMPANY_TEST2);
    orgValues.put(Contacts.Organizations.TITLE, MODIFY_TITLE_TEST2);
    orgValues.put(Contacts.Organizations.TYPE, MODIFY_COMPANY_TYPE_TEST2);
    orgValues.put(Contacts.Organizations.ISPRIMARY, 1);
    Uri orgUri2 = mCr.insert(Contacts.Organizations.CONTENT_URI, orgValues);
    assertTrue("Unable to insert contact into native contact methods table 1", orgUri2 != null);
    final long orgId2 = (int) ContentUris.parseId(orgUri2);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking still 1 contact");
    peopleCursor.requery();
    assertEquals(1, peopleCursor.getCount());
    assertTrue(peopleCursor.moveToFirst());
    ContactSummary summary = ContactSummaryTable.getQueryData(peopleCursor);
    assertTrue(summary != null);
    Contact newContact = new Contact();
    ServiceStatus status = mDb.fetchContact(summary.localContactID, newContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    boolean doneName = false;
    boolean doneNickname = false;
    boolean doneNote = false;
    boolean donePhone1 = false;
    boolean donePhone2 = false;
    boolean doneCm1 = false;
    boolean doneCm2 = false;
    boolean doneOrg1 = false;
    boolean doneOrg2 = false;
    boolean doneTitle1 = false;
    boolean doneTitle2 = false;
    assertTrue(newContact.synctophone);
    assertEquals(personId, newContact.nativeContactId.longValue());
    assertEquals(personId, summary.nativeContactId.longValue());
    for (ContactDetail detail : newContact.details) {
        assertEquals(Integer.valueOf((int) personId), detail.nativeContactId);
        detail.syncNativeContactId = fetchSyncNativeId(detail.localDetailID);
        assertEquals("No sync marker, ID = " + detail.nativeDetailId + ", key = " + detail.key, Integer.valueOf(-1), detail.syncNativeContactId);
        Integer detailId = detail.nativeDetailId;
        assertTrue(detailId != null);
        switch(detail.key) {
            case VCARD_NAME:
                assertEquals(personId, detailId.longValue());
                assertEquals(MODIFY_CONTACT_TEST_NAME, detail.nativeVal1);
                VCardHelper.Name name = detail.getName();
                assertTrue(name != null);
                assertEquals(MODIFY_CONTACT_TEST_NAME, name.toString());
                doneName = true;
                break;
            case VCARD_NICKNAME:
                assertEquals(personId, detailId.longValue());
                assertEquals(MODIFY_CONTACT_TEST_NAME, detail.nativeVal1);
                assertEquals(MODIFY_CONTACT_TEST_NAME, detail.getValue());
                doneNickname = true;
                break;
            case VCARD_NOTE:
                assertEquals(personId, detailId.longValue());
                assertEquals(ADD_CONTACT_TEST_NOTE, detail.nativeVal1);
                assertEquals(ADD_CONTACT_TEST_NOTE, detail.getValue());
                doneNote = true;
                break;
            case VCARD_PHONE:
                if (detailId.longValue() == phoneId1) {
                    donePhone1 = true;
                    assertEquals(MODIFY_PHONE_TEST1, detail.nativeVal1);
                    assertEquals(MODIFY_PHONE_TEST1, detail.getValue());
                    assertEquals(ADD_PHONE_PEOPLE_TYPE_TEST1, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_NORMAL), detail.order);
                } else if (detailId.longValue() == phoneId2) {
                    donePhone2 = true;
                    assertEquals(MODIFY_PHONE_TEST2, detail.nativeVal1);
                    assertEquals(MODIFY_PHONE_TEST2, detail.getValue());
                    assertEquals(MODIFY_PHONE_PEOPLE_TYPE_TEST2, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_PREFERRED), detail.order);
                } else {
                    fail("Unknown phone number in people contact: ID:" + detailId + " does not match " + phoneId1 + "," + phoneId2);
                }
                break;
            case VCARD_EMAIL:
                assertTrue(detailId != null);
                if (detailId.longValue() == cmId1) {
                    doneCm1 = true;
                    assertEquals(MODIFY_EMAIL_TEST1, detail.nativeVal1);
                    assertEquals(MODIFY_EMAIL_TEST1, detail.getValue());
                    assertEquals(String.valueOf(ADD_CM_TYPE_TEST1), detail.nativeVal2);
                    assertEquals(String.valueOf(ADD_CM_KIND_TEST1), detail.nativeVal3);
                    assertEquals(ADD_CM_PEOPLE_TYPE_TEST1, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_PREFERRED), detail.order);
                } else if (detailId.longValue() == cmId2) {
                    doneCm2 = true;
                    assertEquals(MODIFY_EMAIL_TEST2, detail.nativeVal1);
                    assertEquals(MODIFY_EMAIL_TEST2, detail.getValue());
                    assertEquals(String.valueOf(MODIFY_EMAIL_KIND_TEST2), detail.nativeVal2);
                    assertEquals(String.valueOf(MODIFY_EMAIL_TYPE_TEST2), detail.nativeVal3);
                    assertEquals(MODIFY_EMAIL_PEOPLE_TYPE_TEST2, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_NORMAL), detail.order);
                } else {
                    fail("Unknown email in people contact: ID:" + detailId + " does not match " + phoneId1 + "," + phoneId2);
                }
                break;
            case VCARD_ORG:
                assertTrue(detailId != null);
                if (detailId.longValue() == orgId1) {
                    doneOrg1 = true;
                    assertEquals(MODIFY_COMPANY_TEST1, detail.nativeVal1);
                    assertEquals(String.valueOf(ADD_ORG_TYPE_TEST1), detail.nativeVal3);
                    VCardHelper.Organisation org = detail.getOrg();
                    assertTrue(org != null);
                    assertEquals(0, org.unitNames.size());
                    assertEquals(MODIFY_COMPANY_TEST1, org.name);
                    assertEquals(ADD_ORG_PEOPLE_TYPE_TEST1, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_NORMAL), detail.order);
                } else if (detailId.longValue() == orgId2) {
                    doneOrg2 = true;
                    assertEquals(MODIFY_COMPANY_TEST2, detail.nativeVal1);
                    assertEquals(String.valueOf(MODIFY_COMPANY_TYPE_TEST2), detail.nativeVal3);
                    VCardHelper.Organisation org = detail.getOrg();
                    assertTrue(org != null);
                    assertEquals(0, org.unitNames.size());
                    assertEquals(MODIFY_COMPANY_TEST2, org.name);
                    assertEquals(MODIFY_COMPANY_PEOPLE_TYPE_TEST2, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_PREFERRED), detail.order);
                } else {
                    fail("Unknown organisation in people contact");
                }
                break;
            case VCARD_TITLE:
                assertTrue(detailId != null);
                if (detailId.longValue() == orgId1) {
                    doneTitle1 = true;
                    assertEquals(ADD_ORG_TITLE_TEST1, detail.nativeVal1);
                    assertEquals(ADD_ORG_TITLE_TEST1, detail.getValue());
                } else if (detailId.longValue() == orgId2) {
                    doneTitle2 = true;
                    assertEquals(MODIFY_TITLE_TEST2, detail.nativeVal1);
                    assertEquals(MODIFY_TITLE_TEST2, detail.getValue());
                } else {
                    fail("Unknown title in people contact");
                }
                break;
            default:
                fail("Unexpected detail in people contact: " + detail.key);
        }
    }
    assertTrue("Name was missing", doneName);
    assertTrue("Nickname was missing", doneNickname);
    assertTrue("Note was missing", doneNote);
    assertTrue("Phone1 was missing", donePhone1);
    assertTrue("Phone2 was missing", donePhone2);
    assertTrue("Email1 was missing", doneCm1);
    assertTrue("Email2 was missing", doneCm2);
    assertTrue("Organisation1 was missing", doneOrg1);
    assertTrue("Organisation2 was missing", doneOrg2);
    assertTrue("Title1 was missing", doneTitle1);
    assertTrue("Title2 was missing", doneTitle2);
    nativeCursor.close();
    peopleCursor.close();
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContentValues(android.content.ContentValues) ContactSummary(com.vodafone360.people.datatypes.ContactSummary) Cursor(android.database.Cursor) Uri(android.net.Uri) Contact(com.vodafone360.people.datatypes.Contact) ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 8 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.

the class FetchNativeContactsTest method checkContacts.

private void checkContacts(List<NativeContactDetails> nativeContactList) {
    for (int i = 0; i < nativeContactList.size(); i++) {
        NativeContactDetails ncd = nativeContactList.get(i);
        ContactIdInfo info = ContactsTable.fetchContactIdFromNative(ncd.mId, mDb.getReadableDatabase());
        Contact contact = new Contact();
        ServiceStatus status = mDb.fetchContact(info.localId, contact);
        assertEquals(ServiceStatus.SUCCESS, status);
        LogUtils.logI("Checking contact local ID " + info.localId + ", native ID " + ncd.mId);
        boolean nameDone = false;
        boolean nicknameDone = false;
        boolean noteDone = false;
        int phonesDone = 0;
        int emailsDone = 0;
        int addressesDone = 0;
        int orgsDone = 0;
        int titlesDone = 0;
        for (ContactDetail detail : contact.details) {
            assertEquals(ncd.mId, detail.nativeContactId);
            detail.syncNativeContactId = fetchSyncNativeId(detail.localDetailID);
            assertEquals("No sync marker, ID = " + detail.nativeDetailId + ", key = " + detail.key, Integer.valueOf(-1), detail.syncNativeContactId);
            switch(detail.key) {
                case VCARD_NAME:
                    nameDone = true;
                    assertEquals(ncd.mName.toString(), detail.nativeVal1);
                    break;
                case VCARD_NICKNAME:
                    nicknameDone = true;
                    assertEquals(ncd.mName.toString(), detail.nativeVal1);
                    break;
                case VCARD_NOTE:
                    noteDone = true;
                    assertEquals(ncd.mNote, detail.nativeVal1);
                    break;
                case VCARD_PHONE:
                    phonesDone++;
                    for (NativeDetail nd : ncd.mPhoneList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                case VCARD_EMAIL:
                    emailsDone++;
                    for (NativeDetail nd : ncd.mEmailList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                case VCARD_ADDRESS:
                    addressesDone++;
                    for (NativeDetail nd : ncd.mAddressList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                case VCARD_ORG:
                    orgsDone++;
                    for (NativeDetail nd : ncd.mOrgList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                case VCARD_TITLE:
                    titlesDone++;
                    for (NativeDetail nd : ncd.mTitleList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                default:
                    fail("Unexpected detail: " + detail.key);
            }
        }
        String nameString = ncd.mName.toString();
        if (nameString.length() > 0) {
            assertTrue("Name was not done", nameDone);
            assertTrue("Nickname was not done", nicknameDone);
        }
        if (ncd.mNote != null && ncd.mNote.length() > 0) {
            assertTrue("Note was not done", noteDone);
        }
        assertEquals(ncd.mPhoneList.size(), phonesDone);
        assertEquals(ncd.mEmailList.size(), emailsDone);
        assertEquals(ncd.mAddressList.size(), addressesDone);
        assertEquals(ncd.mOrgList.size(), orgsDone);
        assertEquals(ncd.mTitleList.size(), titlesDone);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) NativeContactDetails(com.vodafone360.people.tests.TestModule.NativeContactDetails) ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) ServiceStatus(com.vodafone360.people.service.ServiceStatus) NativeDetail(com.vodafone360.people.tests.TestModule.NativeDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 9 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.

the class NowPlusDatatypesTests method testUserProfile.

public void testUserProfile() {
    UserProfile input = new UserProfile();
    input.userID = 50L;
    input.aboutMe = "newAboutMe";
    input.contactID = 10L;
    input.gender = 1;
    input.profilePath = "foo";
    input.updated = 2L;
    ContactDetail contactDetail = new ContactDetail();
    contactDetail.value = "00000000";
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    hash.put("userid", input.userID);
    hash.put("aboutme", input.aboutMe);
    hash.put("contactid", input.contactID);
    hash.put("gender", input.gender);
    hash.put("profilepath", input.profilePath);
    hash.put("updated", input.updated);
    UserProfile output = UserProfile.createFromHashtable(hash);
    assertEquals(BaseDataType.USER_PROFILE_DATA_TYPE, output.getType());
    assertEquals(input.toString(), output.toString());
    assertEquals(input.userID, output.userID);
    assertEquals(input.aboutMe, output.aboutMe);
    assertEquals(input.contactID, output.contactID);
    assertEquals(input.gender, output.gender);
    assertEquals(input.profilePath, output.profilePath);
    assertEquals(input.updated, output.updated);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) UserProfile(com.vodafone360.people.datatypes.UserProfile) Hashtable(java.util.Hashtable)

Example 10 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.

the class UploadServerContactsTest method reportDeleteContactDetailSuccess.

private void reportDeleteContactDetailSuccess(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportDeleteContactDetailSuccess");
    mProcessor.verifyDeleteDetailsState();
    Contact contact = new Contact();
    mProcessor.testFetchContactDetailDeleteList(contact);
    assertEquals(2, contact.details.size());
    assertEquals(ContactDetail.DetailKeys.VCARD_NAME, contact.details.get(0).key);
    assertEquals(ContactDetail.DetailKeys.VCARD_PHONE, contact.details.get(1).key);
    ContactDetailDeletion contactDetailDeletion = new ContactDetailDeletion();
    contactDetailDeletion.mServerVersionAfter = 1;
    contactDetailDeletion.mServerVersionBefore = 0;
    data.add(contactDetailDeletion);
    contactDetailDeletion.mContactId = contact.contactID.intValue();
    contactDetailDeletion.mDetails = new ArrayList<ContactDetail>();
    for (ContactDetail detail : contact.details) {
        ContactDetail tempDetail = new ContactDetail();
        tempDetail.key = detail.key;
        tempDetail.unique_id = detail.unique_id;
        contactDetailDeletion.mDetails.add(tempDetail);
    }
    mItemCount--;
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        nextState(State.IDLE);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactDetailDeletion(com.vodafone360.people.datatypes.ContactDetailDeletion) Contact(com.vodafone360.people.datatypes.Contact)

Aggregations

ContactDetail (com.vodafone360.people.datatypes.ContactDetail)109 Contact (com.vodafone360.people.datatypes.Contact)60 ServiceStatus (com.vodafone360.people.service.ServiceStatus)57 ArrayList (java.util.ArrayList)33 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 MediumTest (android.test.suitebuilder.annotation.MediumTest)24 Cursor (android.database.Cursor)20 Suppress (android.test.suitebuilder.annotation.Suppress)16 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)15 ContentValues (android.content.ContentValues)11 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)10 SQLException (android.database.SQLException)8 Uri (android.net.Uri)7 SQLiteException (android.database.sqlite.SQLiteException)6 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)6 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)6 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)4 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)4 Date (java.util.Date)4