Search in sources :

Example 71 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class NowPlusContactSummaryTest method testUpdateDisplayName.

/**
 * Tests updating a contact's display name.
 */
@SmallTest
public void testUpdateDisplayName() {
    Log.i(LOG_TAG, "***** EXECUTING testtestUpdateDisplayName *****");
    Log.i(LOG_TAG, "Create ContactSummaryTable");
    ContactSummaryTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Create also a ContactDetailsTable");
    ContactDetailsTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
    final Contact contact = new Contact();
    contact.localContactID = new Long(10);
    contact.nativeContactId = new Integer(11);
    ServiceStatus serviceStatus = ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    // Name
    ContactDetail nameDetail = new ContactDetail();
    nameDetail.localContactID = contact.localContactID;
    VCardHelper.Name name = new VCardHelper.Name();
    name.firstname = "John";
    name.surname = "Doe";
    nameDetail.setName(name);
    // ORG
    ContactDetail orgDetail = new ContactDetail();
    nameDetail.localContactID = contact.localContactID;
    VCardHelper.Organisation org = new VCardHelper.Organisation();
    org.name = "VF";
    org.unitNames.add("Dev");
    orgDetail.setOrg(org, ContactDetail.DetailKeyTypes.WORK);
    ContactDetail emailDetail = new ContactDetail();
    emailDetail.localContactID = contact.localContactID;
    emailDetail.setEmail("dev@vf.com", ContactDetail.DetailKeyTypes.WORK);
    ContactDetail phoneDetail = new ContactDetail();
    phoneDetail.localContactID = contact.localContactID;
    phoneDetail.setTel("+123456789", ContactDetail.DetailKeyTypes.HOME);
    contact.details.add(nameDetail);
    contact.details.add(orgDetail);
    contact.details.add(emailDetail);
    contact.details.add(phoneDetail);
    // Loop for number of details + 1
    final int numLoopCycles = contact.details.size() + 1;
    int loopCycles = numLoopCycles;
    boolean isMe = false;
    while (loopCycles-- > 0) {
        assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
        if (contact.details.size() > 0) {
            contact.details.remove(0);
        }
    }
    final Contact meContact = new Contact();
    meContact.localContactID = new Long(11);
    meContact.nativeContactId = new Integer(12);
    isMe = true;
    Log.i(LOG_TAG, "Add me Contact to ContactSummaryTable");
    serviceStatus = ContactSummaryTable.addContact(meContact, mTestDatabase.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    meContact.details.add(nameDetail);
    meContact.details.add(orgDetail);
    meContact.details.add(emailDetail);
    meContact.details.add(phoneDetail);
    loopCycles = numLoopCycles;
    while (loopCycles-- > 0) {
        assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
        if (contact.details.size() > 0) {
            contact.details.remove(0);
        }
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 72 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class NowPlusContactSummaryTest method testModifyingContactDetails.

/**
 * Tests modifying a contact detail of an existing contact.
 */
@SmallTest
public void testModifyingContactDetails() {
    Log.i(LOG_TAG, "***** EXECUTING testModifyingContactDetails *****");
    Log.i(LOG_TAG, "Create ContactSummaryTable");
    ContactSummaryTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Create also a ContactDetailsTable");
    ContactDetailsTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
    final Contact contact = new Contact();
    contact.localContactID = new Long(10);
    contact.nativeContactId = new Integer(11);
    ServiceStatus serviceStatus = ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    Log.i(LOG_TAG, "Add a contact detail to the previous contact");
    ContactDetail contactDetail = new ContactDetail();
    contactDetail.localContactID = contact.localContactID;
    contactDetail.setEmail("toto@mail.co.uk", ContactDetail.DetailKeyTypes.HOME);
    boolean isMe = false;
    assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
    Log.i(LOG_TAG, "Modify a contact detail to the previous contact");
    contactDetail = new ContactDetail();
    contactDetail.localContactID = contact.localContactID;
    final String eMail2 = "toto2@mail.co.uk";
    contactDetail.setEmail(eMail2, ContactDetail.DetailKeyTypes.HOME);
    assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 73 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class NowPlusContactSummaryTest method testModifyingingContactSummary.

/**
 * Tests modifying a contact summary.
 */
@SmallTest
public void testModifyingingContactSummary() {
    Log.i(LOG_TAG, "***** EXECUTING testModifyingingContactSummary *****");
    Log.i(LOG_TAG, "Create ContactSummaryTable");
    ContactSummaryTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
    final Contact contact = mTestModule.createDummyContactData();
    contact.localContactID = new Long(10);
    contact.nativeContactId = new Integer(11);
    ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Fetching a ContactSummary from ContactSummaryTable");
    ContactSummary contactSummary = new ContactSummary();
    ServiceStatus serviceStatus = ContactSummaryTable.fetchSummaryItem(contact.localContactID, contactSummary, mTestDatabase.getReadableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    compareContactWithContactSummary(contact, contactSummary);
    Log.i(LOG_TAG, "Modify a contact");
    final Contact contact2 = copyContact(contact);
    contact2.synctophone = !contact.synctophone;
    serviceStatus = ContactSummaryTable.modifyContact(contact2, mTestDatabase.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    Log.i(LOG_TAG, "Fetching a ContactSummary from ContactSummaryTable");
    contactSummary = new ContactSummary();
    serviceStatus = ContactSummaryTable.fetchSummaryItem(contact.localContactID, contactSummary, mTestDatabase.getReadableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    // by doing so, we should get back to the original if it was correctly
    // modified
    contactSummary.synctophone = !contactSummary.synctophone;
    compareContactWithContactSummary(contact, contactSummary);
}
Also used : ContactSummary(com.vodafone360.people.datatypes.ContactSummary) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 74 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class NowPlusContactsTest method testAddDeleteContacts.

@MediumTest
public void testAddDeleteContacts() {
    Log.i(LOG_TAG, "***** EXECUTING testAddDeleteContacts *****");
    Log.i(LOG_TAG, "Test contact functionality (add delete contacts)");
    Log.i(LOG_TAG, "Test 1a: Initialise test environment and load database");
    assertTrue(initialise());
    Log.i(LOG_TAG, "Test 1b: Remove user data");
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "Test 1c: Add " + NUM_OF_CONTACTS + " random contacts");
    // add contacts and check if added contacts are the same as fetched
    Contact[] inputContacts = new Contact[NUM_OF_CONTACTS];
    Contact addedContact = new Contact();
    for (int i = 0; i < NUM_OF_CONTACTS; i++) {
        inputContacts[i] = mTestModule.createDummyContactData();
        status = mDatabaseHelper.addContact(inputContacts[i]);
        assertEquals(ServiceStatus.SUCCESS, status);
        status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, addedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        assertTrue(TestModule.doContactsMatch(addedContact, inputContacts[i]));
    }
    Log.i(LOG_TAG, "Test 1d: Delete contacts and check if deletion was correct");
    for (int i = 0; i < inputContacts.length; i++) {
        // check if deletion works good
        status = mDatabaseHelper.deleteContact(inputContacts[i].localContactID);
        assertEquals(ServiceStatus.SUCCESS, status);
        Contact removedContact = new Contact();
        status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, removedContact);
        // contact was deleted so it shouldn't be found
        assertEquals(ServiceStatus.ERROR_NOT_FOUND, status);
    }
    shutdown();
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 75 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class NowPlusContactsTest method testAddDeleteContactsDetails.

@MediumTest
public void testAddDeleteContactsDetails() {
    Log.i(LOG_TAG, "***** EXECUTING testAddDeleteContactsDetails *****");
    Log.i(LOG_TAG, "Test contact functionality (add delete contacts details)");
    Log.i(LOG_TAG, "Test 1a: Initialise test environment and load database");
    assertTrue(initialise());
    Log.i(LOG_TAG, "Test 1b: Remove user data");
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "Test 1c: Add " + NUM_OF_CONTACTS + " random contacts");
    // add contacts and check if added contacts are the same as fetched
    Contact[] inputContacts = new Contact[NUM_OF_CONTACTS];
    Contact addedContact = new Contact();
    for (int i = 0; i < NUM_OF_CONTACTS; i++) {
        inputContacts[i] = mTestModule.createDummyContactData();
        status = mDatabaseHelper.addContact(inputContacts[i]);
        assertEquals(ServiceStatus.SUCCESS, status);
        status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, addedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        assertTrue(TestModule.doContactsMatch(addedContact, inputContacts[i]));
    }
    Log.i(LOG_TAG, "Test 1d: Delete contacts detatils and check if deletion was correct");
    for (int i = 0; i < inputContacts.length; i++) {
        for (int j = 0; j < inputContacts[i].details.size(); j++) {
            ContactDetail detail = inputContacts[i].details.get(j);
            status = mDatabaseHelper.deleteContactDetail(detail.localDetailID);
            assertEquals(ServiceStatus.SUCCESS, status);
        }
        // check if deletion works good
        Contact modifiedContact = new Contact();
        status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, modifiedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        assertTrue(TestModule.doContactsMatch(modifiedContact, inputContacts[i]));
    }
    shutdown();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

Contact (com.vodafone360.people.datatypes.Contact)109 ServiceStatus (com.vodafone360.people.service.ServiceStatus)107 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)100 ArrayList (java.util.ArrayList)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)50 Suppress (android.test.suitebuilder.annotation.Suppress)39 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)34 Cursor (android.database.Cursor)31 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)22 SmallTest (android.test.suitebuilder.annotation.SmallTest)19 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)18 SQLException (android.database.SQLException)15 ContentValues (android.content.ContentValues)14 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)13 Uri (android.net.Uri)11 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)11 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)11 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)11 SQLiteException (android.database.sqlite.SQLiteException)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)9