use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class NowPlusContactDetailsTableTest method testDeleteContactDetail.
@MediumTest
public void testDeleteContactDetail() {
final String fnName = "testDeleteContactDetail";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "Deltes a contact detail from the contacts detail table, validating all the way");
SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
ContactDetail detail = new ContactDetail();
mTestModule.createDummyDetailsData(detail);
detail.localContactID = TestModule.generateRandomLong();
// try to delete contact by contact id before creating a table
ServiceStatus status = ContactDetailsTable.deleteDetailByContactId(detail.localContactID, writeableDb);
assertEquals(ServiceStatus.ERROR_DATABASE_CORRUPT, status);
// try to delete contact by detail id before creating a table
assertFalse(ContactDetailsTable.deleteDetailByDetailId(TestModule.generateRandomLong(), writeableDb));
startSubTest(fnName, "Creating table");
createTable();
// try to add detail with localContactID that is set
status = ContactDetailsTable.addContactDetail(detail, true, true, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
// delete previously added contact
status = ContactDetailsTable.deleteDetailByContactId(detail.localContactID, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
// fetch deleted detail (should be null)
ContactDetail fetchedDetail = ContactDetailsTable.fetchDetail(detail.localDetailID, readableDb);
assertEquals(null, fetchedDetail);
// try to add detail with localContactID that is set
status = ContactDetailsTable.addContactDetail(detail, true, true, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
// try to delete contact by detail id
assertTrue(ContactDetailsTable.deleteDetailByDetailId(detail.localDetailID, writeableDb));
// fetch deleted detail (should be null)
fetchedDetail = ContactDetailsTable.fetchDetail(detail.localDetailID, readableDb);
assertEquals(null, fetchedDetail);
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "***********************************************");
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class NowPlusContactDetailsTableTest method testFetchContactInfo.
@MediumTest
public void testFetchContactInfo() {
final String fnName = "testAddFetchContactDetail";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "Adds a contact details to the contacts details table, validating all the way");
SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
startSubTest(fnName, "Creating table");
createTable();
// create and add phoneDetail
ContactDetail phoneDetail = new ContactDetail();
phoneDetail.localContactID = TestModule.generateRandomLong();
phoneDetail.key = ContactDetail.DetailKeys.VCARD_PHONE;
String number = "07967 123456";
phoneDetail.setTel(number, ContactDetail.DetailKeyTypes.CELL);
ServiceStatus status = ContactDetailsTable.addContactDetail(phoneDetail, true, true, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
// create and add phoneDetail
ContactDetail nameDetail = mTestModule.createDummyDetailsName();
nameDetail.localContactID = phoneDetail.localContactID;
status = ContactDetailsTable.addContactDetail(nameDetail, true, true, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
ContactDetail fetchName = new ContactDetail();
ContactDetail fetchPhone = new ContactDetail();
status = ContactDetailsTable.fetchContactInfo(number, fetchPhone, fetchName, readableDb);
assertTrue(DatabaseHelper.doDetailsMatch(phoneDetail, fetchPhone));
assertTrue(DatabaseHelper.doDetailsMatch(nameDetail, fetchName));
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "***********************************************");
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class NowPlusContactDetailsTableTest method testfixPreferredDetail.
@MediumTest
public void testfixPreferredDetail() {
final String fnName = "testfixPreferredDetail";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "Adds a contact details to the contacts details table, validating all the way");
startSubTest(fnName, "Creating table");
createTable();
SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
ContactDetail detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
detail.setTel("07967 123456", ContactDetail.DetailKeyTypes.CELL);
// not preferred detail
detail.order = 50;
detail.localContactID = TestModule.generateRandomLong();
ServiceStatus status = ContactDetailsTable.addContactDetail(detail, true, true, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
status = ContactDetailsTable.fixPreferredValues(detail.localContactID, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
// fetch deleted detail (should be null)
ContactDetail fetchedDetail = ContactDetailsTable.fetchDetail(detail.localDetailID, readableDb);
// detail is now preferred
assertEquals(0, fetchedDetail.order.intValue());
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "***********************************************");
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class TestModule method createDummyContactData.
public Contact createDummyContactData() {
Contact contact = new Contact();
// contact.localContactID = 0L;
contact.synctophone = generateRandomBoolean();
contact.details.clear();
contact.aboutMe = generateRandomString();
contact.friendOfMine = ((generateRandomInt() & 1) == 0);
contact.gender = generateRandomInt() & 1;
if (contact.groupList == null) {
contact.groupList = new ArrayList<Long>();
}
for (int i = 0; i < (generateRandomInt() & 3); i++) {
addRandomGroup(contact.groupList);
}
if (contact.sources == null) {
contact.sources = new ArrayList<String>();
}
for (int i = 0; i < (generateRandomInt() & 3); i++) {
contact.sources.add(generateRandomString());
}
ContactDetail nameDetail = createDummyDetailsName();
ContactDetail nicknameDetail = createDummyDetailsNickname(nameDetail);
contact.details.add(nameDetail);
contact.details.add(nicknameDetail);
final int noOfDetails = (generateRandomInt() % 10);
for (int i = 0; i < noOfDetails; i++) {
ContactDetail detail = new ContactDetail();
createDummyDetailsData(detail);
contact.details.add(detail);
}
if ((generateRandomInt() & 1) == 0) {
ContactDetail detail = new ContactDetail();
Organisation org = new Organisation();
org.name = generateRandomString();
detail.setOrg(org, null);
contact.details.add(detail);
}
if ((generateRandomInt() & 1) == 0) {
ContactDetail detail = new ContactDetail();
detail.setValue(generateRandomString(), ContactDetail.DetailKeys.VCARD_TITLE, null);
contact.details.add(detail);
}
fixPreferred(contact);
return contact;
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class NowPlusChangeLogTest 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 = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail with null local contact ID to change log (error expected)");
final Long serverContactId = mTestModule.GenerateRandomLong();
ContactDetail testDetail = mTestModule.createDummyDetailsName();
ContactDetail testDetail2 = new ContactDetail();
testDetail.localDetailID = mTestModule.GenerateRandomLong();
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = testDetail.key;
assertFalse(ContactChangeLogTable.addNewContactDetailChange(testDetail2, serverContactId, 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(ContactChangeLogTable.addNewContactDetailChange(testDetail2, serverContactId, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail with null key to change log (error expected)");
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = null;
assertFalse(ContactChangeLogTable.addNewContactDetailChange(testDetail2, serverContactId, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log is still empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add valid contact detail to change log");
assertTrue(ContactChangeLogTable.addNewContactDetailChange(testDetail, serverContactId, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching new detail change log");
final List<ContactChangeInfo> contactChangeList = new ArrayList<ContactChangeInfo>();
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Checking change log data");
ContactChangeInfo info = contactChangeList.get(0);
assertTrue(info.mContactChangeId != null);
assertTrue(info.mGroupOrRelId == null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mServerContactId, serverContactId);
assertTrue(info.mServerDetailId == null);
assertEquals(info.mServerDetailKey, testDetail.key);
assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.NEW_DETAIL);
startSubTest(fnName, "Clear new contact from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail with null server contact ID to change log when add contact is not in list (should add a new contact change)");
assertTrue(ContactChangeLogTable.addNewContactDetailChange(testDetail, null, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching new detail change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
assertEquals(contactChangeList.get(0).mLocalContactId, testDetail.localContactID);
startSubTest(fnName, "Clear new contact from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add new contact log...");
assertTrue(ContactChangeLogTable.addNewContactChange(testDetail.localContactID, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by new detail log with no server ID");
assertTrue(ContactChangeLogTable.addNewContactDetailChange(testDetail, null, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 2 entries");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 2);
startSubTest(fnName, "Fetching new detail change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Checking change log data");
info = contactChangeList.get(0);
assertTrue(info.mContactChangeId != null);
assertTrue(info.mGroupOrRelId == null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertTrue(info.mServerContactId == null);
assertEquals(info.mServerDetailId, testDetail.unique_id);
assertEquals(info.mServerDetailKey, testDetail.key);
assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.NEW_DETAIL);
startSubTest(fnName, "Clear new detail from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Fetching new contact change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Clear new contact from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact deleted log...");
assertTrue(ContactChangeLogTable.addDeletedContactChange(testDetail.localContactID, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by new detail log (error expected)");
assertFalse(ContactChangeLogTable.addNewContactDetailChange(testDetail, serverContactId, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Clear delete contact from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(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 = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail with null local contact ID to change log (error expected)");
final Long serverContactId = mTestModule.GenerateRandomLong();
ContactDetail testDetail = mTestModule.createDummyDetailsName();
ContactDetail testDetail2 = new ContactDetail();
testDetail.localDetailID = mTestModule.GenerateRandomLong();
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = testDetail.key;
assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, false, mTestDatabase.getWritableDatabase()));
assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, 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(ContactChangeLogTable.addModifiedContactDetailChange(testDetail2, serverContactId, false, mTestDatabase.getWritableDatabase()));
assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail2, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail with null key to change log (error expected)");
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = null;
assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail2, serverContactId, false, mTestDatabase.getWritableDatabase()));
assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail2, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log is still empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add modified contact detail change to change log with no unique ID");
assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, false, mTestDatabase.getWritableDatabase()));
assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching new detail change log");
final List<ContactChangeInfo> contactChangeList = new ArrayList<ContactChangeInfo>();
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Checking change log data");
ContactChangeInfo info = contactChangeList.get(0);
assertTrue(info.mContactChangeId != null);
assertTrue(info.mGroupOrRelId == null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mServerContactId, serverContactId);
assertTrue(info.mServerDetailId == null);
assertEquals(info.mServerDetailKey, testDetail.key);
assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL);
startSubTest(fnName, "Clear change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verify change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add modified contact detail change to change log with unique ID");
testDetail.unique_id = mTestModule.GenerateRandomLong();
assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, false, mTestDatabase.getWritableDatabase()));
assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching new detail change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Checking change log data");
info = contactChangeList.get(0);
assertTrue(info.mContactChangeId != null);
assertTrue(info.mGroupOrRelId == null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mServerContactId, serverContactId);
assertEquals(info.mServerDetailId, testDetail.unique_id);
assertEquals(info.mServerDetailKey, testDetail.key);
assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL);
startSubTest(fnName, "Clear change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail with null server contact ID to change log when add contact is not in list (should add a new contact change)");
assertTrue(ContactChangeLogTable.addNewContactDetailChange(testDetail, null, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching new detail change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
assertEquals(contactChangeList.get(0).mLocalContactId, testDetail.localContactID);
startSubTest(fnName, "Clear new contact from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verify change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add new contact log...");
assertTrue(ContactChangeLogTable.addNewContactChange(testDetail.localContactID, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by modified detail log with no server ID");
assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, null, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 2 entries");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 2);
startSubTest(fnName, "Fetching change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Checking change log data");
info = contactChangeList.get(0);
assertTrue(info.mContactChangeId != null);
assertTrue(info.mGroupOrRelId == null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertTrue(info.mServerContactId == null);
assertEquals(info.mServerDetailId, testDetail.unique_id);
assertEquals(info.mServerDetailKey, testDetail.key);
assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL);
startSubTest(fnName, "Clear modify detail from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Fetching new contact change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Clear new contact from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact deleted log...");
assertTrue(ContactChangeLogTable.addDeletedContactChange(testDetail.localContactID, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by modify detail log");
assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Clear delete contact from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verify change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail deleted log...");
assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by modify detail log (error expected)");
assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Clear delete contact detail from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verify change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(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 = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail deletion with null local contact ID to change log (error expected)");
final Long serverContactId = TestModule.generateRandomLong();
ContactDetail testDetail = mTestModule.createDummyDetailsName();
ContactDetail testDetail2 = new ContactDetail();
testDetail.localDetailID = TestModule.generateRandomLong();
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = testDetail.key;
testDetail2.serverContactId = serverContactId;
testDetail.serverContactId = serverContactId;
assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, false, mTestDatabase.getWritableDatabase()));
assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail deletion with null local detail ID to change log (error expected)");
testDetail.localContactID = TestModule.generateRandomLong();
testDetail2.localContactID = testDetail.localContactID;
testDetail2.localDetailID = null;
assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, false, mTestDatabase.getWritableDatabase()));
assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Add contact detail deletion with null key to change log (error expected)");
testDetail2.localDetailID = testDetail.localDetailID;
testDetail2.key = null;
assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, false, mTestDatabase.getWritableDatabase()));
assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log is still empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add deleted contact detail change to change log with no unique ID");
assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, false, mTestDatabase.getWritableDatabase()));
assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
final List<ContactChangeInfo> contactChangeList = new ArrayList<ContactChangeInfo>();
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Checking change log data");
ContactChangeInfo info = contactChangeList.get(0);
assertTrue(info.mContactChangeId != null);
assertTrue(info.mGroupOrRelId == null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mServerContactId, serverContactId);
assertTrue(info.mServerDetailId == null);
assertEquals(info.mServerDetailKey, testDetail.key);
assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL);
startSubTest(fnName, "Clear change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verify change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add deleted contact detail change to change log with unique ID");
testDetail.unique_id = TestModule.generateRandomLong();
assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, false, mTestDatabase.getWritableDatabase()));
assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching new detail change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Checking change log data");
info = contactChangeList.get(0);
assertTrue(info.mContactChangeId != null);
assertTrue(info.mGroupOrRelId == null);
assertEquals(info.mLocalContactId, testDetail.localContactID);
assertEquals(info.mLocalDetailId, testDetail.localDetailID);
assertEquals(info.mServerContactId, serverContactId);
assertEquals(info.mServerDetailId, testDetail.unique_id);
assertEquals(info.mServerDetailKey, testDetail.key);
assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL);
startSubTest(fnName, "Clear change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact deleted log...");
assertTrue(ContactChangeLogTable.addDeletedContactChange(testDetail.localContactID, serverContactId, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by delete detail log (error expected)");
assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Clear delete contact from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 0);
startSubTest(fnName, "Add contact detail deleted log...");
assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Followed by detail deleted log again");
assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Check change log has now 1 entry");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
assertTrue(noOfChanges == 1);
startSubTest(fnName, "Fetching change log");
assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
assertTrue(contactChangeList.size() == 1);
startSubTest(fnName, "Clear delete contact detail from change log");
assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
startSubTest(fnName, "Verfy change log is now empty");
noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(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, "");
}
Aggregations