use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class FetchNativeContactsTest method testRunDuplicateContactTest.
@MediumTest
@Suppress
public // Breaks tests.
void testRunDuplicateContactTest() {
final String fnName = "testRunConflictTests";
Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
mTestStep = 1;
startSubTest(fnName, "Checking people database is empty");
Cursor peopleCursor = mDb.openContactSummaryCursor(null, null);
assertEquals(0, peopleCursor.getCount());
assertTrue(Settings.ENABLE_UPDATE_NATIVE_CONTACTS);
startSubTest(fnName, "Checking native database is empty");
Cursor nativeCursor = mCr.query(People.CONTENT_URI, new String[] { People._ID, People.NAME, People.NOTES }, null, null, null);
assertEquals(0, nativeCursor.getCount());
startSubTest(fnName, "Add first dummy native contact to native");
ContentValues peopleValues = new ContentValues();
peopleValues.put(Contacts.People.NAME, DUP_CONTACT_NAME);
Uri personUri1 = mCr.insert(Contacts.People.CONTENT_URI, peopleValues);
assertTrue("Unable to insert contact into native people table", personUri1 != null);
final long personId1 = ContentUris.parseId(personUri1);
ContentValues phoneValues = new ContentValues();
phoneValues.put(Contacts.Phones.PERSON_ID, personId1);
phoneValues.put(Contacts.Phones.NUMBER, DUP_CONTACT_NUMBER);
phoneValues.put(Contacts.Phones.TYPE, Contacts.Phones.TYPE_MOBILE);
Uri phoneUri1 = mCr.insert(Contacts.Phones.CONTENT_URI, phoneValues);
assertTrue("Unable to insert contact into native phone table 1", phoneUri1 != null);
final long phoneId1 = (int) ContentUris.parseId(phoneUri1);
startSubTest(fnName, "Add second dummy native contact to native");
peopleValues.clear();
peopleValues.put(Contacts.People.NAME, DUP_CONTACT_NAME);
Uri personUri2 = mCr.insert(Contacts.People.CONTENT_URI, peopleValues);
assertTrue("Unable to insert contact into native people table", personUri2 != null);
final long personId2 = ContentUris.parseId(personUri2);
Contact testContact1 = new Contact();
ContactDetail testDetail1 = new ContactDetail();
VCardHelper.Name name1 = new VCardHelper.Name();
name1.firstname = DUP_CONTACT_NAME;
testDetail1.setName(name1);
ContactDetail testDetail2 = new ContactDetail();
testDetail2.setValue(name1.toString(), ContactDetail.DetailKeys.VCARD_NICKNAME, null);
ContactDetail testDetail3 = new ContactDetail();
testDetail3.setTel(DUP_CONTACT_NUMBER, ContactDetail.DetailKeyTypes.CELL);
testContact1.details.add(testDetail1);
testContact1.details.add(testDetail2);
testContact1.details.add(testDetail3);
ServiceStatus status = mDb.addContact(testContact1);
assertEquals(ServiceStatus.SUCCESS, status);
Contact testContact2 = new Contact();
ContactDetail testDetail4 = new ContactDetail();
VCardHelper.Name name2 = new VCardHelper.Name();
name2.firstname = DUP_CONTACT_NAME;
testDetail4.setName(name2);
ContactDetail testDetail5 = new ContactDetail();
testDetail5.setValue(name2.toString(), ContactDetail.DetailKeys.VCARD_NICKNAME, null);
testContact2.details.add(testDetail4);
testContact2.details.add(testDetail5);
status = mDb.addContact(testContact2);
assertEquals(ServiceStatus.SUCCESS, status);
startSubTest(fnName, "Running processor");
runProcessor();
Contact updatedContact1 = new Contact();
status = mDb.fetchContact(testContact1.localContactID, updatedContact1);
assertEquals(ServiceStatus.SUCCESS, status);
Contact updatedContact2 = new Contact();
status = mDb.fetchContact(testContact2.localContactID, updatedContact2);
assertEquals(ServiceStatus.SUCCESS, status);
assertEquals(personId1, updatedContact1.nativeContactId.longValue());
assertEquals(personId2, updatedContact2.nativeContactId.longValue());
boolean doneName = false;
boolean doneNickname = false;
boolean donePhone = false;
for (ContactDetail detail : updatedContact1.details) {
assertEquals(personId1, detail.nativeContactId.longValue());
detail.syncNativeContactId = fetchSyncNativeId(detail.localDetailID);
assertEquals("No sync marker, ID = " + detail.nativeDetailId + ", key = " + detail.key, Integer.valueOf(-1), detail.syncNativeContactId);
Integer detailId = detail.nativeDetailId;
assertTrue(detailId != null);
switch(detail.key) {
case VCARD_NAME:
assertEquals(DUP_CONTACT_NAME, detail.nativeVal1);
assertEquals(DUP_CONTACT_NAME, detail.getName().toString());
assertEquals(personId1, detailId.longValue());
doneName = true;
break;
case VCARD_NICKNAME:
assertEquals(DUP_CONTACT_NAME, detail.nativeVal1);
assertEquals(DUP_CONTACT_NAME, detail.getValue());
assertEquals(personId1, detailId.longValue());
doneNickname = true;
break;
case VCARD_PHONE:
assertEquals(DUP_CONTACT_NUMBER, detail.nativeVal1);
assertEquals(DUP_CONTACT_NUMBER, detail.getValue());
assertEquals(ContactDetail.DetailKeyTypes.CELL, detail.keyType);
assertEquals(phoneId1, detailId.longValue());
donePhone = true;
break;
}
}
assertTrue(doneName);
assertTrue(doneNickname);
assertTrue(donePhone);
doneName = false;
doneNickname = false;
for (ContactDetail detail : updatedContact2.details) {
assertEquals(personId2, detail.nativeContactId.longValue());
detail.syncNativeContactId = fetchSyncNativeId(detail.localDetailID);
assertEquals("No sync marker, ID = " + detail.nativeDetailId + ", key = " + detail.key, Integer.valueOf(-1), detail.syncNativeContactId);
Integer detailId = detail.nativeDetailId;
assertTrue(detailId != null);
switch(detail.key) {
case VCARD_NAME:
assertEquals(DUP_CONTACT_NAME, detail.nativeVal1);
assertEquals(DUP_CONTACT_NAME, detail.getName().toString());
assertEquals(personId2, detailId.longValue());
doneName = true;
break;
case VCARD_NICKNAME:
assertEquals(DUP_CONTACT_NAME, detail.nativeVal1);
assertEquals(DUP_CONTACT_NAME, detail.getValue());
assertEquals(personId2, detailId.longValue());
doneNickname = true;
break;
default:
fail("Unexpected detail: " + detail.key);
}
}
assertTrue(doneName);
assertTrue(doneNickname);
nativeCursor.close();
peopleCursor.close();
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 FetchNativeContactsTest method testRunWithDeletedDetails.
@MediumTest
@Suppress
public // Breaks tests
void testRunWithDeletedDetails() {
final String fnName = "testRunWithDeletedDetails";
Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
mTestStep = 1;
startSubTest(fnName, "Checking people database is empty");
Cursor peopleCursor = mDb.openContactSummaryCursor(null, null);
assertEquals(0, peopleCursor.getCount());
assertTrue(Settings.ENABLE_UPDATE_NATIVE_CONTACTS);
startSubTest(fnName, "Checking native database is empty");
Cursor nativeCursor = mCr.query(People.CONTENT_URI, new String[] { People._ID, People.NAME, People.NOTES }, null, null, null);
assertEquals(0, nativeCursor.getCount());
startSubTest(fnName, "Add one dummy native contact");
ContentValues peopleValues = new ContentValues();
peopleValues.put(Contacts.People.NAME, ADD_CONTACT_TEST_NAME);
peopleValues.put(Contacts.People.NOTES, ADD_CONTACT_TEST_NOTE);
Uri personUri1 = mCr.insert(Contacts.People.CONTENT_URI, peopleValues);
assertTrue("Unable to insert contact into native people table", personUri1 != null);
final long personId = ContentUris.parseId(personUri1);
ContentValues phoneValues = new ContentValues();
phoneValues.put(Contacts.Phones.PERSON_ID, personId);
phoneValues.put(Contacts.Phones.NUMBER, ADD_PHONE_TEST1);
phoneValues.put(Contacts.Phones.TYPE, ADD_PHONE_TYPE_TEST1);
Uri phoneUri1 = mCr.insert(Contacts.Phones.CONTENT_URI, phoneValues);
assertTrue("Unable to insert contact into native phone table 1", phoneUri1 != null);
final long phoneId1 = (int) ContentUris.parseId(phoneUri1);
ContentValues cmValues = new ContentValues();
cmValues.put(Contacts.ContactMethods.PERSON_ID, personId);
cmValues.put(Contacts.ContactMethods.DATA, ADD_CM_TEST1);
cmValues.put(Contacts.ContactMethods.TYPE, ADD_CM_TYPE_TEST1);
cmValues.put(Contacts.ContactMethods.KIND, ADD_CM_KIND_TEST1);
Uri cmUri1 = mCr.insert(Contacts.ContactMethods.CONTENT_URI, cmValues);
assertTrue("Unable to insert contact into native contact methods table 1", cmUri1 != null);
final long cmId1 = ContentUris.parseId(cmUri1);
cmValues.put(Contacts.ContactMethods.DATA, ADD_CM_TEST2);
cmValues.put(Contacts.ContactMethods.TYPE, ADD_CM_TYPE_TEST2);
cmValues.put(Contacts.ContactMethods.KIND, ADD_CM_KIND_TEST2);
cmValues.put(Contacts.ContactMethods.ISPRIMARY, 1);
Uri cmUri2 = mCr.insert(Contacts.ContactMethods.CONTENT_URI, cmValues);
assertTrue("Unable to insert contact into native contact methods table 2", cmUri2 != null);
final long cmId2 = ContentUris.parseId(cmUri2);
ContentValues orgValues = new ContentValues();
orgValues.put(Contacts.Organizations.PERSON_ID, personId);
orgValues.put(Contacts.Organizations.COMPANY, ADD_ORG_COMPANY_TEST1);
orgValues.put(Contacts.Organizations.TITLE, ADD_ORG_TITLE_TEST1);
orgValues.put(Contacts.Organizations.TYPE, ADD_ORG_TYPE_TEST1);
orgValues.put(Contacts.Organizations.LABEL, ADD_ORG_LABEL_TEST1);
Uri orgUri = mCr.insert(Contacts.Organizations.CONTENT_URI, orgValues);
assertTrue("Unable to insert contact into native organizations table 1", orgUri != null);
final long orgId1 = ContentUris.parseId(orgUri);
startSubTest(fnName, "Running processor");
runProcessor();
startSubTest(fnName, "Checking contact has been synced to people");
peopleCursor.requery();
assertEquals(1, peopleCursor.getCount());
assertTrue(peopleCursor.moveToFirst());
ContactSummary summary = ContactSummaryTable.getQueryData(peopleCursor);
assertTrue(summary != null);
Contact newContact = new Contact();
ServiceStatus status = mDb.fetchContact(summary.localContactID, newContact);
assertEquals(ServiceStatus.SUCCESS, status);
boolean doneNote = false;
boolean donePhone1 = false;
boolean doneCm1 = false;
boolean doneCm2 = false;
boolean doneOrg1 = false;
boolean doneTitle1 = false;
assertTrue(newContact.synctophone);
assertEquals(personId, newContact.nativeContactId.longValue());
assertEquals(personId, summary.nativeContactId.longValue());
for (ContactDetail detail : newContact.details) {
assertEquals(personId, detail.nativeContactId.longValue());
detail.syncNativeContactId = fetchSyncNativeId(detail.localDetailID);
assertEquals("No sync marker, ID = " + detail.nativeDetailId + ", key = " + detail.key, Integer.valueOf(-1), detail.syncNativeContactId);
Integer detailId = detail.nativeDetailId;
assertTrue(detailId != null);
switch(detail.key) {
case VCARD_NAME:
case VCARD_NICKNAME:
assertEquals(personId, detailId.longValue());
break;
case VCARD_NOTE:
assertEquals(personId, detailId.longValue());
doneNote = true;
mDb.deleteContactDetail(detail.localDetailID);
break;
case VCARD_PHONE:
if (detailId.longValue() == phoneId1) {
donePhone1 = true;
mDb.deleteContactDetail(detail.localDetailID);
} else {
fail("Unknown phone number in people contact: ID:" + detailId + " does not match " + phoneId1);
}
break;
case VCARD_EMAIL:
if (detailId.longValue() == cmId1) {
doneCm1 = true;
mDb.deleteContactDetail(detail.localDetailID);
} else {
fail("Unknown email in people contact");
}
break;
case VCARD_ADDRESS:
if (detailId.longValue() == cmId2) {
doneCm2 = true;
mDb.deleteContactDetail(detail.localDetailID);
} else {
fail("Unknown address in people contact");
}
break;
case VCARD_ORG:
if (detailId.longValue() == orgId1) {
doneOrg1 = true;
mDb.deleteContactDetail(detail.localDetailID);
} else {
fail("Unknown organisation in people contact");
}
break;
case VCARD_TITLE:
if (detailId.longValue() == orgId1) {
doneTitle1 = true;
mDb.deleteContactDetail(detail.localDetailID);
} else {
fail("Unknown title in people contact");
}
break;
default:
fail("Unexpected detail in people contact: " + detail.key);
}
}
assertTrue("Note was missing", doneNote);
assertTrue("Phone1 was missing", donePhone1);
assertTrue("Email was missing", doneCm1);
assertTrue("Address was missing", doneCm2);
assertTrue("Organisation was missing", doneOrg1);
assertTrue("Position was missing", doneTitle1);
startSubTest(fnName, "Running processor");
runProcessor();
startSubTest(fnName, "Checking contact has been synced to people");
peopleCursor.requery();
assertEquals(1, peopleCursor.getCount());
assertTrue(peopleCursor.moveToFirst());
summary = ContactSummaryTable.getQueryData(peopleCursor);
assertTrue(summary != null);
newContact = new Contact();
status = mDb.fetchContact(summary.localContactID, newContact);
assertEquals(ServiceStatus.SUCCESS, status);
assertTrue(newContact.synctophone);
assertEquals(personId, newContact.nativeContactId.longValue());
assertEquals(personId, summary.nativeContactId.longValue());
boolean doneName = false;
boolean doneNickname = false;
for (ContactDetail detail : newContact.details) {
assertEquals(personId, detail.nativeContactId.longValue());
detail.syncNativeContactId = fetchSyncNativeId(detail.localDetailID);
assertEquals("No sync marker, ID = " + detail.nativeDetailId + ", key = " + detail.key, Integer.valueOf(-1), detail.syncNativeContactId);
Integer detailId = detail.nativeDetailId;
assertTrue(detailId != null);
switch(detail.key) {
case VCARD_NAME:
assertEquals(personId, detailId.longValue());
assertEquals(ADD_CONTACT_TEST_NAME, detail.nativeVal1);
VCardHelper.Name name = detail.getName();
assertTrue(name != null);
assertEquals(ADD_CONTACT_TEST_NAME, name.toString());
doneName = true;
break;
case VCARD_NICKNAME:
assertEquals(personId, detailId.longValue());
assertEquals(ADD_CONTACT_TEST_NAME, detail.nativeVal1);
assertEquals(ADD_CONTACT_TEST_NAME, detail.getValue());
doneNickname = true;
break;
default:
fail("Unexpected contact detail: " + detail.key);
}
}
assertTrue("Name was missing", doneName);
assertTrue("Nickname was missing", doneNickname);
nativeCursor.close();
peopleCursor.close();
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 FetchNativeContactsTest method testRunWithOneNoNameContact.
@MediumTest
@Suppress
public // Breaks tests
void testRunWithOneNoNameContact() {
final String fnName = "testRunWithOneNoNameContact";
Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
mTestStep = 1;
startSubTest(fnName, "Checking people database is empty");
Cursor peopleCursor = mDb.openContactSummaryCursor(null, null);
assertEquals(0, peopleCursor.getCount());
assertTrue(Settings.ENABLE_UPDATE_NATIVE_CONTACTS);
startSubTest(fnName, "Checking native database is empty");
Cursor nativeCursor = mCr.query(People.CONTENT_URI, new String[] { People._ID, People.NAME, People.NOTES }, null, null, null);
assertEquals(0, nativeCursor.getCount());
startSubTest(fnName, "Add one dummy native contact");
ContentValues peopleValues = new ContentValues();
Uri personUri1 = mCr.insert(Contacts.People.CONTENT_URI, peopleValues);
assertTrue("Unable to insert contact into native people table", personUri1 != null);
final long personId = ContentUris.parseId(personUri1);
ContentValues phoneValues = new ContentValues();
phoneValues.put(Contacts.Phones.PERSON_ID, personId);
phoneValues.put(Contacts.Phones.NUMBER, ADD_PHONE_TEST1);
phoneValues.put(Contacts.Phones.TYPE, ADD_PHONE_TYPE_TEST1);
phoneValues.put(Contacts.Phones.ISPRIMARY, 1);
Uri phoneUri1 = mCr.insert(Contacts.Phones.CONTENT_URI, phoneValues);
assertTrue("Unable to insert contact into native phone table 1", phoneUri1 != null);
final long phoneId = (int) ContentUris.parseId(phoneUri1);
startSubTest(fnName, "Running processor");
runProcessor();
startSubTest(fnName, "Checking contact has been synced to people");
peopleCursor.requery();
assertEquals(1, peopleCursor.getCount());
assertTrue(peopleCursor.moveToFirst());
ContactSummary summary = ContactSummaryTable.getQueryData(peopleCursor);
assertTrue(summary != null);
Contact newContact = new Contact();
ServiceStatus status = mDb.fetchContact(summary.localContactID, newContact);
assertEquals(ServiceStatus.SUCCESS, status);
assertTrue(newContact.synctophone);
assertEquals(personId, newContact.nativeContactId.longValue());
assertEquals(personId, summary.nativeContactId.longValue());
boolean donePhone = false;
for (ContactDetail detail : newContact.details) {
assertEquals(personId, detail.nativeContactId.longValue());
detail.syncNativeContactId = fetchSyncNativeId(detail.localDetailID);
assertEquals("No sync marker, ID = " + detail.nativeDetailId + ", key = " + detail.key, Integer.valueOf(-1), detail.syncNativeContactId);
Integer detailId = detail.nativeDetailId;
switch(detail.key) {
case VCARD_PHONE:
assertTrue(detailId != null);
assertTrue(detail.nativeDetailId != null);
assertEquals(phoneId, detail.nativeDetailId.longValue());
assertFalse(donePhone);
donePhone = true;
assertEquals(ADD_PHONE_TEST1, detail.nativeVal1);
assertEquals(ADD_PHONE_TEST1, detail.getValue());
assertEquals(Integer.valueOf(ContactDetail.ORDER_PREFERRED), detail.order);
break;
default:
fail("Unexpected detail in people contact: " + detail.key);
}
}
assertTrue("Phone number was missing", donePhone);
nativeCursor.close();
peopleCursor.close();
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 DownloadServerContactsTest method reportBackWithDeletedDetails.
private void reportBackWithDeletedDetails(int reqId, List<BaseDataType> data) {
Log.d(LOG_TAG, "reportBackWithDeletedDetails");
Integer pageNo = mProcessor.testGetPageFromReqId(reqId);
int pageSize = mProcessor.getDownloadPageSize();
assertTrue(pageNo != null);
assertEquals(Integer.valueOf(mPageCount), pageNo);
ContactChanges contactChanges = new ContactChanges();
data.add(contactChanges);
contactChanges.mCurrentServerVersion = CURRENT_SERVER_VERSION;
contactChanges.mServerRevisionBefore = CURRENT_SERVER_VERSION;
contactChanges.mServerRevisionAfter = CURRENT_SERVER_VERSION;
contactChanges.mVersionAnchor = CURRENT_SERVER_VERSION;
assertTrue(pageSize > 0);
if (pageSize > 0) {
contactChanges.mNumberOfPages = 1 + mPageCount + (mItemCount / pageSize);
}
int noOfContacts = Math.min(pageSize, mItemCount);
for (int i = 0; i < noOfContacts; i++) {
Contact curContact = new Contact();
curContact.contactID = FIRST_MODIFIED_CONTACT_ID + mItemCount - 1;
contactChanges.mContacts.add(curContact);
ContactDetail delDetail1 = new ContactDetail();
delDetail1.key = ContactDetail.DetailKeys.VCARD_NAME;
delDetail1.deleted = true;
ContactDetail delDetail2 = new ContactDetail();
delDetail2.key = ContactDetail.DetailKeys.VCARD_NICKNAME;
delDetail2.deleted = true;
ContactDetail delDetail3 = new ContactDetail();
delDetail3.key = ContactDetail.DetailKeys.VCARD_EMAIL;
delDetail3.unique_id = NEW_EMAIL_DETAIL_ID + mItemCount - 1;
delDetail3.deleted = true;
curContact.details.add(delDetail1);
curContact.details.add(delDetail2);
curContact.details.add(delDetail3);
mItemCount--;
}
mPageCount++;
assertTrue(mItemCount >= 0);
if (mItemCount == 0) {
nextState(State.IDLE);
}
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class DownloadServerContactsTest method reportBackWithNewContacts.
private void reportBackWithNewContacts(int reqId, List<BaseDataType> data) {
Log.d(LOG_TAG, "reportBackWithNewContacts");
Integer pageNo = mProcessor.testGetPageFromReqId(reqId);
int pageSize = mProcessor.getDownloadPageSize();
assertTrue(pageNo != null);
assertEquals(Integer.valueOf(mPageCount), pageNo);
ContactChanges contactChanges = new ContactChanges();
data.add(contactChanges);
contactChanges.mCurrentServerVersion = CURRENT_SERVER_VERSION;
contactChanges.mServerRevisionBefore = CURRENT_SERVER_VERSION;
contactChanges.mServerRevisionAfter = CURRENT_SERVER_VERSION;
contactChanges.mVersionAnchor = CURRENT_SERVER_VERSION;
assertTrue(pageSize > 0);
if (pageSize > 0) {
contactChanges.mNumberOfPages = 1 + mPageCount + (mItemCount / pageSize);
}
int noOfContacts = Math.min(pageSize, mItemCount);
for (int i = 0; i < noOfContacts; i++) {
Contact newContact = mTestModule.createDummyContactData();
if (mLastNewContact == null) {
mLastNewContact = newContact;
}
newContact.contactID = FIRST_MODIFIED_CONTACT_ID + mItemCount - 1;
newContact.userID = generateTestUserID(newContact.contactID);
ContactDetail detail1 = new ContactDetail();
detail1.key = ContactDetail.DetailKeys.VCARD_PHONE;
detail1.unique_id = OLD_PHONE_DETAIL_ID + mItemCount - 1;
detail1.value = OLD_PHONE_DETAIL_VALUE;
newContact.details.add(detail1);
for (int j = 0; j < newContact.details.size(); j++) {
ContactDetail detail = newContact.details.get(j);
switch(detail.key) {
case VCARD_PHONE:
case VCARD_EMAIL:
if (detail.unique_id == null) {
detail.unique_id = ALT_PHONE_DETAIL_ID + j;
}
break;
}
}
contactChanges.mContacts.add(newContact);
mItemCount--;
}
mPageCount++;
assertTrue(mItemCount >= 0);
if (mItemCount == 0) {
nextState(State.IDLE);
}
}
Aggregations