Search in sources :

Example 21 with User

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

the class NowPlusDBHelperLoginTest method testModifyCredentialsAndKey.

/*
	 * Modify credentials and public key then fetch modified credentials and validate it
	 */
@MediumTest
public void testModifyCredentialsAndKey() {
    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();
    PublicKeyDetails pubKeyDetails = new PublicKeyDetails();
    RSAEncryptionUtils.copyDefaultPublicKey(pubKeyDetails);
    pubKeyDetails.mKeyBase64 = TestModule.generateRandomString();
    LoginDetails fetchedLogin = new LoginDetails();
    PublicKeyDetails fetchedPubKey = new PublicKeyDetails();
    status = mDatabaseHelper.fetchLogonCredentialsAndPublicKey(fetchedLogin, fetchedPubKey);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertNull(fetchedLogin.mUsername);
    assertNull(fetchedLogin.mPassword);
    assertNull(fetchedPubKey.mKeyBase64);
    assertNull(fetchedPubKey.mExponential);
    assertNull(fetchedPubKey.mModulus);
    status = mDatabaseHelper.modifyCredentialsAndPublicKey(loginDetails, pubKeyDetails);
    assertEquals(ServiceStatus.SUCCESS, status);
    status = mDatabaseHelper.fetchLogonCredentialsAndPublicKey(fetchedLogin, fetchedPubKey);
    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);
    assertEquals(pubKeyDetails.mExponential.length, fetchedPubKey.mExponential.length);
    for (int i = 0; i < pubKeyDetails.mExponential.length; i++) {
        assertEquals(pubKeyDetails.mExponential[i], fetchedPubKey.mExponential[i]);
    }
    assertEquals(pubKeyDetails.mModulus.length, fetchedPubKey.mModulus.length);
    for (int i = 0; i < fetchedPubKey.mModulus.length; i++) {
        assertEquals(pubKeyDetails.mModulus[i], fetchedPubKey.mModulus[i]);
    }
    assertEquals(pubKeyDetails.mKeyBase64, fetchedPubKey.mKeyBase64);
    shutdown();
    Log.i(LOG_TAG, "*************************************");
    Log.i(LOG_TAG, "testModifyFetchCredentials has completed successfully");
    Log.i(LOG_TAG, "**************************************");
}
Also used : PublicKeyDetails(com.vodafone360.people.datatypes.PublicKeyDetails) 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 22 with User

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

the class NowPlusPresenceTableTest method testSetAllUsersOffline.

// public void testDropTable() {
// Log.i(LOG_TAG, "***** testDropTable() *****");
// PresenceTable.create(mTestDatabase.getWritableDatabase());
// Log.i(LOG_TAG, "***** testDropTable(): table created*****");
// 
// 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);
// assertTrue("the user was not added to DB", PresenceTable.updateUser(user, mTestDatabase.getWritableDatabase()) != PresenceTable.USER_NOTADDED);
// user = null;
// //		4
// NowPlusPresenceDbUtilsTest.dropTable(mTestDatabase.getWritableDatabase());
// Log.i(LOG_TAG, "***** testDropTable(): dropped table*****");
// 
// PresenceTable.create(mTestDatabase.getWritableDatabase());
// Log.i(LOG_TAG, "***** testDropTable(): table created again*****");
// 
// int count = PresenceTable.setAllUsersOffline(mTestDatabase.getWritableDatabase());
// assertTrue("The count of deleted rows is not the expected one:"+count, count == 0);
// Log.i(LOG_TAG, "***** testDropTable() test SUCCEEDED*****");
// }
public void testSetAllUsersOffline() {
    Log.i(LOG_TAG, "***** testSetAllUsersOffline() *****");
    PresenceTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "***** testSetAllUsersOffline(): 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("UNPARSEBLE", status);
    // assertTrue("the UNPARSEBLE user was added to DB", PresenceTable.updateUser(user, mTestDatabase.getWritableDatabase())== PresenceTable.USER_NOTADDED);
    // 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.setAllUsersOffline(mTestDatabase.getWritableDatabase());
    assertTrue("The count of deleted rows is not the expected one:" + count, count == 6);
    Log.i(LOG_TAG, "***** testSetAllUsersOffline() test SUCCEEDED*****");
}
Also used : User(com.vodafone360.people.engine.presence.User) Hashtable(java.util.Hashtable)

Example 23 with User

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

the class NowPlusPresenceTableTest method testUpdateUser.

public void testUpdateUser() {
    Log.i(LOG_TAG, "***** testUpdateUser *****");
    PresenceTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "***** testUpdateUser: 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 *****");
    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);
    // fake localId
    user.setLocalContactId(12L);
    assertTrue("the user was not added to DB", PresenceTable.updateUser(user, null, mTestDatabase.getWritableDatabase()) != PresenceTable.USER_NOTADDED);
    Log.i(LOG_TAG, "***** testUpdateUser Good User test SUCCEEDED*****");
    user = null;
    // now, update the user
    status.put("google", "offline");
    status.put("microsoft", "online");
    status.put("mobile", "online");
    status.put("pc", "offline");
    user = new User("google::meongoogletalk@gmail.com", status);
    // fake localId
    user.setLocalContactId(12L);
    assertTrue("the  Existing NowplusUser might be duplicated to DB", PresenceTable.updateUser(user, null, mTestDatabase.getWritableDatabase()) == PresenceTable.USER_UPDATED);
    User user1 = PresenceTable.getUserPresenceByLocalContactId(12L, mTestDatabase.getReadableDatabase());
    assertTrue("the initial and fetched users are not the same!", user.equals(user1));
    Log.i(LOG_TAG, "***** testUpdateUser test SUCCEEDED*****");
}
Also used : User(com.vodafone360.people.engine.presence.User) Hashtable(java.util.Hashtable)

Example 24 with User

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

the class NowPlusPresenceTableTest method testGetMeProfilePresenceById.

public void testGetMeProfilePresenceById() {
    Log.i(LOG_TAG, "***** GetMeProfilePresenceById() *****");
    PresenceTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "***** GetMeProfilePresenceById(): table created*****");
    Hashtable<String, String> status = new Hashtable<String, String>();
    status.put("google", "online");
    status.put("microsoft", "online");
    status.put("mobile", "online");
    status.put("pc", "online");
    // imaginary Me Profile
    User user = new User("12345678", status);
    // fake localId
    user.setLocalContactId(12L);
    assertTrue("the user was not added to DB", PresenceTable.updateUser(user, null, mTestDatabase.getWritableDatabase()) == PresenceTable.USER_ADDED);
    Log.i(LOG_TAG, "***** testUpdateUser Good User test SUCCEEDED*****");
    User user1 = PresenceTable.getUserPresenceByLocalContactId(12L, mTestDatabase.getReadableDatabase());
    assertTrue("the initial and fetched users are not the same!", user.equals(user1));
    assertNull(PresenceTable.getUserPresenceByLocalContactId(-1L, mTestDatabase.getReadableDatabase()));
    Log.i(LOG_TAG, "***** GetMeProfilePresenceById() SUCCEEEDED*****");
}
Also used : User(com.vodafone360.people.engine.presence.User) Hashtable(java.util.Hashtable)

Example 25 with User

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

the class PresenceDbUtils method processMeProfile.

/**
 * This method alters the User wrapper of me profile,
 *  and returns true if me profile information contains the ignored TPC networks information.
 * Based on the result this information may be deleted.
 * @param removePCPresence - if TRUE the PC network will be removed from the network list.
 * @param user - the me profile wrapper.
 * @param ignoredNetworks - the list if ignored integer network ids.
 * @return
 */
private static boolean processMeProfile(boolean removePCPresence, User user, ArrayList<Integer> ignoredNetworks) {
    if (removePCPresence) {
        int max = OnlineStatus.OFFLINE.ordinal();
        // calculate the new aggregated presence status
        for (NetworkPresence presence : user.getPayload()) {
            if (presence.getOnlineStatusId() > max) {
                max = presence.getOnlineStatusId();
            }
        }
        user.setOverallOnline(max);
    }
    // the list of chat network ids in this User wrapper
    ArrayList<Integer> userNetworks = new ArrayList<Integer>();
    ArrayList<NetworkPresence> payload = user.getPayload();
    for (NetworkPresence presence : payload) {
        int networkId = presence.getNetworkId();
        userNetworks.add(networkId);
        // 1. ignore offline TPC networks
        if (presence.getOnlineStatusId() == OnlineStatus.OFFLINE.ordinal()) {
            ignoredNetworks.add(networkId);
        }
    }
    // 2. ignore the TPC networks presence state for which is unknown
    ArrayList<Identity> identities = EngineManager.getInstance().getIdentityEngine().getMyChattableIdentities();
    SocialNetwork network = null;
    for (Identity identity : identities) {
        network = SocialNetwork.getValue(identity.mNetwork);
        if (network != null) {
            if (!userNetworks.contains(network.ordinal())) {
                ignoredNetworks.add(network.ordinal());
            }
        }
    }
    return !ignoredNetworks.isEmpty();
}
Also used : ArrayList(java.util.ArrayList) SocialNetwork(com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork) Identity(com.vodafone360.people.datatypes.Identity)

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