Search in sources :

Example 21 with DecodedResponse

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

the class HessianDecoderTest method testErrorResponse.

@MediumTest
public void testErrorResponse() {
    //boolean testPassed = true;
    List<BaseDataType> clist = new ArrayList<BaseDataType>();
    HessianDecoder hess = new HessianDecoder();
    try {
        DecodedResponse resp = hess.decodeHessianByteArray(6, testErrorResponse, Type.COMMON, false, EngineId.UNDEFINED);
        clist = resp.mDataTypes;
    } catch (IOException e) {
        e.printStackTrace();
        assertTrue("IOException thrown", false);
    }
    int size = clist.size();
    assertTrue(size == 1);
    assertTrue(clist.get(0) instanceof ServerError);
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) HessianDecoder(com.vodafone360.people.service.utils.hessian.HessianDecoder) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) IOException(java.io.IOException) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 22 with DecodedResponse

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

the class ContactSyncEngine method processPushEvent.

/**
     * Determines if a given response is a push message and processes in this
     * case TODO: we need the check for Me Profile be migrated to he new engine
     * 
     * @param resp Response to check and process
     * @return true if the response was processed
     */
private boolean processPushEvent(DecodedResponse resp) {
    if (resp.mDataTypes == null || resp.mDataTypes.size() == 0) {
        return false;
    }
    BaseDataType dataType = resp.mDataTypes.get(0);
    if ((dataType == null) || dataType.getType() != BaseDataType.PUSH_EVENT_DATA_TYPE) {
        return false;
    }
    PushEvent pushEvent = (PushEvent) dataType;
    LogUtils.logV("Push Event Type = " + pushEvent.mMessageType);
    switch(pushEvent.mMessageType) {
        case CONTACTS_CHANGE:
            LogUtils.logI("ContactSyncEngine.processCommsResponse - Contacts changed push message received");
            mServerSyncRequired = true;
            // fetch the newest groups
            EngineManager.getInstance().getGroupsEngine().addUiGetGroupsRequest();
            mEventCallback.kickWorkerThread();
            break;
        case SYSTEM_NOTIFICATION:
            LogUtils.logI("ContactSyncEngine.processCommsResponse - System notification push message received");
            break;
        default:
            // do nothing.
            break;
    }
    return true;
}
Also used : PushEvent(com.vodafone360.people.datatypes.PushEvent) BaseDataType(com.vodafone360.people.datatypes.BaseDataType)

Example 23 with DecodedResponse

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

the class ActivitiesEngine method processCommsResponse.

/**
     * Handle response received from transport layer (via EngineManager)
     * 
     * @param resp Received Response item either a Status/Timeline related push
     *            message or a response to a get activities request.
     */
@Override
protected void processCommsResponse(DecodedResponse resp) {
    LogUtils.logD("ActivitiesEngine processCommsResponse");
    // handle push response
    if (resp.mReqId == 0 && resp.mDataTypes.size() > 0) {
        PushEvent evt = (PushEvent) resp.mDataTypes.get(0);
        handlePushRequest(evt.mMessageType);
    } else {
        dequeueRequest(resp.mReqId);
        handleGetActivitiesResponse(resp.mDataTypes);
    }
}
Also used : PushEvent(com.vodafone360.people.datatypes.PushEvent)

Example 24 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse 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 25 with DecodedResponse

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

the class HessianDecoderTest method testSessionResponse.

/*
	 * 
	 * r{1}{0}fS{0}{4}codeS{0}{14}INTERNAL_ERRORS{0}{7}
	 * messageS{0}hError occured while getting contacts. Message was: Object reference not set to an instance of an object.S{0}{7}detailsMt{0}{0}S{0}{5}classS{0}Dcom.vodafone.next.api.common.APIStructures$APIInternalErrorExceptionzzz
	 */
@MediumTest
public void testSessionResponse() {
    //boolean testPassed = true;
    List<BaseDataType> slist = new ArrayList<BaseDataType>();
    HessianDecoder hess = new HessianDecoder();
    try {
        DecodedResponse resp = hess.decodeHessianByteArray(1, testSessionData, Type.COMMON, false, EngineId.UNDEFINED);
        slist = resp.mDataTypes;
    } catch (IOException e) {
        e.printStackTrace();
        assertTrue("IOException thrown", false);
    }
    int size = slist.size();
    assertTrue(size == 1);
    assertTrue(slist.get(0) instanceof AuthSessionHolder);
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) ArrayList(java.util.ArrayList) HessianDecoder(com.vodafone360.people.service.utils.hessian.HessianDecoder) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) IOException(java.io.IOException) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)26 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)23 ArrayList (java.util.ArrayList)23 ServiceStatus (com.vodafone360.people.service.ServiceStatus)13 ServerError (com.vodafone360.people.datatypes.ServerError)12 IOException (java.io.IOException)10 MediumTest (android.test.suitebuilder.annotation.MediumTest)9 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)8 PushEvent (com.vodafone360.people.datatypes.PushEvent)7 HessianDecoder (com.vodafone360.people.service.utils.hessian.HessianDecoder)7 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)6 Contact (com.vodafone360.people.datatypes.Contact)5 Suppress (android.test.suitebuilder.annotation.Suppress)4 Identity (com.vodafone360.people.datatypes.Identity)4 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)3 ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)3 Request (com.vodafone360.people.service.io.Request)3 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)2 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)2