Search in sources :

Example 1 with Request

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

the class ContactSyncEngineTest method testUiRequestCompleteEvent_serverSync.

/**
     * Verifies that server sync completes correctly.
     */
@Suppress
public // Breaks tests.
void testUiRequestCompleteEvent_serverSync() {
    Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_serverSync() begin ****");
    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);
            return new DummySyncProcessor(mContactSyncEngine, null);
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    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);
    // set the connection to be fine
    NetworkAgent.setAgentState(AgentState.CONNECTED);
    // ask for a full sync
    mContactSyncEngine.addUiStartFullSync();
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertEquals(0, nextRuntime);
    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 first time sync is completed
    assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
    assertEquals(uiEventCall.status, ServiceStatus.SUCCESS.ordinal());
    Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_serverSync() end ****");
}
Also used : DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) 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 2 with Request

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

the class ContactSyncEngineTest method testEventCallback.

/**
     * Checks that the engine events are correctly sent to listeners.
     */
@Suppress
public // Breaks tests.
void testEventCallback() {
    Log.i(LOG_TAG, "**** testEventCallback() begin ****");
    // Set up the expected events
    final ArrayList<ContactSyncObserver.ContactSyncStateChanged> expectedCssc = new ArrayList<ContactSyncObserver.ContactSyncStateChanged>();
    final ArrayList<ContactSyncObserver.ProgressEvent> expectedPe = new ArrayList<ContactSyncObserver.ProgressEvent>();
    final ArrayList<ContactSyncObserver.SyncComplete> expectedSc = new ArrayList<ContactSyncObserver.SyncComplete>();
    setupExpectedFirstTimeSyncObserverCalls(expectedCssc, expectedPe, expectedSc);
    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);
            return new DummySyncProcessor(mContactSyncEngine, null);
        }
    };
    final ContactSyncObserver observer = new ContactSyncObserver();
    minimalEngineSetup(engineEventCallback, factory);
    NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
    // add a listener
    mContactSyncEngine.addEventCallback(observer);
    // ask for a full sync
    mContactSyncEngine.addUiStartFullSync();
    // perform the sync
    mContactSyncEngine.run();
    // compare the retrieved events with the expected ones
    assertTrue(expectedCssc.equals(observer.mCsscList));
    assertTrue(expectedPe.equals(observer.mPeList));
    assertTrue(expectedSc.equals(observer.mScList));
    Log.i(LOG_TAG, "**** testEventCallback() 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) IContactSyncObserver(com.vodafone360.people.engine.contactsync.ContactSyncEngine.IContactSyncObserver) IEngineEventCallback(com.vodafone360.people.engine.IEngineEventCallback) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 3 with Request

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

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

the class ContactSyncEngineTest method testAutoSyncTimer.

/**
     * Checks that nothing is scheduled before the first time sync has been
     * completed.
     */
@Suppress
public void testAutoSyncTimer() {
    Log.i(LOG_TAG, "**** testAutoSyncTimer() begin ****");
    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);
        }
    };
    final ProcessorFactory factory = new ProcessorFactory() {

        @Override
        public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
            Log.i(LOG_TAG, "create(), type=" + type);
            return new DummySyncProcessor(mContactSyncEngine, null);
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    // set the connection to be fine
    NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
    // should be equal to -1 because first time sync has not been yet
    // started
    assertEquals(-1, mContactSyncEngine.getNextRunTime());
    mContactSyncEngine.run();
    assertEquals(-1, mContactSyncEngine.getNextRunTime());
    mContactSyncEngine.run();
    assertEquals(-1, mContactSyncEngine.getNextRunTime());
    Log.i(LOG_TAG, "**** testAutoSyncTimer() end ****");
}
Also used : DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) 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 5 with Request

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

Aggregations

Request (com.vodafone360.people.service.io.Request)43 QueueManager (com.vodafone360.people.service.io.QueueManager)27 ServiceStatus (com.vodafone360.people.service.ServiceStatus)16 ArrayList (java.util.ArrayList)16 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)12 ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)12 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)11 Suppress (android.test.suitebuilder.annotation.Suppress)10 DatabaseHelper (com.vodafone360.people.database.DatabaseHelper)9 IEngineEventCallback (com.vodafone360.people.engine.IEngineEventCallback)9 IContactSyncCallback (com.vodafone360.people.engine.contactsync.IContactSyncCallback)9 ProcessorFactory (com.vodafone360.people.engine.contactsync.ProcessorFactory)9 ServerError (com.vodafone360.people.datatypes.ServerError)6 IOException (java.io.IOException)6 Identity (com.vodafone360.people.datatypes.Identity)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Bundle (android.os.Bundle)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)4 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)4 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)4