Search in sources :

Example 51 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class PeopleContactsApiTest method testGetNativeContactsIdsMerge.

/**
 * Tests the getNativeContactsIds() method when a merge has to be performed.
 */
public void testGetNativeContactsIdsMerge() {
    final long[] NATIVE_IDS = { 10, 85, 12, 103, 44, 38 };
    final long[] DELETED_IDS = { NATIVE_IDS[0], NATIVE_IDS[5], NATIVE_IDS[3] };
    PeopleContactsApi pca = new PeopleContactsApi(mDatabaseHelper);
    // the database is empty, it shall not return any ids
    assertNull(pca.getNativeContactsIds());
    // let's add the contacts
    for (int i = 0; i < NATIVE_IDS.length; i++) {
        ContactChange[] contact = filterContactChanges(ContactChangeHelper.randomContact(ContactChange.INVALID_ID, ContactChange.INVALID_ID, NATIVE_IDS[i]));
        assertTrue(pca.addNativeContact(contact));
    }
    // check that they exist and in the right order (ascending)
    long[] ids = pca.getNativeContactsIds();
    assertEquals(NATIVE_IDS.length, ids.length);
    assertTrue(checkExistAndAscendingOrder(NATIVE_IDS, ids));
    // delete them from CAB as it was coming from backend or user
    // this has to be done without PeopleContactsApi wrapper as it does not support
    // operations for Contacts not related to the native address book
    List<ContactIdInfo> ciiList = new ArrayList<ContactIdInfo>(DELETED_IDS.length);
    final SQLiteDatabase readableDb = mDatabaseHelper.getReadableDatabase();
    try {
        final SQLiteStatement nativeToLocalId = ContactsTable.fetchLocalFromNativeIdStatement(readableDb);
        for (int i = 0; i < DELETED_IDS.length; i++) {
            final ContactIdInfo cii = new ContactIdInfo();
            cii.localId = ContactsTable.fetchLocalFromNativeId((int) DELETED_IDS[i], nativeToLocalId);
            cii.nativeId = (int) DELETED_IDS[i];
            ciiList.add(cii);
        }
    } finally {
        readableDb.close();
    }
    mDatabaseHelper.syncDeleteContactList(ciiList, false, true);
    // check the returned list of ids which should be similar as before
    ids = pca.getNativeContactsIds();
    assertEquals(NATIVE_IDS.length, ids.length);
    assertTrue(checkExistAndAscendingOrder(NATIVE_IDS, ids));
    // check that the deleted ids have the deleted flag
    for (int i = 0; i < DELETED_IDS.length; i++) {
        final ContactChange[] cc = pca.getContact(DELETED_IDS[i]);
        assertEquals(cc[0].getType(), ContactChange.TYPE_DELETE_CONTACT);
    }
}
Also used : ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) ArrayList(java.util.ArrayList) PeopleContactsApi(com.vodafone360.people.engine.contactsync.PeopleContactsApi) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 52 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class NowPlusDBHelperLoginTest method testSetFetchOption.

/*
	 * set and fetch option
	 */
public void testSetFetchOption() {
    Log.i(LOG_TAG, "***** EXECUTING testAddDeleteContactsDetails *****");
    Log.i(LOG_TAG, "Test contact functionality (add delete contacts details)");
    Log.i(LOG_TAG, "Test 1a: Initialise test environment and load database");
    assertTrue(initialise());
    Log.i(LOG_TAG, "Test 1b: Remove user data");
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    PersistSettings setting = new PersistSettings();
    setting.putInternetAvail(InternetAvail.ALWAYS_CONNECT);
    status = mDatabaseHelper.setOption(setting);
    assertEquals(ServiceStatus.SUCCESS, status);
    PersistSettings fetchedSetting = mDatabaseHelper.fetchOption(PersistSettings.Option.INTERNETAVAIL);
    assertEquals(fetchedSetting.toString(), setting.toString());
    shutdown();
    Log.i(LOG_TAG, "*************************************");
    Log.i(LOG_TAG, "testModifyFetchCredentials has completed successfully");
    Log.i(LOG_TAG, "**************************************");
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 53 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class NowPlusDBHelperLoginTest method testModifyFetchCredentials.

/*
	 * Modify and fetch credentials  
	 */
@MediumTest
public void testModifyFetchCredentials() {
    Log.i(LOG_TAG, "***** EXECUTING testAddDeleteContactsDetails *****");
    Log.i(LOG_TAG, "Test contact functionality (add delete contacts details)");
    Log.i(LOG_TAG, "Test 1a: Initialise test environment and load database");
    assertTrue(initialise());
    Log.i(LOG_TAG, "Test 1b: Remove user data");
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    RegistrationDetails registrationDetails = new RegistrationDetails();
    registrationDetails.mUsername = TestModule.generateRandomString();
    registrationDetails.mPassword = TestModule.generateRandomString();
    registrationDetails.mMsisdn = TestModule.generateRandomString();
    LoginDetails loginDetails = new LoginDetails();
    loginDetails.mUsername = registrationDetails.mUsername;
    loginDetails.mPassword = registrationDetails.mPassword;
    loginDetails.mAutoConnect = TestModule.generateRandomBoolean();
    loginDetails.mRememberMe = TestModule.generateRandomBoolean();
    loginDetails.mMobileNo = registrationDetails.mMsisdn;
    loginDetails.mSubscriberId = TestModule.generateRandomString();
    LoginDetails fetchedLogin = new LoginDetails();
    status = mDatabaseHelper.fetchLogonCredentials(fetchedLogin);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertNull(fetchedLogin.mUsername);
    assertNull(fetchedLogin.mPassword);
    status = mDatabaseHelper.modifyCredentials(loginDetails);
    assertEquals(ServiceStatus.SUCCESS, status);
    status = mDatabaseHelper.fetchLogonCredentials(fetchedLogin);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertEquals(loginDetails.mUsername, fetchedLogin.mUsername);
    if (loginDetails.mRememberMe) {
        assertEquals(loginDetails.mPassword, fetchedLogin.mPassword);
    }
    assertEquals(loginDetails.mAutoConnect, fetchedLogin.mAutoConnect);
    assertEquals(loginDetails.mRememberMe, fetchedLogin.mRememberMe);
    assertEquals(loginDetails.mMobileNo, fetchedLogin.mMobileNo);
    assertEquals(loginDetails.mSubscriberId, fetchedLogin.mSubscriberId);
    shutdown();
    Log.i(LOG_TAG, "*************************************");
    Log.i(LOG_TAG, "testModifyFetchCredentials has completed successfully");
    Log.i(LOG_TAG, "**************************************");
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) RegistrationDetails(com.vodafone360.people.datatypes.RegistrationDetails) LoginDetails(com.vodafone360.people.datatypes.LoginDetails) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 54 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class NowPlusPresenceTableTest method testSetAllUsersOfflineExceptForMe.

public void testSetAllUsersOfflineExceptForMe() {
    Log.i(LOG_TAG, "***** testSetAllUsersOfflineExceptForMe() *****");
    PresenceTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "***** testSetAllUsersOfflineExceptForMe(): table created*****");
    assertTrue("The method adds a null user and returns true", PresenceTable.updateUser(null, null, mTestDatabase.getWritableDatabase()) == PresenceTable.USER_NOTADDED);
    Log.i(LOG_TAG, "***** testUpdateUser: NULL test SUCCEEDED *****");
    // 1
    Hashtable<String, String> status = new Hashtable<String, String>();
    status.put("google", "online");
    status.put("microsoft", "online");
    status.put("mobile", "online");
    // status.put("pc", "online");
    User user = new User("google::meongoogletalk@gmail.com", status);
    user.setLocalContactId(12L);
    assertTrue("the user was not added to DB", PresenceTable.updateUser(user, null, mTestDatabase.getWritableDatabase()) == PresenceTable.USER_ADDED);
    LogUtils.logE("User1:" + user.toString());
    user = null;
    // 4
    user = new User("12345678", status);
    user.setLocalContactId(13L);
    assertTrue("the NowplusUser user was not added to DB", PresenceTable.updateUser(user, null, mTestDatabase.getWritableDatabase()) == PresenceTable.USER_ADDED);
    // user = null;
    // 8
    // status.put("pc", "offline");
    // user = new User("12345678", status);
    user.setLocalContactId(13L);
    LogUtils.logE("User2:" + user.toString());
    LogUtils.logE(user.toString());
    assertTrue("the  Existing NowplusUser might be duplicated to DB", PresenceTable.updateUser(user, null, mTestDatabase.getWritableDatabase()) == PresenceTable.USER_UPDATED);
    // 8
    int count = PresenceTable.setAllUsersOfflineExceptForMe(12L, mTestDatabase.getWritableDatabase());
    assertTrue("The count of deleted rows is not the expected one:" + count, count == 3);
    Log.i(LOG_TAG, "***** testSetAllUsersOfflineExceptForMe() test SUCCEEDED*****");
}
Also used : User(com.vodafone360.people.engine.presence.User) Hashtable(java.util.Hashtable)

Example 55 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class ContactsTable method syncSetServerIds.

/**
 * Updates the server and user IDs for a list of contacts. Also prepares a
 * list of duplicates which will be filled with the Ids for contacts already
 * present in the table (i.e. server ID has already been used). In the case
 * that a duplicate is found, the ContactIdInfo object will also include the
 * local ID of the original contact (see {@link ContactIdInfo#mergedLocalId}
 * ).
 *
 * @param serverIdList A list of ServerIdInfo objects. For each object, the
 *            local ID must match a local contact ID in the table. The
 *            Server ID and User ID will be used for the update.
 * @param dupList On return this will be populated with a list of contacts
 *            which have server IDs already present in the table.
 * @param writeableDb Writeable SQLite database
 * @return SUCCESS or a suitable error code
 */
public static ServiceStatus syncSetServerIds(List<ServerIdInfo> serverIdList, List<ContactIdInfo> dupList, SQLiteDatabase writableDb) {
    DatabaseHelper.trace(true, "ContactsTable.syncSetServerIds()");
    if (serverIdList.size() == 0) {
        return ServiceStatus.SUCCESS;
    }
    SQLiteStatement statement1 = null;
    SQLiteStatement statement2 = null;
    try {
        writableDb.beginTransaction();
        for (int i = 0; i < serverIdList.size(); i++) {
            final ServerIdInfo info = serverIdList.get(i);
            try {
                if (info.serverId != null) {
                    if (info.userId == null) {
                        if (statement2 == null) {
                            statement2 = writableDb.compileStatement("UPDATE " + TABLE_NAME + " SET " + Field.SERVERID + "=? WHERE " + Field.LOCALID + "=?");
                        }
                        statement2.bindLong(1, info.serverId);
                        statement2.bindLong(2, info.localId);
                        statement2.execute();
                    } else {
                        if (statement1 == null) {
                            statement1 = writableDb.compileStatement("UPDATE " + TABLE_NAME + " SET " + Field.SERVERID + "=?," + Field.USERID + "=? WHERE " + Field.LOCALID + "=?");
                        }
                        statement1.bindLong(1, info.serverId);
                        statement1.bindLong(2, info.userId);
                        statement1.bindLong(3, info.localId);
                        statement1.execute();
                    }
                }
            } catch (SQLiteConstraintException e) {
                // server ID is not unique
                ContactIdInfo contactInfo = new ContactIdInfo();
                contactInfo.localId = info.localId;
                contactInfo.serverId = info.serverId;
                if (!fetchLocalIDFromServerID(writableDb, contactInfo)) {
                    writableDb.endTransaction();
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
                dupList.add(contactInfo);
            } catch (SQLException e) {
                LogUtils.logE("ContactsTable.syncSetServerIds() SQLException - " + "Unable to update contact server Ids", e);
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
        }
        writableDb.setTransactionSuccessful();
    } finally {
        writableDb.endTransaction();
        if (statement1 != null) {
            statement1.close();
            statement1 = null;
        }
        if (statement2 != null) {
            statement2.close();
            statement2 = null;
        }
    }
    return ServiceStatus.SUCCESS;
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException) ServerIdInfo(com.vodafone360.people.database.DatabaseHelper.ServerIdInfo) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException)

Aggregations

ServiceStatus (com.vodafone360.people.service.ServiceStatus)22 Contact (com.vodafone360.people.datatypes.Contact)12 ArrayList (java.util.ArrayList)12 User (com.vodafone360.people.engine.presence.User)11 Hashtable (java.util.Hashtable)9 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)7 Request (com.vodafone360.people.service.io.Request)7 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 PersistSettings (com.vodafone360.people.service.PersistSettings)6 QueueManager (com.vodafone360.people.service.io.QueueManager)6 SmallTest (android.test.suitebuilder.annotation.SmallTest)4 Identity (com.vodafone360.people.datatypes.Identity)4 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)3 RegistrationDetails (com.vodafone360.people.datatypes.RegistrationDetails)3 NetworkPresence (com.vodafone360.people.engine.presence.NetworkPresence)3 Cursor (android.database.Cursor)2 SQLiteStatement (android.database.sqlite.SQLiteStatement)2 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)2 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)2 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)2