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);
}
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;
}
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);
}
}
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");
}
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);
}
Aggregations