Search in sources :

Example 76 with ContactDetail

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

the class DownloadServerContactsTest method testRunBulkTest.

@LargeTest
@Suppress
public // Breaks tests.
void testRunBulkTest() {
    final String fnName = "testRunBulkTest";
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
    mTestStep = 1;
    startSubTest(fnName, "Checking database is empty");
    Cursor cursor = mDb.openContactSummaryCursor(null, null);
    assertEquals(0, cursor.getCount());
    startSubTest(fnName, "Running processor");
    runProcessor(BULK_TEST_NO_CONTACTS, State.RUN_WITH_NEW_CONTACTS);
    startSubTest(fnName, "Checking database now has " + BULK_TEST_NO_CONTACTS + " contacts");
    cursor.requery();
    assertEquals(BULK_TEST_NO_CONTACTS, cursor.getCount());
    int[] detailsCountArray = new int[BULK_TEST_NO_CONTACTS];
    while (cursor.moveToNext()) {
        ContactSummary summary = ContactSummaryTable.getQueryData(cursor);
        Contact contact = new Contact();
        ServiceStatus status = mDb.fetchContact(summary.localContactID, contact);
        assertEquals(ServiceStatus.SUCCESS, status);
        int idx = (int) (contact.contactID - FIRST_MODIFIED_CONTACT_ID);
        Long userId = generateTestUserID(contact.contactID);
        assertTrue(contact.contactID != null);
        assertEquals(userId, contact.userID);
        detailsCountArray[idx] = contact.details.size();
        Log.d(LOG_TAG, "Org Contact " + contact.contactID + " has " + contact.details.size() + " details");
        for (ContactDetail detail : contact.details) {
            Log.d(LOG_TAG, "	Detail " + detail.key + ", unique_id=" + detail.unique_id + ", value=" + detail.value);
        }
    }
    assertEquals(State.IDLE, mState);
    startSubTest(fnName, "Running processor");
    runProcessor(BULK_TEST_NO_CONTACTS, State.RUN_WITH_MODIFIED_CONTACTS);
    assertEquals(State.IDLE, mState);
    cursor.requery();
    cursor.moveToPosition(-1);
    while (cursor.moveToNext()) {
        ContactSummary summary = ContactSummaryTable.getQueryData(cursor);
        Contact contact = new Contact();
        ServiceStatus status = mDb.fetchContact(summary.localContactID, contact);
        assertEquals(ServiceStatus.SUCCESS, status);
        int idx = (int) (contact.contactID - FIRST_MODIFIED_CONTACT_ID);
        assertEquals(detailsCountArray[idx] + 2, contact.details.size());
        int currentVal = (int) (contact.contactID - FIRST_MODIFIED_CONTACT_ID);
        boolean foundModNickname = false;
        boolean foundModPhone = false;
        boolean foundNewPhone = false;
        boolean foundNewEmail = false;
        for (ContactDetail detail : contact.details) {
            switch(detail.key) {
                case VCARD_NICKNAME:
                    assertEquals(generateModifiedString(MODIFIED_NICKNAME_STRING, currentVal), detail.value);
                    foundModNickname = true;
                    break;
                case VCARD_PHONE:
                    if (detail.unique_id != null && detail.unique_id.longValue() == OLD_PHONE_DETAIL_ID + currentVal) {
                        assertEquals(generateModifiedString(MODIFIED_PHONE_STRING, currentVal), detail.value);
                        assertEquals(MODIFIED_PHONE_TYPE, detail.keyType);
                        assertEquals(MODIFIED_PHONE_ORDER, detail.order);
                        foundModPhone = true;
                    } else if (detail.unique_id != null && detail.unique_id.longValue() == NEW_PHONE_DETAIL_ID + currentVal) {
                        assertEquals(generateModifiedString(NEW_PHONE_STRING, currentVal), detail.value);
                        assertEquals(NEW_PHONE_TYPE, detail.keyType);
                        assertEquals(NEW_PHONE_ORDER, detail.order);
                        assertEquals(Long.valueOf(NEW_PHONE_DETAIL_ID + currentVal), detail.unique_id);
                        foundNewPhone = true;
                    }
                    break;
                case VCARD_EMAIL:
                    if (detail.unique_id != null && detail.unique_id.longValue() == NEW_EMAIL_DETAIL_ID + currentVal) {
                        assertEquals(generateModifiedString(NEW_EMAIL_STRING, currentVal), detail.value);
                        assertEquals(NEW_EMAIL_TYPE, detail.keyType);
                        assertEquals(NEW_EMAIL_ORDER, detail.order);
                        foundNewEmail = true;
                    }
                    break;
            }
        }
        assertTrue(foundModNickname);
        assertTrue(foundModPhone);
        assertTrue(foundNewPhone);
        assertTrue(foundNewEmail);
    }
    startSubTest(fnName, "Running processor");
    runProcessor(BULK_TEST_NO_CONTACTS, State.RUN_WITH_DELETED_DETAILS);
    assertEquals(State.IDLE, mState);
    cursor.requery();
    cursor.moveToPosition(-1);
    while (cursor.moveToNext()) {
        ContactSummary summary = ContactSummaryTable.getQueryData(cursor);
        Contact contact = new Contact();
        ServiceStatus status = mDb.fetchContact(summary.localContactID, contact);
        assertEquals(ServiceStatus.SUCCESS, status);
        int idx = (int) (contact.contactID - FIRST_MODIFIED_CONTACT_ID);
        Log.d(LOG_TAG, "Del Contact " + contact.contactID + " has " + contact.details.size() + " details");
        for (ContactDetail detail : contact.details) {
            Log.d(LOG_TAG, "	Detail " + detail.key + ", unique_id=" + detail.unique_id + ", value=" + detail.value);
        }
        assertEquals(detailsCountArray[idx] - 1, contact.details.size());
    }
    startSubTest(fnName, "Running processor");
    runProcessor(BULK_TEST_NO_CONTACTS, State.RUN_WITH_DELETED_CONTACTS);
    assertEquals(State.IDLE, mState);
    cursor.requery();
    assertEquals(0, cursor.getCount());
    cursor.close();
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactSummary(com.vodafone360.people.datatypes.ContactSummary) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Cursor(android.database.Cursor) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 77 with ContactDetail

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

the class UploadServerContactsTest method testRunWithNewContactChange.

@MediumTest
@Suppress
public // Breaks tests
void testRunWithNewContactChange() {
    final String fnName = "testRunWithNewContactChange";
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
    mTestStep = 1;
    startSubTest(fnName, "Checking change list is empty");
    long noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    noOfChanges = ContactDetailsTable.syncNativeFetchNoOfChanges(mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    startSubTest(fnName, "Adding test contact to database");
    Contact contact = mTestModule.createDummyContactData();
    ServiceStatus status = mDb.addContact(contact);
    assertEquals(ServiceStatus.SUCCESS, status);
    mInitialContactGroupCount = contact.groupList.size();
    startSubTest(fnName, "Running processor");
    runProcessor(1, State.ADD_CONTACT_LIST);
    startSubTest(fnName, "Fetching contact after sync");
    Contact syncContact = mTestModule.createDummyContactData();
    status = mDb.fetchContact(contact.localContactID, syncContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Check contact server ID is correct");
    assertEquals(syncContact.contactID, mReplyContact.contactID);
    startSubTest(fnName, "Check detail server IDs are correct");
    final ListIterator<ContactDetail> itReplyDetails = mReplyContact.details.listIterator();
    for (ContactDetail syncDetail : syncContact.details) {
        ContactDetail replyDetail = itReplyDetails.next();
        assertEquals(replyDetail.key, syncDetail.key);
        assertEquals(replyDetail.unique_id, syncDetail.unique_id);
    }
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    noOfChanges = ContactDetailsTable.syncNativeFetchNoOfChanges(mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    assertEquals(State.IDLE, mState);
    startSubTest(fnName, "Running processor with no contact changes");
    runProcessor(0, State.IDLE);
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 78 with ContactDetail

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

the class UploadServerContactsTest method testRunWithDetailChanges.

@MediumTest
@Suppress
public // Breaks tests
void testRunWithDetailChanges() {
    final String fnName = "testRunWithDetailChanges";
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
    mTestStep = 1;
    startSubTest(fnName, "Checking change list is empty");
    long noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    noOfChanges = ContactDetailsTable.syncNativeFetchNoOfChanges(mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    startSubTest(fnName, "Adding test contact to database");
    Contact contact = mTestModule.createDummyContactData();
    contact.contactID = TestModule.generateRandomLong();
    contact.userID = generateTestUserID(contact.contactID);
    List<Contact> contactList = new ArrayList<Contact>();
    contactList.add(contact);
    ServiceStatus status = mDb.syncAddContactList(contactList, false, false);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Adding new detail to contact");
    ContactDetail newDetail = new ContactDetail();
    newDetail.value = NEW_DETAIL_VALUE;
    newDetail.key = NEW_DETAIL_KEY;
    newDetail.keyType = NEW_DETAIL_TYPE;
    newDetail.localContactID = contact.localContactID;
    status = mDb.addContactDetail(newDetail);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Modifying detail in contact");
    ContactDetail modDetail = contact.details.get(0);
    modDetail.value = MOD_DETAIL_VALUE;
    modDetail.key = MOD_DETAIL_KEY;
    modDetail.keyType = MOD_DETAIL_TYPE;
    status = mDb.modifyContactDetail(modDetail);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Running processor");
    runProcessor(1, State.MODIFY_CONTACT_LIST);
    startSubTest(fnName, "Fetching detail after sync");
    Contact syncContact = new Contact();
    status = mDb.fetchContact(contact.localContactID, syncContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Check contact server ID is correct");
    boolean done = false;
    for (ContactDetail detail : syncContact.details) {
        if (detail.localDetailID.equals(newDetail.localDetailID)) {
            assertEquals(detail.unique_id, Long.valueOf(detail.localDetailID + 2));
            done = true;
            break;
        }
    }
    assertTrue(done);
    assertEquals(syncContact.contactID, mReplyContact.contactID);
    assertEquals(syncContact.userID, mReplyContact.userID);
    assertEquals(State.IDLE, mState);
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    noOfChanges = ContactDetailsTable.syncNativeFetchNoOfChanges(mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    startSubTest(fnName, "Running processor with no contact changes");
    runProcessor(0, State.IDLE);
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 79 with ContactDetail

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

the class UploadServerContactsTest method reportModifyContactSuccess.

private void reportModifyContactSuccess(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportModifyContactSuccess");
    mProcessor.verifyModifyDetailsState();
    List<Contact> contactChangeList = new ArrayList<Contact>();
    mProcessor.testFetchContactChangeList(contactChangeList);
    assertEquals(Math.min(mItemCount, mProcessor.testGetPageSize()), contactChangeList.size());
    ContactChanges contactChanges = new ContactChanges();
    contactChanges.mServerRevisionAfter = 1;
    contactChanges.mServerRevisionBefore = 0;
    data.add(contactChanges);
    for (int i = 0; i < contactChangeList.size(); i++) {
        Contact actualContact = contactChangeList.get(i);
        assertTrue(actualContact.contactID != null);
        assertEquals(null, actualContact.aboutMe);
        assertEquals(null, actualContact.profilePath);
        assertEquals(null, actualContact.deleted);
        assertEquals(null, actualContact.friendOfMine);
        assertEquals(null, actualContact.gender);
        assertEquals(null, actualContact.groupList);
        assertEquals(null, actualContact.sources);
        assertEquals(null, actualContact.synctophone);
        assertEquals(null, actualContact.updated);
        assertEquals(null, actualContact.userID);
        assertEquals(2, actualContact.details.size());
        // Modified
        ContactDetail modDetail = actualContact.details.get(0);
        // detail
        // always
        // first
        ContactDetail newDetail = actualContact.details.get(1);
        assertEquals(NEW_DETAIL_VALUE, newDetail.value);
        assertEquals(NEW_DETAIL_KEY, newDetail.key);
        assertEquals(NEW_DETAIL_TYPE, newDetail.keyType);
        assertEquals(MOD_DETAIL_VALUE, modDetail.value);
        assertEquals(MOD_DETAIL_KEY, modDetail.key);
        assertEquals(MOD_DETAIL_TYPE, modDetail.keyType);
        mReplyContact = new Contact();
        mReplyContact.contactID = actualContact.contactID;
        mReplyContact.userID = generateTestUserID(mReplyContact.contactID);
        ContactDetail replyDetail1 = new ContactDetail();
        ContactDetail replyDetail2 = new ContactDetail();
        replyDetail1.key = modDetail.key;
        replyDetail1.unique_id = modDetail.unique_id;
        replyDetail2.key = newDetail.key;
        replyDetail2.unique_id = newDetail.localDetailID + 2;
        mReplyContact.details.add(replyDetail1);
        mReplyContact.details.add(replyDetail2);
        contactChanges.mContacts.add(mReplyContact);
    }
    mItemCount -= contactChangeList.size();
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        nextState(State.IDLE);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ArrayList(java.util.ArrayList) ContactChanges(com.vodafone360.people.datatypes.ContactChanges) Contact(com.vodafone360.people.datatypes.Contact)

Example 80 with ContactDetail

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

the class UploadServerContactsTest method testRunWithContactDetailDeletion.

@MediumTest
@Suppress
public // Breaks tests
void testRunWithContactDetailDeletion() {
    final String fnName = "testRunWithContactDetailDeletion";
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
    mTestStep = 1;
    startSubTest(fnName, "Checking change list is empty");
    long noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    noOfChanges = ContactDetailsTable.syncNativeFetchNoOfChanges(mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    startSubTest(fnName, "Adding test contact to database - no sync");
    Contact contact = mTestModule.createDummyContactData();
    contact.contactID = TestModule.generateRandomLong();
    contact.userID = generateTestUserID(contact.contactID);
    List<Contact> contactList = new ArrayList<Contact>();
    contactList.add(contact);
    ServiceStatus status = mDb.syncAddContactList(contactList, false, false);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Adding test contact detail to database - no sync");
    ContactDetail detail = new ContactDetail();
    detail.value = NEW_DETAIL_VALUE;
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.CELL;
    detail.localContactID = contact.localContactID;
    List<ContactDetail> contactDetailList = new ArrayList<ContactDetail>();
    contactDetailList.add(detail);
    status = mDb.syncAddContactDetailList(contactDetailList, false, false);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Deleting contact detail without unique ID");
    status = mDb.deleteContactDetail(contact.details.get(0).localDetailID);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Deleting contact detail with unique ID");
    status = mDb.deleteContactDetail(detail.localDetailID);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Running processor");
    runProcessor(1, State.DELETE_CONTACT_DETAIL_LIST);
    assertEquals(State.IDLE, mState);
    startSubTest(fnName, "Checking change list is empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    noOfChanges = ContactDetailsTable.syncNativeFetchNoOfChanges(mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    startSubTest(fnName, "Running processor with no contact changes");
    runProcessor(0, State.IDLE);
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

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