Search in sources :

Example 21 with ServiceStatus

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

the class UploadServerContactsTest method reportBackAddContactSuccess.

private void reportBackAddContactSuccess(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportBackAddContactSuccess");
    mProcessor.verifyNewContactsState();
    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);
        Contact expectedContact = new Contact();
        ServiceStatus status = mDb.fetchContact(actualContact.localContactID, expectedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        assertEquals(expectedContact.details.size(), actualContact.details.size());
        assertEquals(null, actualContact.aboutMe);
        assertEquals(null, actualContact.profilePath);
        assertEquals(null, actualContact.contactID);
        assertEquals(null, actualContact.deleted);
        assertEquals(null, actualContact.friendOfMine);
        assertEquals(null, actualContact.gender);
        assertEquals(null, actualContact.groupList);
        assertEquals(null, actualContact.sources);
        assertEquals(expectedContact.synctophone, actualContact.synctophone);
        assertEquals(null, actualContact.updated);
        assertEquals(null, actualContact.userID);
        final ListIterator<ContactDetail> itActDetails = actualContact.details.listIterator();
        for (ContactDetail expDetail : expectedContact.details) {
            ContactDetail actDetail = itActDetails.next();
            assertTrue(DatabaseHelper.doDetailsMatch(expDetail, actDetail));
            assertFalse(DatabaseHelper.hasDetailChanged(expDetail, actDetail));
        }
        generateReplyContact(expectedContact);
        contactChanges.mContacts.add(mReplyContact);
    }
    mItemCount -= contactChangeList.size();
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        mInitialCount = mInitialContactGroupCount;
        nextState(State.ADD_NEW_GROUP_LIST);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) ContactChanges(com.vodafone360.people.datatypes.ContactChanges) Contact(com.vodafone360.people.datatypes.Contact)

Example 22 with ServiceStatus

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

the class UploadServerContactsTest method testRunWithManyContacts.

@LargeTest
@Suppress
public // Breaks tests
void testRunWithManyContacts() {
    final String fnName = "testRunWithManyContacts";
    mBulkContactTest = true;
    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 " + NO_OF_CONTACTS_TO_ADD + " test contact to database");
    mInitialContactGroupCount = 0;
    for (int i = 0; i < NO_OF_CONTACTS_TO_ADD; i++) {
        Contact contact = mTestModule.createDummyContactData();
        ServiceStatus status = mDb.addContact(contact);
        assertEquals(ServiceStatus.SUCCESS, status);
        mInitialContactGroupCount += contact.groupList.size();
        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);
    }
    Log.i(LOG_TAG, "Total number of groups = " + mItemCount + " out of " + NO_OF_CONTACTS_TO_ADD + " contacts");
    startSubTest(fnName, "Running processor");
    runProcessor(NO_OF_CONTACTS_TO_ADD, State.ADD_CONTACT_LIST);
    startSubTest(fnName, "Fetching contacts after sync");
    Cursor cursor = mDb.openContactSummaryCursor(null, null);
    assertTrue(cursor != null);
    while (cursor.moveToNext()) {
        ContactSummary summary = ContactSummaryTable.getQueryData(cursor);
        Contact testContact = new Contact();
        ServiceStatus status = mDb.fetchContact(summary.localContactID, testContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        assertEquals(Long.valueOf(summary.localContactID + 1), testContact.contactID);
        if ((testContact.localContactID & 15) != 0) {
            assertEquals(Long.valueOf(summary.localContactID + 2), testContact.userID);
        } else {
            assertEquals(null, testContact.userID);
        }
        for (ContactDetail detail : testContact.details) {
            ContactDetail replyDetail = new ContactDetail();
            generateReplyDetail(replyDetail, detail);
            assertEquals(replyDetail.unique_id, detail.unique_id);
            Long syncServerId = TestModule.fetchSyncServerId(detail.localDetailID, mDb.getReadableDatabase());
            assertEquals(Long.valueOf(-1), syncServerId);
        }
    }
    cursor.close();
    assertEquals(State.IDLE, mState);
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    noOfChanges = ContactDetailsTable.syncNativeFetchNoOfChanges(mDb.getReadableDatabase());
    assertEquals(0, noOfChanges);
    mState = State.IDLE;
    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) 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 23 with ServiceStatus

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

the class UploadServerContactsTest method testRunWithAddDeleteGroupChange.

@Suppress
public // Breaks tests
void testRunWithAddDeleteGroupChange() {
    final String fnName = "testRunWithAddDeleteGroupChange";
    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>();
    contact.groupList.clear();
    contactList.add(contact);
    ServiceStatus status = mDb.syncAddContactList(contactList, false, false);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Adding group to contact");
    status = mDb.addContactToGroup(contact.localContactID, TEST_GROUP_1);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Removing group from contact");
    status = mDb.deleteContactFromGroup(contact.localContactID, TEST_GROUP_1);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Running processor");
    runProcessor(0, State.IDLE);
    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 : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 24 with ServiceStatus

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

the class UploadServerContactsTest method testRunWithContactDeletion.

@MediumTest
@Suppress
public // Breaks tests
void testRunWithContactDeletion() {
    final String fnName = "testRunWithContactDeletion";
    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, "Deleting contact");
    status = mDb.deleteContact(contact.localContactID);
    assertEquals(ServiceStatus.SUCCESS, status);
    startSubTest(fnName, "Running processor");
    runProcessor(1, State.DELETE_CONTACT_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 : 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 25 with ServiceStatus

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

the class NowPlusContactDetailsTableTest method testFindLocalContactIdByKey.

public void testFindLocalContactIdByKey() {
    final String fnName = "testFindLocalContactIdByKey";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
    SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    // create local detail
    ContactDetail localDetail = new ContactDetail();
    localDetail.localContactID = TestModule.generateRandomLong();
    // populate native data
    localDetail.nativeContactId = TestModule.generateRandomInt();
    localDetail.nativeDetailId = TestModule.generateRandomInt();
    localDetail.nativeVal1 = "nativeVal1";
    localDetail.nativeVal2 = "nativeVal2";
    localDetail.nativeVal3 = "nativeVal3";
    localDetail.key = ContactDetail.DetailKeys.VCARD_IMADDRESS;
    localDetail.alt = "google";
    String imAddress = "meon@google.com";
    localDetail.setValue(imAddress, ContactDetail.DetailKeys.VCARD_IMADDRESS, null);
    ServiceStatus status = ContactDetailsTable.addContactDetail(localDetail, true, true, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    // create local detail
    ContactDetail localDetail2 = new ContactDetail();
    localDetail2.localContactID = TestModule.generateRandomLong();
    // populate native data
    localDetail2.nativeContactId = TestModule.generateRandomInt();
    localDetail2.nativeDetailId = TestModule.generateRandomInt();
    localDetail2.nativeVal1 = "nativeVal1";
    localDetail2.nativeVal2 = "nativeVal2";
    localDetail2.nativeVal3 = "nativeVal3";
    localDetail2.key = ContactDetail.DetailKeys.VCARD_IMADDRESS;
    String imAddress2 = "meon@google.com";
    localDetail2.setValue(imAddress2, ContactDetail.DetailKeys.VCARD_IMADDRESS, null);
    ServiceStatus status2 = ContactDetailsTable.addContactDetail(localDetail2, true, true, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status2);
    long result = ContactDetailsTable.findLocalContactIdByKey("google", "meon@google.com", ContactDetail.DetailKeys.VCARD_IMADDRESS, readableDb);
    assertTrue("The contact ids don't match: expected=" + localDetail.localContactID + ", actual=" + result, result == localDetail.localContactID);
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "***********************************************");
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

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