Search in sources :

Example 81 with Request

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

the class LoginEngine method handleNewPublicKeyResponse.

/**
 * Called when a response to the server fetch public key request is
 * received. Validates the response and stores the new public key details.
 *
 * @param mDataTypes Response data from server.
 */
private void handleNewPublicKeyResponse(List<BaseDataType> mDataTypes) {
    LogUtils.logD("LoginEngine.handleNewPublicKeyResponse()");
    ServiceStatus errorStatus = getResponseStatus(BaseDataType.PUBLIC_KEY_DETAILS_DATA_TYPE, mDataTypes);
    if (errorStatus == ServiceStatus.SUCCESS) {
        LogUtils.logD("LoginEngine.handleNewPublicKeyResponse() - Succesfully retrieved");
        // AA
        // 1. save to DB; save the flag that we aren't using default and
        // have to use one from DB
        // 2. start registration again
        mPublicKey = (PublicKeyDetails) mDataTypes.get(0);
        // done in startRegistrationProcessCrypted already
        // mDb.modifyCredentialsAndPublicKey(mLoginDetails, mPublicKey);
        startRegistrationProcessCrypted(mRegistrationDetails);
    } else {
        completeUiRequest(errorStatus, null);
    }
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 82 with Request

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

the class LoginEngine method onReset.

/**
 * Called by the framework before a remove user data operation takes place.
 * Initiates a suitable UI request which will kick the worker thread.
 */
@Override
public void onReset() {
    // reset the engine as if it was just created
    super.onReset();
    setRegistrationComplete(false);
    mState = State.NOT_REGISTERED;
    mRegistrationDetails = new RegistrationDetails();
    mActivationCode = null;
    onLoginStateChanged(false);
}
Also used : RegistrationDetails(com.vodafone360.people.datatypes.RegistrationDetails)

Example 83 with Request

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

the class TimeOutWatcherTest method createRequestWithTimeout.

// //////////////////
// HELPER METHODS //
// //////////////////
/**
 * Creates a request for the "undefined" engine.
 * @param timeout the timeout for the request in milliseconds
 */
private Request createRequestWithTimeout(long timeout) {
    final Request request = new Request("", Type.PRESENCE_LIST, EngineId.UNDEFINED, false, timeout);
    request.setActive(true);
    return request;
}
Also used : Request(com.vodafone360.people.service.io.Request)

Example 84 with Request

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

the class TimeOutWatcherTest method testThrowingTimeout.

/**
 * Tests that a timeout error is thrown if the response of the request has not been received after the timeout period.
 */
@Suppress
public void testThrowingTimeout() {
    Log.i("testThrowingTimeout()", "-begin");
    final Request request = createRequestWithTimeout(TIMEOUT_2000_MS);
    // check that the response queue is empty for the engine with EngineId.UNDEFINED id (we use this one for the test)
    DecodedResponse response = ResponseQueue.getInstance().getNextResponse(EngineId.UNDEFINED);
    assertNull(response);
    // adding the request to the queue should add it to the TimeOutWatcher
    final int reqId = QueueManager.getInstance().addRequest(request);
    // check that the response queue is still empty
    response = ResponseQueue.getInstance().getNextResponse(EngineId.UNDEFINED);
    assertNull(response);
    // let's give at least 2 times the timeout to the system before checking
    long stopTime = System.currentTimeMillis() + (TIMEOUT_2000_MS * 2);
    while (System.currentTimeMillis() < stopTime) {
        try {
            Thread.sleep(TIMEOUT_2000_MS);
        } catch (InterruptedException ie) {
            Log.i("testThrowingTimeout()", "Error while sleeping: " + ie);
        }
    }
    // check that the response is still empty
    response = ResponseQueue.getInstance().getNextResponse(EngineId.UNDEFINED);
    assertNotNull(response);
    // check response request id is the same as the request id
    assertEquals(reqId, response.mReqId.intValue());
    // check the timeout error returned is as expected
    assertNotNull(response.mDataTypes);
    assertEquals(1, response.mDataTypes.size());
    BaseDataType error = response.mDataTypes.get(0);
    assertTrue(error instanceof ServerError);
    ServerError srvError = (ServerError) error;
    assertEquals(ServerError.ErrorType.REQUEST_TIMEOUT, srvError.getType());
    Log.i("testThrowingTimeout()", "-end");
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ServerError(com.vodafone360.people.datatypes.ServerError) Request(com.vodafone360.people.service.io.Request) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 85 with Request

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

the class ContactSyncEngineTest method testUiRequestCompleteEvent_fullSync.

/**
 * Verifies that events are fired after UI requests.
 */
@Suppress
public // Breaks tests.
void testUiRequestCompleteEvent_fullSync() {
    Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_fullSync() begin ****");
    final UiEventCall uiEventCall = new UiEventCall();
    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);
            return new DummySyncProcessor(mContactSyncEngine, null);
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    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);
    // set the connection to be fine
    NetworkAgent.setAgentState(AgentState.CONNECTED);
    // ask for a full sync
    mContactSyncEngine.addUiStartFullSync();
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertEquals(0, nextRuntime);
    mContactSyncEngine.run();
    // check that first time sync is completed
    assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
    assertEquals(uiEventCall.status, ServiceStatus.SUCCESS.ordinal());
    Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_fullSync() end ****");
}
Also used : DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) 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)

Aggregations

Request (com.vodafone360.people.service.io.Request)43 QueueManager (com.vodafone360.people.service.io.QueueManager)27 ServiceStatus (com.vodafone360.people.service.ServiceStatus)16 ArrayList (java.util.ArrayList)16 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)12 ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)12 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)11 Suppress (android.test.suitebuilder.annotation.Suppress)10 DatabaseHelper (com.vodafone360.people.database.DatabaseHelper)9 IEngineEventCallback (com.vodafone360.people.engine.IEngineEventCallback)9 IContactSyncCallback (com.vodafone360.people.engine.contactsync.IContactSyncCallback)9 ProcessorFactory (com.vodafone360.people.engine.contactsync.ProcessorFactory)9 ServerError (com.vodafone360.people.datatypes.ServerError)6 IOException (java.io.IOException)6 Identity (com.vodafone360.people.datatypes.Identity)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Bundle (android.os.Bundle)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)4 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)4 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)4