Search in sources :

Example 31 with ServiceStatus

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

the class NowPlusContactsTableTest method testServerSyncMethods.

@MediumTest
public void testServerSyncMethods() {
    final String fnName = "testServerSyncMethods";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "Validates server sync methods");
    SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
    SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    // add contacts and populate contactServerIdList
    List<ServerIdInfo> contactServerIdList = new ArrayList<ServerIdInfo>();
    final long contactIdBase = TestModule.generateRandomLong();
    for (int i = 0; i < NUM_OF_CONTACTS; i++) {
        Contact c = mTestModule.createDummyContactData();
        if (i == 2) {
            // Add duplicate server ID in database
            c.contactID = contactIdBase;
        }
        c.userID = TestModule.generateRandomLong();
        ServiceStatus status = ContactsTable.addContact(c, writeableDb);
        assertEquals(ServiceStatus.SUCCESS, status);
        ServerIdInfo serverInfo = new ServerIdInfo();
        serverInfo.localId = c.localContactID;
        serverInfo.serverId = contactIdBase + i;
        serverInfo.userId = c.userID;
        contactServerIdList.add(serverInfo);
    }
    // Add duplicate server ID in list from server
    Contact duplicateContact = mTestModule.createDummyContactData();
    duplicateContact.userID = TestModule.generateRandomLong();
    ServiceStatus status = ContactsTable.addContact(duplicateContact, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    ServerIdInfo serverInfo = new ServerIdInfo();
    serverInfo.localId = duplicateContact.localContactID;
    serverInfo.serverId = contactIdBase + 1;
    serverInfo.userId = duplicateContact.userID;
    contactServerIdList.add(serverInfo);
    List<ContactIdInfo> dupList = new ArrayList<ContactIdInfo>();
    status = ContactsTable.syncSetServerIds(contactServerIdList, dupList, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    // fetch server ids
    HashSet<Long> serverIds = new HashSet<Long>();
    status = ContactsTable.fetchContactServerIdList(serverIds, readableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    // validate if lists have the same sizes
    assertEquals(2, dupList.size());
    assertEquals(contactServerIdList.size() - 2, serverIds.size());
    assertEquals(Long.valueOf(dupList.get(0).localId), contactServerIdList.get(0).localId);
    assertEquals(contactServerIdList.get(0).serverId, dupList.get(0).serverId);
    assertEquals(duplicateContact.localContactID, Long.valueOf(dupList.get(1).localId));
    assertEquals(Long.valueOf(contactIdBase + 1), dupList.get(1).serverId);
    // Need to convert HashSet into an Arraylist, otherwise it's not possible to compare
    // HashSet is not sorted!
    ArrayList<Long> serverIdsArrayList = new ArrayList<Long>(serverIds);
    Collections.sort(serverIdsArrayList);
    final Iterator<Long> serverIdsIt = serverIdsArrayList.iterator();
    for (int i = 1; i < contactServerIdList.size() - 1; i++) {
        Long actServerId = serverIdsIt.next();
        assertEquals(contactServerIdList.get(i).serverId, actServerId);
    }
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) ArrayList(java.util.ArrayList) ServerIdInfo(com.vodafone360.people.database.DatabaseHelper.ServerIdInfo) Contact(com.vodafone360.people.datatypes.Contact) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) HashSet(java.util.HashSet) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 32 with ServiceStatus

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

the class NowPlusContactsTableTest method testFetchContactFormNativeId.

@MediumTest
public void testFetchContactFormNativeId() {
    final String fnName = "testFetchContactFormNativeId";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "tests fetchContactFormNativeId a contact id");
    SQLiteDatabase writableDb = mTestDatabase.getWritableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    startSubTest(fnName, "Add Contact");
    Contact contact = mTestModule.createDummyContactData();
    contact.userID = TestModule.generateRandomLong();
    contact.nativeContactId = TestModule.generateRandomInt();
    Long serverId = TestModule.generateRandomLong();
    ServiceStatus status = ContactsTable.addContact(contact, writableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertTrue(ContactsTable.modifyContactServerId(contact.localContactID, serverId, contact.userID, writableDb));
    ContactIdInfo idInfo = ContactsTable.fetchContactIdFromNative(contact.nativeContactId, writableDb);
    assertTrue(idInfo.localId == contact.localContactID);
    assertEquals(serverId, idInfo.serverId);
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 33 with ServiceStatus

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

the class NowPlusContactsTest method testOnUpgrade.

@SmallTest
public void testOnUpgrade() {
    assertTrue(initialise());
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    int oldVersion = TestModule.generateRandomInt();
    int newVersion = TestModule.generateRandomInt();
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    mDatabaseHelper.onUpgrade(db, oldVersion, newVersion);
    shutdown();
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 34 with ServiceStatus

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

the class NowPlusContactsTest method testAddContactDetail.

@SmallTest
@Suppress
public void testAddContactDetail() {
    assertTrue(initialise());
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    Contact addedContact = new Contact();
    status = mDatabaseHelper.addContact(addedContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    ContactDetail detail = new ContactDetail();
    mTestModule.createDummyDetailsData(detail);
    detail.localContactID = addedContact.localContactID;
    status = mDatabaseHelper.addContactDetail(detail);
    assertEquals(ServiceStatus.SUCCESS, status);
    ContactDetail fetchedDetail = new ContactDetail();
    status = mDatabaseHelper.fetchContactDetail(detail.localDetailID, fetchedDetail);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertTrue(DatabaseHelper.doDetailsMatch(detail, fetchedDetail));
    assertTrue(!DatabaseHelper.hasDetailChanged(detail, fetchedDetail));
    assertEquals(ServiceStatus.SUCCESS, mDatabaseHelper.deleteAllGroups());
    List<ServerIdInfo> serverIdList = new ArrayList<ServerIdInfo>();
    ServerIdInfo info = new ServerIdInfo();
    info.localId = fetchedDetail.localDetailID;
    info.serverId = fetchedDetail.localDetailID + 1;
    serverIdList.add(info);
    status = ContactDetailsTable.syncSetServerIds(serverIdList, mDatabaseHelper.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, status);
    status = mDatabaseHelper.fetchContactDetail(detail.localDetailID, fetchedDetail);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertEquals(info.serverId, fetchedDetail.unique_id);
    shutdown();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) ServerIdInfo(com.vodafone360.people.database.DatabaseHelper.ServerIdInfo) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 35 with ServiceStatus

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

the class GroupsEngine method processCommsResponse.

@Override
protected void processCommsResponse(DecodedResponse resp) {
    LogUtils.logD("DownloadGroups.processCommsResponse()");
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.ITEM_LIST_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        final List<GroupItem> tempGroupList = new ArrayList<GroupItem>();
        for (int i = 0; i < resp.mDataTypes.size(); i++) {
            ItemList itemList = (ItemList) resp.mDataTypes.get(i);
            if (itemList.mType != ItemList.Type.group_privacy) {
                completeUiRequest(ServiceStatus.ERROR_UNEXPECTED_RESPONSE);
                return;
            }
            // TODO: why cloning the list?
            for (int j = 0; j < itemList.mItemList.size(); j++) {
                tempGroupList.add((GroupItem) itemList.mItemList.get(j));
            }
        }
        LogUtils.logI("DownloadGroups.processCommsResponse() - No of groups " + tempGroupList.size());
        if (mPageNo == 0) {
            // clear old groups if we request the first groups page
            mDb.deleteAllGroups();
        }
        status = GroupsTable.addGroupList(tempGroupList, mDb.getWritableDatabase());
        if (ServiceStatus.SUCCESS != status) {
            completeUiRequest(status);
            return;
        }
        mNoOfGroupsFetched += tempGroupList.size();
        if (tempGroupList.size() < MAX_DOWN_PAGE_SIZE) {
            completeUiRequest(ServiceStatus.SUCCESS);
            return;
        }
        mPageNo++;
        requestNextGroupsPage();
        return;
    }
    LogUtils.logE("DownloadGroups.processCommsResponse() - Error requesting Zyb groups, error = " + status);
    completeUiRequest(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ItemList(com.vodafone360.people.datatypes.ItemList) ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem)

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