Search in sources :

Example 1 with BaseDataType

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

the class DownloadServerContactsTest method reportBackToEngine.

@Override
public void reportBackToEngine(int reqId, EngineId engine) {
    Log.d(LOG_TAG, "reportBackToEngine");
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    try {
        assertEquals(mEng.engineId(), engine);
        switch(mState) {
            case RUN_WITH_NO_CHANGES:
                reportBackWithNoChanges(reqId, data);
                break;
            case RUN_WITH_NEW_CONTACTS:
                reportBackWithNewContacts(reqId, data);
                break;
            case RUN_WITH_DELETED_CONTACTS:
                reportBackWithDeletedContacts(reqId, data);
                break;
            case RUN_WITH_MODIFIED_CONTACTS:
                reportBackWithModifiedContacts(reqId, data);
                break;
            case RUN_WITH_DELETED_DETAILS:
                reportBackWithDeletedDetails(reqId, data);
                break;
            default:
                fail("Unexpected request rom processor");
        }
    } catch (Throwable err) {
        ServerError serverError = new ServerError(ServerError.ErrorType.INTERNALERROR);
        serverError.errorDescription = err + "\n";
        for (int i = 0; i < err.getStackTrace().length; i++) {
            StackTraceElement v = err.getStackTrace()[i];
            serverError.errorDescription += "\t" + v + "\n";
        }
        Log.e(LOG_TAG, "Exception:\n" + serverError.errorDescription);
        data.clear();
        data.add(serverError);
    }
    respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
    mEng.onCommsInMessage();
    Log.d(LOG_TAG, "reportBackToEngine - message added to response queue");
}
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)

Example 2 with BaseDataType

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

the class DownloadServerContactsTest method reportBackWithModifiedContacts.

private void reportBackWithModifiedContacts(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportBackWithModifiedContacts");
    Integer pageNo = mProcessor.testGetPageFromReqId(reqId);
    int pageSize = mProcessor.getDownloadPageSize();
    assertTrue(pageNo != null);
    assertEquals(Integer.valueOf(mPageCount), pageNo);
    ContactChanges contactChanges = new ContactChanges();
    data.add(contactChanges);
    contactChanges.mCurrentServerVersion = CURRENT_SERVER_VERSION;
    contactChanges.mServerRevisionBefore = CURRENT_SERVER_VERSION;
    contactChanges.mServerRevisionAfter = CURRENT_SERVER_VERSION;
    contactChanges.mVersionAnchor = CURRENT_SERVER_VERSION;
    assertTrue(pageSize > 0);
    if (pageSize > 0) {
        contactChanges.mNumberOfPages = 1 + mPageCount + (mItemCount / pageSize);
    }
    int noOfContacts = Math.min(pageSize, mItemCount);
    for (int i = 0; i < noOfContacts; i++) {
        Contact modifiedContact = new Contact();
        modifiedContact.contactID = FIRST_MODIFIED_CONTACT_ID + mItemCount - 1;
        // Modified details
        ContactDetail detail1 = new ContactDetail();
        detail1.key = ContactDetail.DetailKeys.VCARD_NICKNAME;
        detail1.value = generateModifiedString(MODIFIED_NICKNAME_STRING, mItemCount - 1);
        modifiedContact.details.add(detail1);
        ContactDetail detail2 = new ContactDetail();
        detail2.key = ContactDetail.DetailKeys.VCARD_PHONE;
        detail2.keyType = MODIFIED_PHONE_TYPE;
        detail2.order = MODIFIED_PHONE_ORDER;
        detail2.value = generateModifiedString(MODIFIED_PHONE_STRING, mItemCount - 1);
        detail2.unique_id = OLD_PHONE_DETAIL_ID + mItemCount - 1;
        modifiedContact.details.add(detail2);
        // New details
        ContactDetail detail3 = new ContactDetail();
        detail3.key = ContactDetail.DetailKeys.VCARD_PHONE;
        detail3.keyType = NEW_PHONE_TYPE;
        detail3.order = NEW_PHONE_ORDER;
        detail3.value = generateModifiedString(NEW_PHONE_STRING, mItemCount - 1);
        detail3.unique_id = NEW_PHONE_DETAIL_ID + mItemCount - 1;
        modifiedContact.details.add(detail3);
        ContactDetail detail4 = new ContactDetail();
        detail4.key = ContactDetail.DetailKeys.VCARD_EMAIL;
        detail4.keyType = NEW_EMAIL_TYPE;
        detail4.order = NEW_EMAIL_ORDER;
        detail4.value = generateModifiedString(NEW_EMAIL_STRING, mItemCount - 1);
        detail4.unique_id = NEW_EMAIL_DETAIL_ID + mItemCount - 1;
        modifiedContact.details.add(detail4);
        Log.d(LOG_TAG, "Contact " + modifiedContact.contactID + " has details " + detail1.unique_id + ", " + detail2.unique_id + ", " + detail3.unique_id + ", " + detail4.unique_id);
        contactChanges.mContacts.add(modifiedContact);
        mItemCount--;
    }
    mPageCount++;
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        nextState(State.IDLE);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChanges(com.vodafone360.people.datatypes.ContactChanges) Contact(com.vodafone360.people.datatypes.Contact)

Example 3 with BaseDataType

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

the class IdentityEngineTest method reportBackToEngine.

@Override
public void reportBackToEngine(int reqId, EngineId engine) {
    Log.d("TAG", "IdentityEngineTest.reportBackToEngine");
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    switch(mState) {
        case IDLE:
            break;
        case FETCH_IDENTITIES:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine FETCH ids");
            Identity id = new Identity();
            data.add(id);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine add to Q");
            mEng.onCommsInMessage();
            break;
        case GET_MY_IDENTITIES:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine Get ids");
            Identity myId = new Identity();
            data.add(myId);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine add to Q");
            mEng.onCommsInMessage();
            break;
        case FETCH_IDENTITIES_FAIL:
            ServerError err = new ServerError("Catastrophe");
            err.errorDescription = "Fail";
            data.add(err);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case SET_IDENTITY_CAPABILTY:
            StatusMsg msg = new StatusMsg();
            msg.mCode = "ok";
            msg.mDryRun = false;
            msg.mStatus = true;
            data.add(msg);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SET_IDENTITY_CAPABILITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case VALIDATE_ID_CREDENTIALS_SUCCESS:
            StatusMsg msg2 = new StatusMsg();
            msg2.mCode = "ok";
            msg2.mDryRun = false;
            msg2.mStatus = true;
            data.add(msg2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.VALIDATE_IDENTITY_CREDENTIALS_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case VALIDATE_ID_CREDENTIALS_FAIL:
            ServerError err2 = new ServerError("Catastrophe");
            err2.errorDescription = "Fail";
            data.add(err2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_NEXT_RUNTIME:
            break;
        case GET_CHATABLE_IDENTITIES:
        case FETCH_IDENTITIES_POPULATED:
            Identity id2 = new Identity();
            id2.mActive = true;
            id2.mAuthType = "auth";
            List<String> clist = new ArrayList<String>();
            clist.add("uk");
            clist.add("fr");
            id2.mCountryList = clist;
            id2.mCreated = new Long(0);
            id2.mDisplayName = "Facebook";
            // id2.mIcon2Mime = "jpeg";
            id2.mIconMime = "jpeg";
            try {
                id2.mIcon2Url = new URL("url2");
                id2.mIconUrl = new URL("url");
                id2.mNetworkUrl = new URL("network");
            } catch (Exception e) {
            }
            id2.mIdentityId = "fb";
            id2.mIdentityType = "type";
            id2.mName = "Facebook";
            id2.mNetwork = "Facebook";
            id2.mOrder = 0;
            id2.mPluginId = "";
            id2.mUpdated = new Long(0);
            id2.mUserId = 23;
            id2.mUserName = "user";
            data.add(id2);
            List<IdentityCapability> capList = new ArrayList<IdentityCapability>();
            IdentityCapability idcap = new IdentityCapability();
            idcap.mCapability = IdentityCapability.CapabilityID.sync_contacts;
            idcap.mDescription = "sync cont";
            idcap.mName = "sync cont";
            idcap.mValue = true;
            capList.add(idcap);
            id2.mCapabilities = capList;
            data.add(id2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine add to Q");
            mEng.onCommsInMessage();
            break;
        default:
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) StatusMsg(com.vodafone360.people.datatypes.StatusMsg) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) URL(java.net.URL) IdentityCapability(com.vodafone360.people.datatypes.IdentityCapability) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue) Identity(com.vodafone360.people.datatypes.Identity)

Example 4 with BaseDataType

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

the class ActivitiesEngineTest method testPushMessage.

@Suppress
@MediumTest
public void testPushMessage() {
    boolean testPass = true;
    mState = ActivityTestState.GET_ACTIVITIES_SUCCESS;
    // create test Push msg and put it is response Q
    PushEvent evt = new PushEvent();
    evt.mMessageType = PushMessageTypes.STATUS_ACTIVITY_CHANGE;
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    data.add(evt);
    NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
    ResponseQueue.getInstance().addToResponseQueue(new DecodedResponse(0, data, mEng.engineId(), DecodedResponse.ResponseType.PUSH_MESSAGE.ordinal()));
    mEng.onCommsInMessage();
    // see if anything happens
    assertEquals("Expected SUCCESS, not timeout", ServiceStatus.SUCCESS, mEngineTester.waitForEvent());
    Object retdata = mEngineTester.data();
    assertTrue(retdata == null);
    assertTrue("testPushMessage() failed", testPass);
    Log.i(LOG_TAG, "**** testPushMessage (SUCCESS) ****\n");
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) PushEvent(com.vodafone360.people.datatypes.PushEvent) ArrayList(java.util.ArrayList) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 5 with BaseDataType

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

the class ActivitiesEngineTest method reportBackToEngine.

@Override
public void reportBackToEngine(int reqId, EngineId engine) {
    Log.d("TAG", "IdentityEngineTest.reportBackToEngine");
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    switch(mState) {
        case IDLE:
            break;
        case ON_CREATE:
        case ON_DESTROY:
            break;
        case GET_ACTIVITIES_SUCCESS:
            ActivityItem item = new ActivityItem();
            data.add(item);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_TIMELINE_EVENT_FROM_SERVER:
            ActivityItem item2 = new ActivityItem();
            ActivityContact act = new ActivityContact();
            act.mName = "Bill Fleege";
            act.mLocalContactId = new Long(8);
            List<ActivityContact> clist = new ArrayList<ActivityContact>();
            clist.add(act);
            item2.contactList = clist;
            item2.activityFlags = 2;
            item2.type = ActivityItem.Type.CONTACT_JOINED;
            item2.time = System.currentTimeMillis();
            data.add(item2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_POPULATED_ACTIVITIES:
            ActivityItem item3 = new ActivityItem();
            ActivityContact act2 = new ActivityContact();
            act2.mName = "Bill Fleege";
            act2.mLocalContactId = new Long(8);
            List<ActivityContact> clist2 = new ArrayList<ActivityContact>();
            clist2.add(act2);
            item3.contactList = clist2;
            item3.activityFlags = 2;
            item3.type = ActivityItem.Type.CONTACT_JOINED;
            item3.time = System.currentTimeMillis();
            item3.title = "bills new status";
            item3.description = "a description";
            data.add(item3);
            ActivityItem item4 = new ActivityItem();
            item4.contactList = clist2;
            item4.activityFlags = 5;
            item4.type = ActivityItem.Type.CONTACT_JOINED;
            item4.time = System.currentTimeMillis();
            item4.title = "bills new status";
            item4.description = "a description";
            item4.activityId = new Long(23);
            item4.hasChildren = false;
            item4.uri = "uri";
            item4.parentActivity = new Long(0);
            item4.preview = ByteBuffer.allocate(46);
            item4.preview.position(0);
            item4.preview.rewind();
            for (int i = 0; i < 23; i++) {
                item4.preview.putChar((char) i);
            }
            item4.previewMime = "jepg";
            item4.previewUrl = "storeurl";
            item4.store = "google";
            item4.visibilityFlags = 0;
            data.add(item4);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_ACTIVITIES_SERVER_ERR:
            ServerError err = new ServerError("Catastrophe");
            err.errorDescription = "Fail";
            data.add(err);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_ACTIVITIES_UNEXPECTED_RESPONSE:
            StatusMsg msg = new StatusMsg();
            msg.mCode = "ok";
            msg.mDryRun = false;
            msg.mStatus = true;
            data.add(msg);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case SET_STATUS:
            Identity id3 = new Identity();
            data.add(id3);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case ON_SYNC_COMPLETE:
            ServerError err2 = new ServerError("Catastrophe");
            err2.errorDescription = "Fail";
            data.add(err2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_NEXT_RUNTIME:
            break;
        default:
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) StatusMsg(com.vodafone360.people.datatypes.StatusMsg) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) ActivityContact(com.vodafone360.people.datatypes.ActivityContact) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue) Identity(com.vodafone360.people.datatypes.Identity) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Aggregations

BaseDataType (com.vodafone360.people.datatypes.BaseDataType)29 ArrayList (java.util.ArrayList)25 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)21 ServiceStatus (com.vodafone360.people.service.ServiceStatus)15 ServerError (com.vodafone360.people.datatypes.ServerError)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)9 Contact (com.vodafone360.people.datatypes.Contact)9 IOException (java.io.IOException)9 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)8 Identity (com.vodafone360.people.datatypes.Identity)7 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)7 HessianDecoder (com.vodafone360.people.service.utils.hessian.HessianDecoder)7 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)6 ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)5 PushEvent (com.vodafone360.people.datatypes.PushEvent)5 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)5 Bundle (android.os.Bundle)3 Suppress (android.test.suitebuilder.annotation.Suppress)3 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)3 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)3