Search in sources :

Example 56 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class NowPlusContactDetailsTableTest method testFetchContactDetailsForNative.

public void testFetchContactDetailsForNative() {
    final String fnName = "testFetchContactDetailsForNative";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
    SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    Contact contact = new Contact();
    contact.localContactID = TestModule.generateRandomLong();
    // create and add NameDetail
    ContactDetail nameDetail = mTestModule.createDummyDetailsName();
    ContactDetail nicknameDetail = mTestModule.createDummyDetailsNickname(nameDetail);
    nicknameDetail.localContactID = contact.localContactID;
    nicknameDetail.nativeContactId = TestModule.generateRandomInt();
    ServiceStatus status = ContactDetailsTable.addContactDetail(nicknameDetail, true, true, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    List<ContactDetail> addedDetails = new ArrayList<ContactDetail>();
    addedDetails.add(nicknameDetail);
    // create and add phoneDetail
    ContactDetail phoneDetail = new ContactDetail();
    phoneDetail.localContactID = contact.localContactID;
    phoneDetail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    String number = "07967 123456";
    phoneDetail.setTel(number, ContactDetail.DetailKeyTypes.CELL);
    // phoneDetail.nativeContactId = mTestModule.GenerateRandomInt();
    phoneDetail.nativeContactId = nicknameDetail.nativeContactId;
    status = ContactDetailsTable.addContactDetail(phoneDetail, true, true, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    addedDetails.add(phoneDetail);
    // create and add phoneDetail
    ContactDetail emailDetail = new ContactDetail();
    emailDetail.localContactID = contact.localContactID;
    emailDetail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    emailDetail.setEmail(TestModule.generateRandomString() + "@mail.co.uk", ContactDetail.DetailKeyTypes.HOME);
    // emailDetail.nativeContactId = mTestModule.GenerateRandomInt();
    emailDetail.nativeContactId = nicknameDetail.nativeContactId;
    status = ContactDetailsTable.addContactDetail(emailDetail, true, true, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    addedDetails.add(emailDetail);
    ContactDetail.DetailKeys[] keyList = { ContactDetail.DetailKeys.VCARD_NICKNAME, ContactDetail.DetailKeys.VCARD_PHONE, ContactDetail.DetailKeys.VCARD_EMAIL };
    List<ContactDetail> detailList = new ArrayList<ContactDetail>();
    assertTrue(ContactDetailsTable.fetchContactDetailsForNative(detailList, keyList, false, 0, MAX_MODIFY_NOWPLUS_DETAILS_COUNT, readableDb));
    for (int i = 0; i < detailList.size(); i++) {
        assertTrue(DatabaseHelper.doDetailsMatch(detailList.get(i), addedDetails.get(i)));
    }
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "***********************************************");
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact)

Example 57 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class NowPlusContactSummaryTest method testRemovingContactSummary.

/**
 * Tests removing a contact summary.
 */
@SmallTest
public void testRemovingContactSummary() {
    Log.i(LOG_TAG, "***** EXECUTING testRemovingContactSummary *****");
    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 to check that it exists");
    ContactSummary contactSummary = new ContactSummary();
    ServiceStatus serviceStatus = ContactSummaryTable.fetchSummaryItem(contact.localContactID, contactSummary, mTestDatabase.getReadableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    Log.i(LOG_TAG, "Delete the contact from ContactSummaryTable");
    serviceStatus = ContactSummaryTable.deleteContact(contact.localContactID, mTestDatabase.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    Log.i(LOG_TAG, "Try to fetching a ContactSummary from ContactSummaryTable to check that it is not possible anymore");
    contactSummary = new ContactSummary();
    serviceStatus = ContactSummaryTable.fetchSummaryItem(contact.localContactID, contactSummary, mTestDatabase.getReadableDatabase());
    assertTrue(ServiceStatus.SUCCESS != serviceStatus);
}
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 58 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus 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 59 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus 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 60 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus 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)

Aggregations

ServiceStatus (com.vodafone360.people.service.ServiceStatus)190 Contact (com.vodafone360.people.datatypes.Contact)71 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)63 MediumTest (android.test.suitebuilder.annotation.MediumTest)62 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)43 ArrayList (java.util.ArrayList)43 Suppress (android.test.suitebuilder.annotation.Suppress)40 Cursor (android.database.Cursor)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)17 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)16 Bundle (android.os.Bundle)12 ContentValues (android.content.ContentValues)11 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)11 SQLException (android.database.SQLException)9 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)9 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)9 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)8 LoginDetails (com.vodafone360.people.datatypes.LoginDetails)8 PersistSettings (com.vodafone360.people.service.PersistSettings)8