Search in sources :

Example 6 with Type

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

the class ContactSyncEngineTest method testBackgroundSync.

/**
     * Checks that background sync is performed after the first time sync.
     */
@Suppress
public // Breaks tests.
void testBackgroundSync() {
    Log.i(LOG_TAG, "**** testBackgroundSync() begin ****");
    final ArrayList<ProcessorLog> processorLogs = new ArrayList<ProcessorLog>();
    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);
            ProcessorLog log = new ProcessorLog();
            log.type = type;
            log.time = System.currentTimeMillis();
            processorLogs.add(log);
            return new DummySyncProcessor(mContactSyncEngine, null);
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    // set the connection to be fine
    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, mContactSyncEngine.getNextRunTime());
    // force a first time sync
    mContactSyncEngine.addUiStartFullSync();
    nextRuntime = mContactSyncEngine.getNextRunTime();
    // next runtime should be now
    assertEquals(0, nextRuntime);
    // perform the first time sync
    mContactSyncEngine.run();
    // check that first time sync is completed
    assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
    assertEquals(uiEventCall.status, ServiceStatus.SUCCESS.ordinal());
    // check that a thumbnail sync is scheduled for now
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertEquals(0, nextRuntime);
    // reset the processor logs
    processorLogs.clear();
    // get the thumbnail sync to be run
    mContactSyncEngine.run();
    // check processor calls
    ProcessorLog log;
    assertEquals(2, processorLogs.size());
    log = processorLogs.get(0);
    assertEquals(ProcessorFactory.DOWNLOAD_SERVER_THUMBNAILS, log.type);
    log = processorLogs.get(1);
    assertEquals(ProcessorFactory.UPLOAD_SERVER_THUMBNAILS, log.type);
    // check that native sync is scheduled for now
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertEquals(0, nextRuntime);
    // reset the processor logs
    processorLogs.clear();
    // get the native sync to be run
    mContactSyncEngine.run();
    // check processor calls
    assertEquals(1, processorLogs.size());
    log = processorLogs.get(0);
    assertEquals(ProcessorFactory.UPDATE_NATIVE_CONTACTS, log.type);
    // check that nothing else is scheduled
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertEquals(-1, nextRuntime);
    /*
         * long startingTime = System.currentTimeMillis(); long duration =
         * 60000; long currentTime, timeToWait; while( (currentTime =
         * System.currentTimeMillis()) < (startingTime + duration) ) {
         * nextRuntime = mContactSyncEngine.getNextRunTime(); timeToWait =
         * nextRuntime > currentTime ? (nextRuntime-currentTime) : 0;
         * Log.e(LOG_TAG,
         * "testBackgroundSyncAfterFirstTimeSync(), timeToWait ="+timeToWait);
         * if (timeToWait > 0) { try { synchronized (this) { wait(timeToWait); }
         * } catch(Exception e) { Log.e(LOG_TAG,
         * "testBackgroundSyncAfterFirstTimeSync(), error while waiting: "+e); }
         * } Log.e(LOG_TAG,
         * "testBackgroundSyncAfterFirstTimeSync(), calling run()");
         * mContactSyncEngine.run(); }
         */
    Log.i(LOG_TAG, "**** testBackgroundSync() end ****");
}
Also used : ArrayList(java.util.ArrayList) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) 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)

Example 7 with Type

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

the class ContactSyncEngineTest method testCancelSync.

/**
     * Tests the sync is cancelled in case we remove user data.
     */
@Suppress
public // Breaks tests.
void testCancelSync() {
    Log.i(LOG_TAG, "**** testNativeSync_newEngineInstantiation() begin ****");
    final ArrayList<ProcessorLog> processorLogs = new ArrayList<ProcessorLog>();
    final UiEventCall uiEventCall = new UiEventCall();
    final ProcessorLog processorLog = new ProcessorLog();
    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);
            ProcessorLog log = new ProcessorLog();
            log.type = type;
            log.time = System.currentTimeMillis();
            processorLogs.add(log);
            return new BaseSyncProcessor(mContactSyncEngine, null) {

                @Override
                protected void doCancel() {
                    // cancel the job
                    processorLog.type = 1;
                }

                @Override
                protected void doStart() {
                    // set a "timeout" to be called back immediately
                    setTimeout(0);
                    processorLog.type = 2;
                }

                @Override
                public void onTimeoutEvent() {
                    // set the job as completed
                    Log.i(LOG_TAG, "onTimeoutEvent()");
                    complete(ServiceStatus.SUCCESS);
                    processorLog.type = 3;
                }

                @Override
                public void processCommsResponse(DecodedResponse resp) {
                    // we don't need this case in this test
                    processorLog.type = 4;
                }
            };
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    // set the connection to be fine
    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);
    // force a first time sync
    mContactSyncEngine.addUiStartFullSync();
    processorLog.type = 0;
    // start performing the sync
    mContactSyncEngine.run();
    // the first processor should have started
    assertTrue(processorLog.type == 2);
    // this will cancel any sync
    mContactSyncEngine.onReset();
    // get the engine to perform a cancel on the current processor
    mContactSyncEngine.run();
    assertTrue(processorLog.type == 1);
    // check that the engine cancelled the sync
    assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
    assertEquals(uiEventCall.status, ServiceStatus.USER_CANCELLED.ordinal());
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ArrayList(java.util.ArrayList) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) BaseSyncProcessor(com.vodafone360.people.engine.contactsync.BaseSyncProcessor) 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)

Example 8 with Type

use of com.vodafone360.people.service.io.Request.Type 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 9 with Type

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

the class ActivitiesEngineTest method testMessageLog.

/*
     * @MediumTest public void testGetTimelineEvent(){ boolean testPass = true;
     * mState = ActivityTestState.GET_TIMELINE_EVENT_FROM_SERVER; Contact
     * meProfile = mTestModule.createDummyContactData(); ServiceStatus status =
     * mApplication.getDatabase().setMeProfile(meProfile); if(status !=
     * ServiceStatus.SUCCESS){ throw(new
     * RuntimeException("Could not access db")); }
     * mEng.addUiGetActivitiesRequest(); status = mEngineTester.waitForEvent();
     * if(status != ServiceStatus.SUCCESS){ throw(new
     * RuntimeException("Expected SUCCESS")); } Object data =
     * mEngineTester.data(); assertTrue(data==null);
     * mEng.addUiGetActivitiesRequest(); status = mEngineTester.waitForEvent();
     * if(status != ServiceStatus.SUCCESS){ throw(new
     * RuntimeException("Expected SUCCESS")); } data = mEngineTester.data();
     * assertTrue(data==null); assertTrue("testPushMessage() failed", testPass);
     * Log.i(LOG_TAG, "**** testGetTimelineEvent (SUCCESS) ****\n"); }
     */
@MediumTest
// Takes too long.
@Suppress
public void testMessageLog() {
    final String ADDRESS = "address";
    // final String PERSON = "person";
    final String DATE = "date";
    final String READ = "read";
    final String STATUS = "status";
    final String TYPE = "type";
    final String BODY = "body";
    ContentValues values = new ContentValues();
    values.put(ADDRESS, "+61408219690");
    values.put(DATE, "1630000000000");
    values.put(READ, 1);
    values.put(STATUS, -1);
    values.put(TYPE, 2);
    values.put(BODY, "SMS inserting test");
    /* Uri inserted = */
    mApplication.getContentResolver().insert(Uri.parse("content://sms"), values);
    mState = ActivityTestState.GET_ACTIVITIES_SUCCESS;
    // re-test with valid Me profile
    Contact meProfile = mTestModule.createDummyContactData();
    assertEquals("Could not access db", ServiceStatus.SUCCESS, SyncMeDbUtils.setMeProfile(mApplication.getDatabase(), meProfile));
    mEng.addStatusesSyncRequest();
    assertEquals("Expected SUCCESS, not timeout", ServiceStatus.SUCCESS, mEngineTester.waitForEvent());
    Object data = mEngineTester.data();
    assertTrue(data == null);
    values.put(DATE, "1650000000000");
    /* inserted = */
    mApplication.getContentResolver().insert(Uri.parse("content://mms"), values);
    mEng.addStatusesSyncRequest();
    assertEquals("Could not access db", ServiceStatus.SUCCESS, mEngineTester.waitForEvent());
    Log.i(LOG_TAG, "**** testGetActivities (SUCCESS) ****\n");
}
Also used : ContentValues(android.content.ContentValues) ActivityContact(com.vodafone360.people.datatypes.ActivityContact) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 10 with Type

use of com.vodafone360.people.service.io.Request.Type 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

ArrayList (java.util.ArrayList)14 Suppress (android.test.suitebuilder.annotation.Suppress)13 DatabaseHelper (com.vodafone360.people.database.DatabaseHelper)11 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)11 IEngineEventCallback (com.vodafone360.people.engine.IEngineEventCallback)11 IContactSyncCallback (com.vodafone360.people.engine.contactsync.IContactSyncCallback)11 ProcessorFactory (com.vodafone360.people.engine.contactsync.ProcessorFactory)11 ServiceStatus (com.vodafone360.people.service.ServiceStatus)10 ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)10 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)7 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)6 Identity (com.vodafone360.people.datatypes.Identity)6 Request (com.vodafone360.people.service.io.Request)5 Cursor (android.database.Cursor)4 Contact (com.vodafone360.people.datatypes.Contact)4 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)4 ServerError (com.vodafone360.people.datatypes.ServerError)4 SQLException (android.database.SQLException)3 SQLiteException (android.database.sqlite.SQLiteException)3 Bundle (android.os.Bundle)3