AbstractTableMergerTestpublic class AbstractTableMergerTest extends android.test.AndroidTestCase Unit test for {@link android.content.AbstractTableMerger}. |
Fields Summary |
---|
MockSyncableContentProvider | mRealProvider | MockSyncableContentProvider | mTempProvider | MockTableMerger | mMerger | MockSyncContext | mSyncContext | static final String | TABLE_NAME | static final String | DELETED_TABLE_NAME | static final android.net.Uri | CONTENT_URI | static final android.net.Uri | TABLE_URI | static final android.net.Uri | DELETED_TABLE_URI | private final String | ACCOUNT | private final ArrayList | mExpectations |
Methods Summary |
---|
ContentValues | newDeletedValues(java.lang.String syncId, java.lang.String syncAccount, java.lang.String syncVersion, java.lang.Long syncLocalId)
ContentValues values = new ContentValues();
if (syncVersion != null) values.put("_sync_version", syncVersion);
if (syncId != null) values.put("_sync_id", syncId);
if (syncAccount != null) values.put("_sync_account", syncAccount);
if (syncLocalId != null) values.put("_sync_local_id", syncLocalId);
return values;
| ContentValues | newModifyData(java.lang.String data)
ContentValues values = new ContentValues();
values.put("data", data);
values.put("_sync_dirty", 1);
return values;
| ContentValues | newValues(java.lang.String data, java.lang.String syncId, java.lang.String syncAccount, java.lang.String syncTime, java.lang.String syncVersion, java.lang.Long syncLocalId)
ContentValues values = new ContentValues();
if (data != null) values.put("data", data);
if (syncTime != null) values.put("_sync_time", syncTime);
if (syncVersion != null) values.put("_sync_version", syncVersion);
if (syncId != null) values.put("_sync_id", syncId);
if (syncAccount != null) values.put("_sync_account", syncAccount);
values.put("_sync_local_id", syncLocalId);
values.put("_sync_dirty", 0);
return values;
| protected void | setUp()
super.setUp();
mSyncContext = new MockSyncContext();
mRealProvider = new MockSyncableContentProvider();
mTempProvider = mRealProvider.getTemporaryInstance();
mMerger = new MockTableMerger(mRealProvider.getDatabase(),
TABLE_NAME, TABLE_URI, DELETED_TABLE_NAME, DELETED_TABLE_URI);
mExpectations.clear();
| public void | testDeleteRowAfterDelete()
// add rows to the real provider
Uri i1 = mRealProvider.insert(TABLE_URI,
newValues("d1", "si1", ACCOUNT, "st1", "sv1", null));
// add a deleted record to the temp provider
ContentValues row1 = newDeletedValues(null, null, null, ContentUris.parseId(i1));
mTempProvider.insert(DELETED_TABLE_URI, row1);
// add expected callbacks to merger
mExpectations.add(new Expectation(Expectation.Type.DELETE, ContentUris.parseId(i1), null));
// run merger
SyncResult syncResult = new SyncResult();
mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult);
// check that all expectations were met
assertEquals("not all expectations were met", 0, mExpectations.size());
| public void | testDeleteRowAfterInsert()
// add rows to the real provider
Uri i1 = mRealProvider.insert(TABLE_URI, newModifyData("d1"));
// add a deleted record to the temp provider
ContentValues row1 = newDeletedValues(null, null, null, ContentUris.parseId(i1));
mTempProvider.insert(DELETED_TABLE_URI, row1);
// add expected callbacks to merger
mExpectations.add(new Expectation(Expectation.Type.DELETE, ContentUris.parseId(i1), null));
// run merger
SyncResult syncResult = new SyncResult();
mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult);
// check that all expectations were met
assertEquals("not all expectations were met", 0, mExpectations.size());
| public void | testDeleteRowAfterUpdate()
// add rows to the real provider
Uri i1 = mRealProvider.insert(TABLE_URI,
newValues("d1", "si1", ACCOUNT, "st1", "sv1", null));
// add a deleted record to the temp provider
ContentValues row1 = newDeletedValues("si1", ACCOUNT, "sv1", ContentUris.parseId(i1));
mTempProvider.insert(DELETED_TABLE_URI, row1);
// add expected callbacks to merger
mExpectations.add(new Expectation(Expectation.Type.DELETE, ContentUris.parseId(i1), null));
// run merger
SyncResult syncResult = new SyncResult();
mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult);
// check that all expectations were met
assertEquals("not all expectations were met", 0, mExpectations.size());
| public void | testDeleteRowFromServer()
// add rows to the real provider
Uri i1 = mRealProvider.insert(TABLE_URI,
newValues("d1", "si1", ACCOUNT, "st1", "sv1", null));
// add a deleted record to the temp provider
ContentValues row1 = newDeletedValues("si1", ACCOUNT, "sv1", null);
mTempProvider.insert(DELETED_TABLE_URI, row1);
// add expected callbacks to merger
mExpectations.add(new Expectation(Expectation.Type.DELETE, ContentUris.parseId(i1), null));
// run merger
SyncResult syncResult = new SyncResult();
mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult);
// check that all expectations were met
assertEquals("not all expectations were met", 0, mExpectations.size());
| public void | testInsert()
// add rows to the real provider
// add new row to the temp provider
final ContentValues row1 = newValues("d1", "si1", ACCOUNT, "st1", "sv1", null);
mTempProvider.insert(TABLE_URI, row1);
// add expected callbacks to merger
mExpectations.add(new Expectation(Expectation.Type.INSERT, null /* syncLocalId */, row1));
// run merger
SyncResult syncResult = new SyncResult();
mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult);
// check that all expectations were met
assertEquals("not all expectations were met", 0, mExpectations.size());
| public void | testResolve()
// add rows to the real provider
Uri i1 = mRealProvider.insert(TABLE_URI,
newValues("d1", "si1", ACCOUNT, "st1", "sv1", null));
mRealProvider.update(TABLE_URI, newModifyData("d2"), null, null);
// add row to the temp provider that matches a dirty, synced row in the real provider
final ContentValues row1 = newValues("d3", "si1", ACCOUNT, "st2", "sv2", null);
mTempProvider.insert(TABLE_URI, row1);
// add expected callbacks to merger
mExpectations.add(new Expectation(Expectation.Type.RESOLVE, ContentUris.parseId(i1), row1));
// run merger
SyncResult syncResult = new SyncResult();
mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult);
// check that all expectations were met
assertEquals("not all expectations were met", 0, mExpectations.size());
| public void | testResolveWithLocalId()
// add rows to the real provider
Uri i1 = mRealProvider.insert(TABLE_URI,
newValues("d1", "si1", ACCOUNT, "st1", "sv1", null));
mRealProvider.update(TABLE_URI, newModifyData("d2"), null, null);
// add row to the temp provider that matches a dirty, synced row in the real provider
ContentValues row1 = newValues("d2", "si1", ACCOUNT, "st2", "sv2", ContentUris.parseId(i1));
mTempProvider.insert(TABLE_URI, row1);
// add expected callbacks to merger
mExpectations.add(new Expectation(Expectation.Type.UPDATE, ContentUris.parseId(i1), row1));
// run merger
SyncResult syncResult = new SyncResult();
mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult);
// check that all expectations were met
assertEquals("not all expectations were met", 0, mExpectations.size());
| public void | testUpdateWithLocalId()
// add rows to the real provider
// add new row to the temp provider that matches an unsynced row in the real provider
final ContentValues row1 = newValues("d1", "si1", ACCOUNT, "st1", "sv1", 11L);
mTempProvider.insert(TABLE_URI, row1);
// add expected callbacks to merger
mExpectations.add(new Expectation(Expectation.Type.UPDATE, 11L, row1));
// run merger
SyncResult syncResult = new SyncResult();
mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult);
// check that all expectations were met
assertEquals("not all expectations were met", 0, mExpectations.size());
| public void | testUpdateWithoutLocalId()
// add rows to the real provider
Uri i1 = mRealProvider.insert(TABLE_URI,
newValues("d1", "si1", ACCOUNT, "st1", "sv1", null));
// add new row to the temp provider that matches an unsynced row in the real provider
final ContentValues row1 = newValues("d2", "si1", ACCOUNT, "st2", "sv2", null);
mTempProvider.insert(TABLE_URI, row1);
// add expected callbacks to merger
mExpectations.add(new Expectation(Expectation.Type.UPDATE, ContentUris.parseId(i1), row1));
// run merger
SyncResult syncResult = new SyncResult();
mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult);
// check that all expectations were met
assertEquals("not all expectations were met", 0, mExpectations.size());
|
|