use of android.test.suitebuilder.annotation.Suppress in project 360-Engine-for-Android by 360.
the class ContactSyncEngineTest method testFirstTimeSync_dummyProcessors.
/**
* Verifies that the first time sync triggers a call to the correct
* processors and in the right order.
*/
@Suppress
public // Breaks tests.
void testFirstTimeSync_dummyProcessors() {
// list of the processors in calling order
final ArrayList<Integer> processorTypeList = new ArrayList<Integer>();
// list of expected processors in the right calling order
final ArrayList<Integer> expectedTypeList = new ArrayList<Integer>();
// set the expected processors
expectedTypeList.add(new Integer(ProcessorFactory.DOWNLOAD_SERVER_CONTACTS));
expectedTypeList.add(new Integer(ProcessorFactory.FETCH_NATIVE_CONTACTS));
expectedTypeList.add(new Integer(ProcessorFactory.SYNC_ME_PROFILE));
expectedTypeList.add(new Integer(ProcessorFactory.UPLOAD_SERVER_CONTACTS));
final ProcessorFactory factory = new ProcessorFactory() {
@Override
public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
Log.i(LOG_TAG, "create(), type=" + type);
processorTypeList.add(new Integer(type));
return new DummySyncProcessor(mContactSyncEngine, null);
}
};
final IEngineEventCallback engineEventCallback = new HelperClasses.EngineCallbackBase();
minimalEngineSetup(engineEventCallback, factory);
NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
mContactSyncEngine.addUiStartFullSync();
mContactSyncEngine.run();
// check the processors order
assertTrue(processorTypeList.equals(expectedTypeList));
}
use of android.test.suitebuilder.annotation.Suppress 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 ****");
}
use of android.test.suitebuilder.annotation.Suppress 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 ****");
}
use of android.test.suitebuilder.annotation.Suppress 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());
}
use of android.test.suitebuilder.annotation.Suppress in project 360-Engine-for-Android by 360.
the class NativeContactsApiTest method testUpdateContacts.
@MediumTest
@Suppress
public void testUpdateContacts() {
Account account = null;
if (mUsing2xApi) {
// Add Account for the case where we are in 2.X
mNabApi.addPeopleAccount(PEOPLE_USERNAME);
account = s360PeopleAccount;
threadWait(100);
}
long[] ids = getContactIdsForAllAccounts();
assertNull(ids);
final int numRandomContacts = 10;
for (int i = 0; i < numRandomContacts; i++) {
long id = i;
final ContactChange[] newContactCcList = ContactChangeHelper.randomContact(id, id, -1);
mNabApi.addContact(account, newContactCcList);
// expectedContactId = newIds[0].getNabContactId() + 1;
// GET CONTACT
ids = getContactIdsForAllAccounts();
assertNotNull(ids);
assertEquals(i + 1, ids.length);
final ContactChange[] fetchedContactCcList = mNabApi.getContact(ids[i]);
assertNotNull(fetchedContactCcList);
// UPDATE
final ContactChange[] updateCcList = ContactChangeHelper.randomContactUpdate(fetchedContactCcList);
assertNotNull(updateCcList);
assertTrue(updateCcList.length > 0);
final ContactChange[] updatedIdsCcList = mNabApi.updateContact(updateCcList);
verifyUpdateContactIds(fetchedContactCcList, updateCcList, updatedIdsCcList);
final ContactChange[] updatedContactCcList = ContactChangeHelper.generatedUpdatedContact(newContactCcList, updateCcList);
ids = getContactIdsForAllAccounts();
assertNotNull(ids);
assertEquals(i + 1, ids.length);
final ContactChange[] fetchedUpdatedContactCcList = mNabApi.getContact(ids[i]);
assertNotNull(fetchedUpdatedContactCcList);
if (!ContactChangeHelper.areUnsortedChangeListsEqual(updatedContactCcList, fetchedUpdatedContactCcList, false)) {
// Print update
Log.e(LOG_TAG, "UPDATE FAILED: Print of initial contact follows");
ContactChangeHelper.printContactChangeList(fetchedContactCcList);
Log.e(LOG_TAG, "UPDATE FAILED: Print of failed update follows:");
ContactChangeHelper.printContactChangeList(updateCcList);
// fail test at this point
assertFalse(true);
}
}
// DELETE
final int idCount = ids.length;
for (int i = 0; i < idCount; i++) {
mNabApi.removeContact(ids[i]);
}
ids = getContactIdsForAllAccounts();
assertNull(ids);
}
Aggregations