use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class NowPlusNativeChangeTableTest method testServerDeleteContactDetail.
/*
@MediumTest
public void testServerAddContactDetail() {
final String fnName = "testServerAddContactDetail";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "Add new contact details to the change log, validating all the way");
startSubTest(fnName, "Creating table");
createTable();
startSubTest(fnName, "Check change log is empty");
long noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail with null local contact ID to change log (error expected)");
final Integer nativeId = mTestModule.GenerateRandomInt();
ContactDetail testDetail = mTestModule.createDummyDetailsName();
ContactDetail testDetail2 = new ContactDetail();
testDetail.localDetailID = mTestModule.GenerateRandomLong();
testDetail.nativeContactId = nativeId;
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = testDetail.key;
testDetail2.nativeContactId = testDetail.nativeContactId;
assertFalse(NativeChangeLogTable.addNewContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail with null local detail ID to change log (error expected)");
testDetail.localContactID = mTestModule.GenerateRandomLong();
testDetail2.localDetailID = null;
assertFalse(NativeChangeLogTable.addNewContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail with null key to change log (error expected)");
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = null;
assertFalse(NativeChangeLogTable.addNewContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log is still empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add valid contact detail to change log");
final List<Long> changeIdxList = new ArrayList<Long>();
assertTrue(NativeChangeLogTable.addNewContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
Cursor cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
ContactChangeInfo info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mNativeContactId, testDetail.nativeContactId);
assertEquals(info.mNativeDetailId, testDetail.nativeDetailId);
assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.NEW_DETAIL);
assertTrue(testDetail.nativeDetailId == null);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail with null native ID to change log when add contact is not in list (should add a new contact change)");
assertTrue(NativeChangeLogTable.addNewContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mNativeContactId, testDetail.nativeContactId);
assertTrue(info.mNativeDetailId == null);
assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.NEW_DETAIL);
assertTrue(testDetail.nativeDetailId == null);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add new contact log...");
assertTrue(NativeChangeLogTable.addNewContactChange(testDetail.localContactID, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by new detail log with no server ID");
assertTrue(NativeChangeLogTable.addNewContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 2);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_CONTACT, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact deleted log...");
assertTrue(NativeChangeLogTable.addDeletedContactChange(testDetail.localContactID, nativeId, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by new detail log (error expected)");
assertFalse(NativeChangeLogTable.addNewContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_CONTACT, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
Log.i(LOG_TAG, "*************************************************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "*************************************************************************");
Log.i(LOG_TAG, "");
}
@MediumTest
public void testServerModifyContactDetail() {
final String fnName = "testServerModifyContactDetail";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "Add contact details modifications to the change log, validating all the way");
startSubTest(fnName, "Creating table");
createTable();
startSubTest(fnName, "Check change log is empty");
long noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail with null local contact ID to change log (error expected)");
ContactDetail testDetail = mTestModule.createDummyDetailsName();
ContactDetail testDetail2 = new ContactDetail();
testDetail.localDetailID = mTestModule.GenerateRandomLong();
final int nativeId = mTestModule.GenerateRandomInt();
testDetail.nativeContactId = nativeId;
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = testDetail.key;
testDetail2.nativeContactId = testDetail.nativeContactId;
assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail with null local detail ID to change log (error expected)");
testDetail.localContactID = mTestModule.GenerateRandomLong();
testDetail2.localDetailID = null;
assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail with null key to change log (error expected)");
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = null;
assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log is still empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add modified contact detail change to change log with no native detail id");
final List<Long> changeIdxList = new ArrayList<Long>();
assertTrue(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
Cursor cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
ContactChangeInfo info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mNativeContactId, testDetail.nativeContactId);
assertEquals(info.mNativeDetailId, testDetail.nativeDetailId);
assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL);
assertTrue(testDetail.nativeDetailId == null);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add modified contact detail change to change log with native detail ID");
testDetail.nativeDetailId = mTestModule.GenerateRandomInt();
assertTrue(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mNativeContactId, testDetail.nativeContactId);
assertEquals(info.mNativeDetailId, testDetail.nativeDetailId);
assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail with null native contact ID to change log when add contact is not in list (should add a new contact change)");
testDetail.nativeContactId = null;
assertTrue(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_CONTACT, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add new contact log...");
assertTrue(NativeChangeLogTable.addNewContactChange(testDetail.localContactID, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by modified detail log with no native ID");
testDetail.nativeContactId = null;
testDetail.nativeDetailId = null;
assertTrue(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 2 entries");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 2);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertTrue(info.mNativeContactId == null);
assertTrue(info.mNativeDetailId == null);
assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_CONTACT, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact deleted log...");
assertTrue(NativeChangeLogTable.addDeletedContactChange(testDetail.localContactID, nativeId, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by modify detail log");
testDetail.nativeContactId = nativeId;
assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_CONTACT, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail deleted log...");
assertTrue(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by modify detail log (error expected)");
assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verify change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
Log.i(LOG_TAG, "*************************************************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "*************************************************************************");
Log.i(LOG_TAG, "");
}
*/
@MediumTest
public void testServerDeleteContactDetail() {
final String fnName = "testServerDeleteContactDetail";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "Add contact details deletions to the change log, validating all the way");
startSubTest(fnName, "Creating table");
createTable();
startSubTest(fnName, "Check change log is empty");
long noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
ContactDetail testDetail = mTestModule.createDummyDetailsName();
ContactDetail testDetail2 = new ContactDetail();
final int nativeId = TestModule.generateRandomInt();
testDetail.nativeContactId = nativeId;
testDetail.localContactID = TestModule.generateRandomLong();
testDetail.localDetailID = TestModule.generateRandomLong();
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = testDetail.key;
testDetail2.nativeContactId = nativeId;
startSubTest(fnName, "Add contact detail deletion with null local contact ID to change log (error expected)");
assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail deletion with null local detail ID to change log (error expected)");
testDetail2.localContactID = testDetail.localContactID;
testDetail2.localDetailID = null;
assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail deletion with null key to change log (error expected)");
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = null;
assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add deleted contact detail change to change log with no unique ID");
assertTrue(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
Cursor cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
final List<Long> changeIdxList = new ArrayList<Long>();
ContactChangeInfo info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mNativeContactId, testDetail.nativeContactId);
assertTrue(info.mNativeDetailId == null);
assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.DELETE_DETAIL);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add deleted contact detail change to change log with unique ID");
testDetail.nativeDetailId = TestModule.generateRandomInt();
assertTrue(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mNativeContactId, testDetail.nativeContactId);
assertEquals(info.mNativeDetailId, testDetail.nativeDetailId);
assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.DELETE_DETAIL);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact deleted log...");
testDetail.nativeContactId = nativeId;
assertTrue(NativeChangeLogTable.addDeletedContactChange(testDetail.localContactID, testDetail.nativeContactId, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by delete detail log (error expected)");
assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_CONTACT, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail deleted log...");
assertTrue(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by detail deleted log again");
assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_DETAIL, mTestDatabase.getReadableDatabase());
assertTrue(cursor != null);
assertTrue(cursor.getCount() == 1);
assertTrue(cursor.moveToFirst());
startSubTest(fnName, "Checking log data");
info = NativeChangeLogTable.getQueryData(cursor);
assertTrue(info.mNativeChangeId != null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
changeIdxList.add(info.mNativeChangeId);
cursor.close();
startSubTest(fnName, "Clear change log");
assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
changeIdxList.clear();
Log.i(LOG_TAG, "*************************************************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "*************************************************************************");
Log.i(LOG_TAG, "");
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class ChatDbUtils method fillInContactDetails.
/**
* Remove hard code
*
* @param msg
* @param item
* @param databaseHelper
* @param incoming
*/
private static void fillInContactDetails(ChatMessage msg, TimelineSummaryItem item, DatabaseHelper databaseHelper, TimelineSummaryItem.Type incoming) {
item.mTimestamp = System.currentTimeMillis();
// here we set the time stamp back into the chat message
// in order to be able to remove it from the chat history by time stamp in case its delivery fails
msg.setTimeStamp(item.mTimestamp);
item.mType = ActivityItem.Type.MESSAGE_IM_CONVERSATION;
item.mDescription = msg.getBody();
item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
// we store sender's localContactId for incoming msgs and recipient's
// localContactId for outgoing msgs
item.mLocalContactId = msg.getLocalContactId();
if (item.mLocalContactId != null && item.mLocalContactId != -1) {
ContactDetail cd = ContactDetailsTable.fetchDetail(item.mLocalContactId, DetailKeys.VCARD_NAME, databaseHelper.getReadableDatabase());
if (cd == null || cd.getName() == null) {
// if we don't get any details, we have to check the summary
// table because gtalk contacts
// without name will be otherwise show as unknown
ContactSummary contactSummary = new ContactSummary();
ServiceStatus error = ContactSummaryTable.fetchSummaryItem(item.mLocalContactId, contactSummary, databaseHelper.getReadableDatabase());
if (error == ServiceStatus.SUCCESS) {
item.mContactName = (contactSummary.formattedName != null) ? contactSummary.formattedName : ContactDetail.UNKNOWN_NAME;
} else {
item.mContactName = ContactDetail.UNKNOWN_NAME;
}
} else {
/**
* Get name from contact details. *
*/
VCardHelper.Name name = cd.getName();
item.mContactName = (name != null) ? name.toString() : ContactDetail.UNKNOWN_NAME;
}
}
item.mIncoming = incoming;
item.mContactNetwork = SocialNetwork.getSocialNetworkValue(msg.getNetworkId()).toString();
item.mNativeItemType = TimelineNativeTypes.ChatLog.ordinal();
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class DatabaseHelper method addContact.
/**
* Adds a contact to the database and fires an internal database change
* event.
*
* @param contact A {@link Contact} object which contains the details to be
* added
* @return SUCCESS or a suitable error code
* @see #deleteContact(long)
* @see #addContactDetail(ContactDetail)
* @see #modifyContactDetail(ContactDetail)
* @see #deleteContactDetail(long)
* @see #addContactToGroup(long, long)
* @see #deleteContactFromGroup(long, long)
*/
public ServiceStatus addContact(Contact contact) {
if (Settings.ENABLED_DATABASE_TRACE) {
trace(false, "DatabaseHelper.addContact() contactID[" + contact.contactID + "] nativeContactId[" + contact.nativeContactId + "]");
}
List<Contact> contactList = new ArrayList<Contact>();
contactList.add(contact);
ServiceStatus status = syncAddContactList(contactList, true, true);
if (ServiceStatus.SUCCESS == status) {
fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
}
return status;
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class DatabaseHelper method convertNativeContactChanges.
/**
* Converts an array of ContactChange into a Contact object.
*
* @see ContactChange
* @see Contact
* @param contactChanges the array of ContactChange to convert
* @return the equivalent Contact
*/
private Contact convertNativeContactChanges(ContactChange[] contactChanges) {
if (contactChanges == null || contactChanges.length <= 0)
return null;
final Contact contact = new Contact();
contact.localContactID = contactChanges[0].getInternalContactId();
// coming from native
contact.nativeContactId = new Integer((int) contactChanges[0].getNabContactId());
contact.synctophone = true;
// fill the contact with all the details
for (int i = 0; i < contactChanges.length; i++) {
final ContactDetail detail = convertContactChange(contactChanges[i]);
// setting it to -1 means that it does not need to be synced back to
// native
detail.syncNativeContactId = -1;
contact.details.add(detail);
}
return contact;
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class DatabaseHelper method syncDeleteContactDetailList.
/**
* Function used by the contact sync engine to delete a list of contact
* details from the database.
*
* @param contactDetailList The list of details which has been deleted on
* the server
* @param serverIdList A list of server IDs if known, or null
* @param syncToServer true if the details need to be sent to the server
* @param syncToNative true if the contacts need to be added to the native
* phonebook
* @param meProfile - TRUE if the added contact is Me profile.
* @return SUCCESS or a suitable error code
* @see #deleteContactDetail(long)
*/
public ServiceStatus syncDeleteContactDetailList(List<ContactDetail> contactDetailList, boolean syncToServer, boolean syncToNative) {
if (Settings.ENABLED_DATABASE_TRACE)
trace(false, "DatabaseHelper.syncDeleteContactDetailList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
syncToServer = false;
}
if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
syncToNative = false;
}
SQLiteDatabase db = getWritableDatabase();
boolean needFireDbUpdate = false;
for (ContactDetail contactDetail : contactDetailList) {
if ((contactDetail.serverContactId == null) || (contactDetail.serverContactId == -1)) {
ContactsTable.ContactIdInfo contactIdInfo = ContactsTable.validateContactId(contactDetail.localContactID, db);
if (contactIdInfo == null) {
return ServiceStatus.ERROR_NOT_FOUND;
}
contactDetail.nativeContactId = contactIdInfo.nativeId;
contactDetail.serverContactId = contactIdInfo.serverId;
}
try {
db.beginTransaction();
if (syncToNative) {
if (!NativeChangeLogTable.addDeletedContactDetailChange(contactDetail, db)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
if (syncToServer) {
if (!ContactChangeLogTable.addDeletedContactDetailChange(contactDetail, syncToServer, db)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
if (!ContactDetailsTable.deleteDetailByDetailId(contactDetail.localDetailID, db)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
// in order not to override the new picture before it is uploaded.
if (contactDetail.key == ContactDetail.DetailKeys.PHOTO && TextUtils.isEmpty(contactDetail.photo_url)) {
ContactSummaryTable.modifyPictureLoadedFlag(contactDetail.localContactID, false, db);
deleteThumbnail(contactDetail.localContactID);
}
String displayName = updateContactNameInSummary(db, contactDetail.localContactID, SyncMeDbUtils.isMeProfile(this, contactDetail.localContactID));
if (displayName == null) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
if (updateTimelineNames(contactDetail, displayName, contactDetail.localContactID, db)) {
needFireDbUpdate = true;
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
if (needFireDbUpdate) {
fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, false);
}
return ServiceStatus.SUCCESS;
}
Aggregations