Search in sources :

Example 11 with User

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

the class NowPlusServiceTestHelper method fetchUsernameState.

/**
 * Synchronously fetches the state of the user name from the NOW+ server
 *
 * @param username The user name to check (entered during registration)
 * @param data On success fills the given bundle with a key called
 *            "UsernameState.mBundleKey" and string data which is one of the
 *            UsernameState enum values.
 * @return SUCCESS or one of the ServiceStatus error codes.
 */
public ServiceStatus fetchUsernameState(String username, Bundle data) {
    ServiceStatus status = ServiceStatus.SUCCESS;
    synchronized (mUiRequestLock) {
        status = startSynchronousRequest(ServiceUiRequest.USERNAME_AVAILABILITY);
        mPeopleService.fetchUsernameState(username);
        status = waitForEvent(WAIT_EVENT_TIMEOUT_MS, 0);
    }
    return status;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 12 with User

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

the class ContactSyncEngineTest method testCancelSync.

/**
 * Tests the sync is cancelled in case we remove user data.
 */
@Suppress
public // Breaks tests.
void testCancelSync() {
    Log.i(LOG_TAG, "**** testNativeSync_newEngineInstantiation() begin ****");
    final ArrayList<ProcessorLog> processorLogs = new ArrayList<ProcessorLog>();
    final UiEventCall uiEventCall = new UiEventCall();
    final ProcessorLog processorLog = new ProcessorLog();
    final IEngineEventCallback engineEventCallback = new HelperClasses.EngineCallbackBase() {

        @Override
        public void onUiEvent(ServiceUiRequest event, int request, int status, Object data) {
            Log.i(LOG_TAG, "onUiEvent: " + event + ", " + request + ", " + status + ", " + data);
            uiEventCall.event = event.ordinal();
            uiEventCall.request = request;
            uiEventCall.status = status;
            uiEventCall.data = data;
        }
    };
    final ProcessorFactory factory = new ProcessorFactory() {

        @Override
        public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
            Log.i(LOG_TAG, "create(), type=" + type);
            ProcessorLog log = new ProcessorLog();
            log.type = type;
            log.time = System.currentTimeMillis();
            processorLogs.add(log);
            return new BaseSyncProcessor(mContactSyncEngine, null) {

                @Override
                protected void doCancel() {
                    // cancel the job
                    processorLog.type = 1;
                }

                @Override
                protected void doStart() {
                    // set a "timeout" to be called back immediately
                    setTimeout(0);
                    processorLog.type = 2;
                }

                @Override
                public void onTimeoutEvent() {
                    // set the job as completed
                    Log.i(LOG_TAG, "onTimeoutEvent()");
                    complete(ServiceStatus.SUCCESS);
                    processorLog.type = 3;
                }

                @Override
                public void processCommsResponse(DecodedResponse resp) {
                    // we don't need this case in this test
                    processorLog.type = 4;
                }
            };
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    // set the connection to be fine
    NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
    long nextRuntime = mContactSyncEngine.getNextRunTime();
    // should be equal to -1 because first time sync has not been yet
    // started
    assertEquals(-1, nextRuntime);
    // force a first time sync
    mContactSyncEngine.addUiStartFullSync();
    processorLog.type = 0;
    // start performing the sync
    mContactSyncEngine.run();
    // the first processor should have started
    assertTrue(processorLog.type == 2);
    // this will cancel any sync
    mContactSyncEngine.onReset();
    // get the engine to perform a cancel on the current processor
    mContactSyncEngine.run();
    assertTrue(processorLog.type == 1);
    // check that the engine cancelled the sync
    assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
    assertEquals(uiEventCall.status, ServiceStatus.USER_CANCELLED.ordinal());
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ArrayList(java.util.ArrayList) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) BaseSyncProcessor(com.vodafone360.people.engine.contactsync.BaseSyncProcessor) ProcessorFactory(com.vodafone360.people.engine.contactsync.ProcessorFactory) IContactSyncCallback(com.vodafone360.people.engine.contactsync.IContactSyncCallback) IEngineEventCallback(com.vodafone360.people.engine.IEngineEventCallback) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 13 with User

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

the class PeopleContactsApiTest method testUpdateGetNativeContactWithDelete.

/**
 * Tests the updateNativeContact() method when a detail is deleted outside.
 */
public void testUpdateGetNativeContactWithDelete() {
    final long NATIVE_ID = 15;
    PeopleContactsApi pca = new PeopleContactsApi(mDatabaseHelper);
    // the database is empty, it shall not return any ids
    assertNull(pca.getNativeContactsIds());
    // let's add a contact
    ContactChange[] contact = filterContactChanges(ContactChangeHelper.randomContact(ContactChange.INVALID_ID, ContactChange.INVALID_ID, NATIVE_ID));
    assertTrue(pca.addNativeContact(contact));
    // check that it exists
    long[] ids = pca.getNativeContactsIds();
    assertEquals(1, ids.length);
    assertEquals(NATIVE_ID, ids[0]);
    // get the contact back
    ContactChange[] savedContact = pca.getContact(NATIVE_ID);
    assertNotNull(savedContact);
    // let's add a detail
    ContactChange addedDetail = new ContactChange(ContactChange.KEY_VCARD_PHONE, "+3300000", ContactChange.FLAG_HOME);
    addedDetail.setNabContactId(NATIVE_ID);
    addedDetail.setType(ContactChange.TYPE_ADD_DETAIL);
    addedDetail.setInternalContactId(savedContact[0].getInternalContactId());
    ContactChange[] updates = { addedDetail };
    pca.updateNativeContact(updates);
    // get the contact back
    savedContact = pca.getContact(NATIVE_ID);
    assertNotNull(savedContact);
    assertEquals(contact.length + 1, savedContact.length);
    // find the localId of the detail to delete
    int index = findContactChangeIndex(savedContact, addedDetail);
    assertTrue(index != -1);
    addedDetail.setInternalDetailId(savedContact[index].getInternalDetailId());
    // remove the detail as if coming from user or server (i.e. not yet synced to native)
    ArrayList<ContactDetail> detailList = new ArrayList<ContactDetail>(1);
    detailList.add(mDatabaseHelper.convertContactChange(addedDetail));
    mDatabaseHelper.syncDeleteContactDetailList(detailList, false, true);
    // get the contact back
    savedContact = pca.getContact(NATIVE_ID);
    assertNotNull(savedContact);
    // the deleted detail shall be given
    assertEquals(contact.length + 1, savedContact.length);
    // check that one contact has the deleted flag
    int deletedIndex = -1;
    int deletedCount = 0;
    for (int i = 0; i < savedContact.length; i++) {
        if (savedContact[i].getType() == ContactChange.TYPE_DELETE_DETAIL) {
            deletedIndex = i;
            deletedCount++;
        }
    }
    // there shall be only one deleted detail
    assertEquals(1, deletedCount);
    assertEquals(addedDetail.getInternalDetailId(), savedContact[deletedIndex].getInternalDetailId());
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ArrayList(java.util.ArrayList) PeopleContactsApi(com.vodafone360.people.engine.contactsync.PeopleContactsApi) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 14 with User

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

the class UploadServerContacts method processModifiedDetailsResp.

/**
 * Called when a server response is received during a modified contact sync.
 * The server ID, user ID and contact detail unique IDs are extracted from
 * the response and the NowPlus database updated if necessary. Possibly
 * server errors are also handled.
 *
 * @param resp Response from server.
 */
private void processModifiedDetailsResp(final DecodedResponse resp) {
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactChanges contactChanges = (ContactChanges) resp.mDataTypes.get(0);
        ListIterator<Contact> itContactSrc = contactChanges.mContacts.listIterator();
        ListIterator<Contact> itContactDest = mContactChangeList.listIterator();
        List<ServerIdInfo> detailServerIdList = new ArrayList<ServerIdInfo>();
        while (itContactSrc.hasNext()) {
            if (!itContactDest.hasNext()) {
                /*
                     * The response should contain the same number of contacts
                     * as was supplied but must handle the error.
                     */
                status = ServiceStatus.ERROR_COMMS_BAD_RESPONSE;
                break;
            }
            status = handleUploadDetailChanges(itContactSrc.next(), itContactDest.next(), detailServerIdList);
        }
        if (status != ServiceStatus.SUCCESS) {
            /**
             * Something is going wrong - cancel the update. *
             */
            complete(status);
            return;
        }
        long startTime = System.nanoTime();
        status = ContactDetailsTable.syncSetServerIds(detailServerIdList, mDb.getWritableDatabase());
        if (status != ServiceStatus.SUCCESS) {
            complete(status);
            return;
        }
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        mContactChangeInfoList.clear();
        updateProgress();
        sendNextDetailChangesPage();
        return;
    }
    LogUtils.logE("UploadServerContacts.processModifiedDetailsResp() " + "Error requesting contact changes, error = " + status);
    complete(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) ServerIdInfo(com.vodafone360.people.database.DatabaseHelper.ServerIdInfo) ContactChanges(com.vodafone360.people.datatypes.ContactChanges) Contact(com.vodafone360.people.datatypes.Contact)

Example 15 with User

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

the class NowPlusContactsTest method testAddDeleteContacts.

@MediumTest
public void testAddDeleteContacts() {
    Log.i(LOG_TAG, "***** EXECUTING testAddDeleteContacts *****");
    Log.i(LOG_TAG, "Test contact functionality (add delete contacts)");
    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);
    Log.i(LOG_TAG, "Test 1c: Add " + NUM_OF_CONTACTS + " random contacts");
    // add contacts and check if added contacts are the same as fetched
    Contact[] inputContacts = new Contact[NUM_OF_CONTACTS];
    Contact addedContact = new Contact();
    for (int i = 0; i < NUM_OF_CONTACTS; i++) {
        inputContacts[i] = mTestModule.createDummyContactData();
        status = mDatabaseHelper.addContact(inputContacts[i]);
        assertEquals(ServiceStatus.SUCCESS, status);
        status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, addedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        assertTrue(TestModule.doContactsMatch(addedContact, inputContacts[i]));
    }
    Log.i(LOG_TAG, "Test 1d: Delete contacts and check if deletion was correct");
    for (int i = 0; i < inputContacts.length; i++) {
        // check if deletion works good
        status = mDatabaseHelper.deleteContact(inputContacts[i].localContactID);
        assertEquals(ServiceStatus.SUCCESS, status);
        Contact removedContact = new Contact();
        status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, removedContact);
        // contact was deleted so it shouldn't be found
        assertEquals(ServiceStatus.ERROR_NOT_FOUND, status);
    }
    shutdown();
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact) MediumTest(android.test.suitebuilder.annotation.MediumTest)

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