Search in sources :

Example 36 with ContactDetail

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

the class NowPlusContactDetailsTableTest method testSyncServerFetchContactChanges.

/*
	 * test syncServerFetchContactChanges
	 */
public void testSyncServerFetchContactChanges() {
    final String fnName = "testSyncServerFetchContactChanges";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "Validates syncServerFetchContactChanges details");
    SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
    SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    List<ContactDetail> detailsList = new ArrayList<ContactDetail>();
    for (int i = 0; i < NUM_OF_CONTACTS; i++) {
        ContactDetail detail = new ContactDetail();
        detail.localContactID = TestModule.generateRandomLong();
        mTestModule.createDummyDetailsData(detail);
        ContactDetailsTable.addContactDetail(detail, true, true, writeableDb);
        detailsList.add(detail);
    }
    Cursor cursor = ContactDetailsTable.syncServerFetchContactChanges(readableDb, true);
    assertEquals(NUM_OF_CONTACTS, cursor.getCount());
    Cursor cursorOldContacts = ContactDetailsTable.syncServerFetchContactChanges(readableDb, false);
    assertEquals(0, cursorOldContacts.getCount());
    cursorOldContacts.close();
    List<Contact> contactList = new ArrayList<Contact>();
    ContactDetailsTable.syncServerGetNextNewContactDetails(cursor, contactList, NUM_OF_CONTACTS);
    for (int i = 0; i < contactList.size(); i++) {
        assertTrue(DatabaseHelper.doDetailsMatch(detailsList.get(i), contactList.get(i).details.get(0)));
    }
    cursor.close();
    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) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Contact(com.vodafone360.people.datatypes.Contact)

Example 37 with ContactDetail

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

the class NowPlusContactDetailsTableTest method testSyncServerFetchNoOfChanges.

/*
	 * test syncServerFetchNoOfChanges
	 */
public void testSyncServerFetchNoOfChanges() {
    final String fnName = "testSyncServerFetchNoOfChanges";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "Validates syncServerFetchContactChanges details");
    SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
    SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    List<ContactDetail> detailsList = new ArrayList<ContactDetail>();
    for (int i = 0; i < NUM_OF_CONTACTS; i++) {
        ContactDetail detail = new ContactDetail();
        detail.localContactID = TestModule.generateRandomLong();
        detail.serverContactId = TestModule.generateRandomLong();
        mTestModule.createDummyDetailsData(detail);
        ContactDetailsTable.addContactDetail(detail, true, true, writeableDb);
        detailsList.add(detail);
    }
    Cursor cursor = ContactDetailsTable.syncServerFetchContactChanges(readableDb, false);
    assertEquals(cursor.getCount(), ContactDetailsTable.syncServerFetchNoOfChanges(readableDb));
    for (ContactDetail contactDetail : detailsList) {
        Long serverContactId = TestModule.fetchSyncServerId(contactDetail.localDetailID, readableDb);
        assertEquals(contactDetail.serverContactId, serverContactId);
    }
    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) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 38 with ContactDetail

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

the class NowPlusContactDetailsTableTest method testSyncNativeContactChanges.

/*
	 * test Sync Native Contact Changes
	 */
public void testSyncNativeContactChanges() {
    final String fnName = "testSyncNativeContactChanges";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "Validates sync server native contact details");
    SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
    SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    List<ContactDetail> detailsList = new ArrayList<ContactDetail>();
    for (int i = 0; i < NUM_OF_CONTACTS; i++) {
        ContactDetail detail = new ContactDetail();
        detail.localContactID = TestModule.generateRandomLong();
        detail.nativeContactId = TestModule.generateRandomInt();
        detail.nativeVal1 = TestModule.generateRandomString();
        detail.nativeVal2 = TestModule.generateRandomString();
        detail.nativeVal3 = TestModule.generateRandomString();
        mTestModule.createDummyDetailsData(detail);
        ContactDetailsTable.addContactDetail(detail, true, true, writeableDb);
        detailsList.add(detail);
    }
    Cursor nat = ContactDetailsTable.syncNativeFetchContactChanges(readableDb, true);
    assertEquals(3, nat.getCount());
    nat.close();
    Cursor cursor = ContactDetailsTable.syncNativeFetchContactChanges(readableDb, false);
    assertEquals(cursor.getCount(), ContactDetailsTable.syncNativeFetchNoOfChanges(readableDb));
    List<Contact> contactList = new ArrayList<Contact>();
    ContactDetailsTable.syncNativeGetNextNewContactDetails(cursor, contactList, NUM_OF_CONTACTS);
    for (int i = 0; i < contactList.size(); i++) {
        assertTrue(DatabaseHelper.doDetailsMatch(detailsList.get(i), contactList.get(i).details.get(0)));
    }
    cursor.close();
    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) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Contact(com.vodafone360.people.datatypes.Contact)

Example 39 with ContactDetail

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

the class NowPlusContactSummaryTest method testAddingContactDetails.

/**
 * Tests adding a contact detail to an existing contact.
 */
@SmallTest
public void testAddingContactDetails() {
    Log.i(LOG_TAG, "***** EXECUTING testAddingContactDetails *****");
    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 = mTestModule.createDummyContactData();
    contact.localContactID = new Long(10);
    contact.nativeContactId = new Integer(11);
    ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Add a contact detail to the previous contact");
    final ContactDetail contactDetail = new ContactDetail();
    contactDetail.localContactID = contact.localContactID;
    boolean isMe = false;
    contactDetail.setEmail("test@example.com", ContactDetail.DetailKeyTypes.HOME);
    assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 40 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail 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)

Aggregations

ContactDetail (com.vodafone360.people.datatypes.ContactDetail)109 Contact (com.vodafone360.people.datatypes.Contact)60 ServiceStatus (com.vodafone360.people.service.ServiceStatus)57 ArrayList (java.util.ArrayList)33 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 MediumTest (android.test.suitebuilder.annotation.MediumTest)24 Cursor (android.database.Cursor)20 Suppress (android.test.suitebuilder.annotation.Suppress)16 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)15 ContentValues (android.content.ContentValues)11 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)10 SQLException (android.database.SQLException)8 Uri (android.net.Uri)7 SQLiteException (android.database.sqlite.SQLiteException)6 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)6 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)6 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)4 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)4 Date (java.util.Date)4