use of com.vodafone360.people.datatypes.VCardHelper.Organisation 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.VCardHelper.Organisation in project 360-Engine-for-Android by 360.
the class ContactChangeHelper method randomOrganization.
private static Organisation randomOrganization() {
String company = null, department = null;
if (randomTrue()) {
company = randomString();
}
if (randomTrue()) {
// Department only matters in 2.X
department = randomString();
}
Organisation org = new Organisation();
if (company == null && department == null || (!VersionUtils.is2XPlatform() && company == null)) {
// So that we have one part not null
// Also in 1.X we should have a company because department doesn't matter
company = randomString();
}
org.name = company;
org.unitNames.add(department);
return org;
}
use of com.vodafone360.people.datatypes.VCardHelper.Organisation in project 360-Engine-for-Android by 360.
the class TestModule method modifyDummyDetailsData.
public void modifyDummyDetailsData(ContactDetail detail) {
switch(detail.key) {
case VCARD_NAME:
VCardHelper.Name name = createDummyName();
detail.setName(name);
break;
case PRESENCE_TEXT:
detail.setValue(generateRandomString(), detail.key, null);
break;
case VCARD_DATE:
Time time = new Time();
time.parse("20080605");
detail.setDate(time, ContactDetail.DetailKeyTypes.BIRTHDAY);
break;
case VCARD_IMADDRESS:
detail.setValue(generateRandomString() + "@mail.co.uk", detail.key, null);
break;
case VCARD_EMAIL:
detail.setEmail(generateRandomString() + "@mail.co.uk", ContactDetail.DetailKeyTypes.HOME);
break;
case VCARD_PHONE:
detail.setTel("07967 123456", ContactDetail.DetailKeyTypes.CELL);
break;
case VCARD_BUSINESS:
case VCARD_ADDRESS:
VCardHelper.PostalAddress address = new VCardHelper.PostalAddress();
address.addressLine1 = "123 Any road";
address.addressLine2 = "Any location";
address.city = "Any City";
address.county = "Any County";
address.postCode = "M6 2AY";
address.country = "United Kingdom";
detail.setPostalAddress(address, ContactDetail.DetailKeyTypes.HOME);
break;
case VCARD_URL:
case VCARD_INTERNET_ADDRESS:
detail.setValue("www." + generateRandomString() + "anyaddress.co.uk", detail.key, null);
break;
case VCARD_ROLE:
detail.setValue(generateRandomString(), detail.key, null);
break;
case VCARD_ORG:
Organisation org = new Organisation();
org.name = generateRandomString();
detail.setOrg(org, null);
break;
case VCARD_TITLE:
detail.setValue(generateRandomString(), detail.key, null);
break;
case VCARD_NOTE:
{
String randomString = new String();
for (int i = 0; i < generateRandomInt() % 10; i++) {
randomString += generateRandomString() + " ";
}
detail.setValue(randomString, detail.key, null);
break;
}
}
}
use of com.vodafone360.people.datatypes.VCardHelper.Organisation 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.VCardHelper.Organisation in project 360-Engine-for-Android by 360.
the class UpdateNativeContactsTest method feedOneSyncableContact.
/**
* Feeds the People database with a contact containing all the possible details
* that can be synced on native side.
*
* @return the created Contact
*/
private Contact feedOneSyncableContact() {
final Contact contact = new Contact();
// set it syncable to native side
contact.synctophone = true;
contact.aboutMe = "xxx xxyyyy";
contact.friendOfMine = false;
contact.gender = 1;
// add a VCARD_NAME
ContactDetail detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_NAME;
detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
detail.order = ContactDetail.ORDER_NORMAL;
Name name = new Name();
name.firstname = "Firstname";
name.midname = "Midname";
name.surname = "Surname";
name.suffixes = "Suffixes";
name.title = "Title";
// a VCARD_NAME
detail.value = VCardHelper.makeName(name);
contact.details.add(detail);
// add a VCARD_NICKNAME
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_NICKNAME;
detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "My Nickname";
contact.details.add(detail);
// add a birthday VCARD_DATE + BIRTHDAY type
detail = new ContactDetail();
detail.order = ContactDetail.ORDER_NORMAL;
Time time = new Time();
time.set(1, 1, 2010);
detail.setDate(time, ContactDetail.DetailKeyTypes.BIRTHDAY);
contact.details.add(detail);
// add emails (Work, Home, Other)
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
detail.keyType = ContactDetail.DetailKeyTypes.HOME;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "email@home.test";
contact.details.add(detail);
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
detail.keyType = ContactDetail.DetailKeyTypes.WORK;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "email@work.test";
contact.details.add(detail);
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "email@other.test";
contact.details.add(detail);
// add phones VCARD_PHONE (Home, Cell, Work, Fax, Other)
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
detail.keyType = ContactDetail.DetailKeyTypes.HOME;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "+33111111";
contact.details.add(detail);
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
detail.keyType = ContactDetail.DetailKeyTypes.CELL;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "+33222222";
contact.details.add(detail);
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
detail.keyType = ContactDetail.DetailKeyTypes.WORK;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "+33333333";
contact.details.add(detail);
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
detail.keyType = ContactDetail.DetailKeyTypes.FAX;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "+33444444";
contact.details.add(detail);
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "+33555555";
contact.details.add(detail);
// add a preferred detail since all the others are set to normal
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
detail.keyType = ContactDetail.DetailKeyTypes.HOME;
detail.order = ContactDetail.ORDER_PREFERRED;
detail.value = "+33666666";
contact.details.add(detail);
// add VCARD_ADDRESS (Home, Work, Other)
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
detail.keyType = ContactDetail.DetailKeyTypes.HOME;
detail.order = ContactDetail.ORDER_NORMAL;
PostalAddress address = new PostalAddress();
address.addressLine1 = "home address line 1";
address.addressLine2 = "home address line 2";
address.city = "home city";
address.country = "home country";
address.county = "home county";
address.postCode = "home postcode";
address.postOfficeBox = "home po box";
detail.value = VCardHelper.makePostalAddress(address);
contact.details.add(detail);
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
detail.keyType = ContactDetail.DetailKeyTypes.WORK;
detail.order = ContactDetail.ORDER_NORMAL;
address = new PostalAddress();
address.addressLine1 = "work address line 1";
address.addressLine2 = "work address line 2";
address.city = "work city";
address.country = "work country";
address.county = "work county";
address.postCode = "work postcode";
address.postOfficeBox = "work po box";
detail.value = VCardHelper.makePostalAddress(address);
contact.details.add(detail);
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
detail.order = ContactDetail.ORDER_NORMAL;
address = new PostalAddress();
address.addressLine1 = "other address line 1";
address.addressLine2 = "other address line 2";
address.city = "other city";
address.country = "other country";
address.county = "other county";
address.postCode = "other postcode";
address.postOfficeBox = "other po box";
detail.value = VCardHelper.makePostalAddress(address);
contact.details.add(detail);
// add a VCARD_URL
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_URL;
detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "http://myurl.test";
contact.details.add(detail);
// add a VCARD_NOTE
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_NOTE;
detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "a note";
contact.details.add(detail);
// add a VCARD_ORG
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_ORG;
detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
detail.order = ContactDetail.ORDER_NORMAL;
Organisation org = new Organisation();
org.name = "company name";
org.unitNames.add("department");
detail.value = VCardHelper.makeOrg(org);
contact.details.add(detail);
// add a VCARD_TITLE
detail = new ContactDetail();
detail.key = ContactDetail.DetailKeys.VCARD_TITLE;
detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
detail.order = ContactDetail.ORDER_NORMAL;
detail.value = "title";
contact.details.add(detail);
mDatabaseHelper.addContact(contact);
return contact;
}
Aggregations