Search in sources :

Example 11 with ServerError

use of com.vodafone360.people.datatypes.ServerError in project 360-Engine-for-Android by 360.

the class EngineTestFramework method reportBackToFramework.

@Override
public void reportBackToFramework(int reqId, EngineId engine) {
    Log.d("TAG", "EngineTestFramework.reportBackToFramework");
    mObserver.reportBackToEngine(reqId, engine);
    final QueueManager reqQ = QueueManager.getInstance();
    final ResponseQueue respQ = ResponseQueue.getInstance();
    if (reqQ.getRequest(reqId) != null) {
        List<BaseDataType> dataTypeList = new ArrayList<BaseDataType>();
        ServerError err = new ServerError(ServerError.ErrorType.UNKNOWN);
        dataTypeList.add(err);
        respQ.addToResponseQueue(new DecodedResponse(reqId, dataTypeList, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 12 with ServerError

use of com.vodafone360.people.datatypes.ServerError in project 360-Engine-for-Android by 360.

the class LoginEngineTest method reportBackToEngine.

@Override
public void reportBackToEngine(int reqId, EngineId engine) {
    Log.d("TAG", "LoginEngineTest.reportBackToEngine");
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    switch(mState) {
        case IDLE:
            break;
        case LOGIN_REQUEST:
        case SMS_RESPONSE_SIGNIN:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine FETCH ids");
            StatusMsg msg = new StatusMsg();
            data.add(msg);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            mState = LoginTestState.LOGIN_REQUEST_VALID;
            break;
        case LOGIN_REQUEST_VALID:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine FETCH ids");
            AuthSessionHolder sesh = new AuthSessionHolder();
            data.add(sesh);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            mState = LoginTestState.SMS_RESPONSE_SIGNIN;
            break;
        case REGISTRATION:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine Registration");
            data.add(mTestModule.createDummyContactData());
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SIGNUP_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case REGISTRATION_ERROR:
            data.add(new ServerError(ServerError.ErrorType.UNKNOWN));
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_T_AND_C:
        case FETCH_PRIVACY:
        case USER_NAME_STATE:
            SimpleText txt = new SimpleText();
            txt.addText("Simple text");
            data.add(txt);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_T_AND_C_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case SERVER_ERROR:
            data.add(new ServerError(ServerError.ErrorType.UNKNOWN));
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        default:
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) StatusMsg(com.vodafone360.people.datatypes.StatusMsg) SimpleText(com.vodafone360.people.datatypes.SimpleText) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue)

Example 13 with ServerError

use of com.vodafone360.people.datatypes.ServerError 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)

Aggregations

BaseDataType (com.vodafone360.people.datatypes.BaseDataType)12 ServerError (com.vodafone360.people.datatypes.ServerError)12 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)12 ArrayList (java.util.ArrayList)11 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)7 Identity (com.vodafone360.people.datatypes.Identity)3 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)3 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)2 Request (com.vodafone360.people.service.io.Request)2 IOException (java.io.IOException)2 MediumTest (android.test.suitebuilder.annotation.MediumTest)1 Suppress (android.test.suitebuilder.annotation.Suppress)1 ActivityContact (com.vodafone360.people.datatypes.ActivityContact)1 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)1 ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)1 IdentityCapability (com.vodafone360.people.datatypes.IdentityCapability)1 SimpleText (com.vodafone360.people.datatypes.SimpleText)1 EngineId (com.vodafone360.people.engine.EngineManager.EngineId)1 ServiceStatus (com.vodafone360.people.service.ServiceStatus)1 QueueManager (com.vodafone360.people.service.io.QueueManager)1