Search in sources :

Example 1 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class NowPlusDBHelperThumbnailTest method testDBHelperThumbnail.

@SmallTest
public void testDBHelperThumbnail() {
    assertTrue(initialise());
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
    Contact contact = mTestModule.createDummyContactData();
    status = mDatabaseHelper.addContact(contact);
    assertEquals(ServiceStatus.SUCCESS, status);
    Bitmap testBimap = Bitmap.createBitmap(createColors(), 0, STRIDE, WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
    ContactDetail cd = new ContactDetail();
    cd.localContactID = contact.localContactID;
    cd.photo = testBimap;
    status = mDatabaseHelper.addContactDetail(cd);
    status = ContactSummaryTable.modifyPictureLoadedFlag(contact.localContactID, false, mDatabaseHelper.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, status);
    int numOfThumbnails = mDatabaseHelper.fetchThumbnailUrlCount();
    assertEquals(1, numOfThumbnails);
    List<ThumbnailInfo> thumbInfoList = new ArrayList<ThumbnailInfo>();
    status = mDatabaseHelper.fetchThumbnailUrls(thumbInfoList, 0, 1);
    assertEquals(ServiceStatus.SUCCESS, status);
    shutdown();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Bitmap(android.graphics.Bitmap) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) ThumbnailInfo(com.vodafone360.people.database.DatabaseHelper.ThumbnailInfo) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 2 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class DownloadServerContactsTest method testRunWithOneNewContact.

@MediumTest
@Suppress
public // Breaks tests.
void testRunWithOneNewContact() {
    final String fnName = "testRunWithOneNewContact";
    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(1, State.RUN_WITH_NEW_CONTACTS);
    startSubTest(fnName, "Checking database now has one contact");
    cursor.requery();
    assertEquals(1, cursor.getCount());
    assertTrue(cursor.moveToNext());
    ContactSummary summary = ContactSummaryTable.getQueryData(cursor);
    Contact contact = new Contact();
    ServiceStatus status = mDb.fetchContact(summary.localContactID, contact);
    assertEquals(ServiceStatus.SUCCESS, status);
    Long userId = generateTestUserID(contact.contactID);
    assertTrue(contact.contactID != null);
    assertEquals(userId, contact.userID);
    assertTrue(mLastNewContact != null);
    assertTrue(TestModule.doContactsMatch(contact, mLastNewContact));
    assertTrue(TestModule.doContactsFieldsMatch(contact, mLastNewContact));
    assertEquals(State.IDLE, mState);
    cursor.close();
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : 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) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 3 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class DownloadServerContactsTest method testRunWithOneModifiedContact.

@MediumTest
@Suppress
public // Breaks tests.
void testRunWithOneModifiedContact() {
    final String fnName = "testRunWithOneModifiedContact";
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
    mTestStep = 1;
    startSubTest(fnName, "Checking database is empty");
    Cursor cursor = mDb.openContactSummaryCursor(null, null);
    assertEquals(0, cursor.getCount());
    Contact orgContact = mTestModule.createDummyContactData();
    orgContact.contactID = FIRST_MODIFIED_CONTACT_ID;
    for (int j = 0; j < orgContact.details.size(); j++) {
        ContactDetail detail = orgContact.details.get(j);
        switch(detail.key) {
            case VCARD_PHONE:
            case VCARD_EMAIL:
                detail.unique_id = ALT_PHONE_DETAIL_ID + j;
                break;
        }
    }
    ContactDetail detail1 = new ContactDetail();
    detail1.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail1.unique_id = OLD_PHONE_DETAIL_ID;
    detail1.value = OLD_PHONE_DETAIL_VALUE;
    orgContact.details.add(detail1);
    List<Contact> contactList = new ArrayList<Contact>();
    int originalNoOfDetails = orgContact.details.size();
    contactList.add(orgContact);
    ServiceStatus status = mDb.syncAddContactList(contactList, false, false);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Running processor");
    runProcessor(1, State.RUN_WITH_MODIFIED_CONTACTS);
    startSubTest(fnName, "Checking database still has one contact");
    cursor.requery();
    assertEquals(1, cursor.getCount());
    cursor.close();
    Contact modContact = new Contact();
    status = mDb.fetchContactByServerId(FIRST_MODIFIED_CONTACT_ID, modContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertEquals(originalNoOfDetails + 2, modContact.details.size());
    for (ContactDetail detail : modContact.details) {
        switch(detail.key) {
            case VCARD_NICKNAME:
                assertEquals(generateModifiedString(MODIFIED_NICKNAME_STRING, 0), detail.value);
                break;
            case VCARD_PHONE:
                if (detail.unique_id != null && detail.unique_id.equals(OLD_PHONE_DETAIL_ID)) {
                    assertEquals(generateModifiedString(MODIFIED_PHONE_STRING, 0), detail.value);
                    assertEquals(MODIFIED_PHONE_TYPE, detail.keyType);
                    assertEquals(MODIFIED_PHONE_ORDER, detail.order);
                } else if (detail.unique_id != null && detail.unique_id.equals(NEW_PHONE_DETAIL_ID)) {
                    assertEquals(generateModifiedString(NEW_PHONE_STRING, 0), detail.value);
                    assertEquals(NEW_PHONE_TYPE, detail.keyType);
                    assertEquals(NEW_PHONE_ORDER, detail.order);
                }
                break;
            case VCARD_EMAIL:
                if (detail.unique_id != null && detail.unique_id.equals(NEW_EMAIL_DETAIL_ID)) {
                    assertEquals(generateModifiedString(NEW_EMAIL_STRING, 0), detail.value);
                    assertEquals(NEW_EMAIL_TYPE, detail.keyType);
                    assertEquals(NEW_EMAIL_ORDER, detail.order);
                    assertEquals(NEW_EMAIL_DETAIL_ID, detail.unique_id);
                    break;
                }
            // Fall through
            default:
                boolean done = false;
                for (int j = 0; j < orgContact.details.size(); j++) {
                    if (orgContact.details.get(j).localDetailID.equals(detail.localDetailID)) {
                        assertTrue(DatabaseHelper.doDetailsMatch(orgContact.details.get(j), detail));
                        assertFalse(DatabaseHelper.hasDetailChanged(orgContact.details.get(j), detail));
                        done = true;
                        break;
                    }
                }
                assertTrue(done);
        }
    }
    assertEquals(State.IDLE, mState);
    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) Cursor(android.database.Cursor) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 4 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class DownloadServerContactsTest method testRunWithOneDeletedDetail.

@MediumTest
@Suppress
public // Breaks tests.
void testRunWithOneDeletedDetail() {
    final String fnName = "testRunWithOneDeletedDetail";
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
    mTestStep = 1;
    startSubTest(fnName, "Checking database is empty");
    Cursor cursor = mDb.openContactSummaryCursor(null, null);
    assertEquals(0, cursor.getCount());
    Contact orgContact = mTestModule.createDummyContactData();
    orgContact.contactID = FIRST_MODIFIED_CONTACT_ID;
    ContactDetail detail1 = new ContactDetail();
    detail1.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail1.keyType = NEW_EMAIL_TYPE;
    detail1.value = NEW_EMAIL_STRING;
    detail1.unique_id = NEW_EMAIL_DETAIL_ID;
    orgContact.details.add(detail1);
    ContactDetail detail2 = new ContactDetail();
    detail2.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail2.keyType = NEW_EMAIL_TYPE;
    detail2.value = DEL_EMAIL_STRING2;
    detail2.unique_id = NEW_EMAIL_DETAIL_ID + 1;
    orgContact.details.add(detail2);
    int originalNoOfDetails = orgContact.details.size();
    List<Contact> contactList = new ArrayList<Contact>();
    contactList.add(orgContact);
    ServiceStatus status = mDb.syncAddContactList(contactList, false, false);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Running processor");
    runProcessor(1, State.RUN_WITH_DELETED_DETAILS);
    startSubTest(fnName, "Checking database still has 1 contact");
    cursor.requery();
    assertEquals(1, cursor.getCount());
    cursor.close();
    Contact modContact = new Contact();
    status = mDb.fetchContactByServerId(FIRST_MODIFIED_CONTACT_ID, modContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertEquals(originalNoOfDetails - 3, modContact.details.size());
    for (ContactDetail detail : modContact.details) {
        switch(detail.key) {
            case VCARD_NAME:
            case VCARD_NICKNAME:
                fail("Unexpected detail after deletion: " + detail.key);
                break;
            case VCARD_EMAIL:
                if (detail.unique_id != null && detail.unique_id.equals(NEW_EMAIL_DETAIL_ID)) {
                    fail("Unexpected detail after deletion: " + detail.key);
                    break;
                }
            // Fall through
            default:
                boolean done = false;
                for (int j = 0; j < orgContact.details.size(); j++) {
                    if (orgContact.details.get(j).localDetailID.equals(detail.localDetailID)) {
                        assertTrue(DatabaseHelper.doDetailsMatch(orgContact.details.get(j), detail));
                        assertFalse(DatabaseHelper.hasDetailChanged(orgContact.details.get(j), detail));
                        done = true;
                        break;
                    }
                }
                assertTrue(done);
        }
    }
    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) Cursor(android.database.Cursor) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 5 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus 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)

Aggregations

ServiceStatus (com.vodafone360.people.service.ServiceStatus)190 Contact (com.vodafone360.people.datatypes.Contact)71 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)63 MediumTest (android.test.suitebuilder.annotation.MediumTest)62 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)43 ArrayList (java.util.ArrayList)43 Suppress (android.test.suitebuilder.annotation.Suppress)40 Cursor (android.database.Cursor)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)17 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)16 Bundle (android.os.Bundle)12 ContentValues (android.content.ContentValues)11 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)11 SQLException (android.database.SQLException)9 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)9 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)9 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)8 LoginDetails (com.vodafone360.people.datatypes.LoginDetails)8 PersistSettings (com.vodafone360.people.service.PersistSettings)8