Search in sources :

Example 21 with ContactDetail

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

the class NowPlusContactsTest method testAddModifyContacts.

@MediumTest
public void testAddModifyContacts() {
    Log.i(LOG_TAG, "***** EXECUTING testAddModifyContacts *****");
    Log.i(LOG_TAG, "Test contact functionality (add/modify details 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: Modify contacts and check if modification 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);
            mTestModule.modifyDummyDetailsData(detail);
            status = mDatabaseHelper.modifyContactDetail(detail);
            assertEquals(ServiceStatus.SUCCESS, status);
            assertTrue(isContactDetailInSummary(detail));
        }
        // check if modifyContactDatail works good 
        Contact modifiedContact = new Contact();
        status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, modifiedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        assertTrue(TestModule.doContactsMatch(modifiedContact, inputContacts[i]));
    }
    Log.i(LOG_TAG, "Test 1d: contacts and check if modification 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);
            mTestModule.modifyDummyDetailsData(detail);
            status = mDatabaseHelper.modifyContactDetail(detail);
            assertEquals(ServiceStatus.SUCCESS, status);
        }
        // check if modifyContactDatail 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)

Example 22 with ContactDetail

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

the class NowPlusContactsTest method testModifyDetailServerId.

@SmallTest
@Suppress
public void testModifyDetailServerId() {
    assertTrue(initialise());
    mDatabaseHelper.removeUserData();
    assertEquals(ServiceStatus.SUCCESS, mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK));
    Contact addedContact = new Contact();
    assertEquals(ServiceStatus.SUCCESS, mDatabaseHelper.addContact(addedContact));
    ContactDetail detail = new ContactDetail();
    mTestModule.createDummyDetailsData(detail);
    detail.localContactID = addedContact.localContactID;
    assertEquals(ServiceStatus.SUCCESS, mDatabaseHelper.addContactDetail(detail));
    Long serverDetailId = detail.localContactID + TestModule.generateRandomLong();
    assertTrue(mDatabaseHelper.syncContactDetail(detail.localDetailID, serverDetailId));
    ContactDetail fetchedDetail = new ContactDetail();
    assertEquals(ServiceStatus.SUCCESS, mDatabaseHelper.fetchContactDetail(detail.localDetailID, fetchedDetail));
    assertEquals(serverDetailId, fetchedDetail.unique_id);
    shutdown();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 23 with ContactDetail

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

the class NowPlusContactsTest method testFindNativeContact.

@SmallTest
public void testFindNativeContact() {
    Log.i(LOG_TAG, "***** EXECUTING testFetchContactInfo *****");
    Log.i(LOG_TAG, "Test Find Native Contact");
    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);
    // add contacts and check if added contacts are the same as fetched 
    Contact nativeContact = new Contact();
    nativeContact.synctophone = true;
    status = mDatabaseHelper.addContact(nativeContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    // create and add NameDetail
    ContactDetail nameDetail = mTestModule.createDummyDetailsName();
    ContactDetail nicknameDetail = mTestModule.createDummyDetailsNickname(nameDetail);
    nicknameDetail.localContactID = nativeContact.localContactID;
    status = mDatabaseHelper.addContactDetail(nicknameDetail);
    assertEquals(ServiceStatus.SUCCESS, status);
    // create and add phoneDetail
    ContactDetail phoneDetail = new ContactDetail();
    phoneDetail.localContactID = nativeContact.localContactID;
    phoneDetail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    String number = "07967 123456";
    phoneDetail.setTel(number, ContactDetail.DetailKeyTypes.CELL);
    status = mDatabaseHelper.addContactDetail(phoneDetail);
    assertEquals(ServiceStatus.SUCCESS, status);
    // create and add phoneDetail
    ContactDetail emailDetail = new ContactDetail();
    emailDetail.localContactID = nativeContact.localContactID;
    emailDetail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    emailDetail.setEmail(TestModule.generateRandomString() + "@mail.co.uk", ContactDetail.DetailKeyTypes.HOME);
    status = mDatabaseHelper.addContactDetail(emailDetail);
    assertEquals(ServiceStatus.SUCCESS, status);
    Contact fetchedContact = new Contact();
    status = mDatabaseHelper.fetchContact(nativeContact.localContactID, fetchedContact);
    assertTrue(mDatabaseHelper.findNativeContact(fetchedContact));
    Contact c = new Contact();
    assertFalse(mDatabaseHelper.findNativeContact(c));
    shutdown();
}
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 24 with ContactDetail

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

the class NowPlusDBHelperThumbnailTest method testDBHelperThumbnail.

@SmallTest
public void testDBHelperThumbnail() {
    assertTrue(initialise());
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
    Contact contact = mTestModule.createDummyContactData();
    status = mDatabaseHelper.addContact(contact);
    assertEquals(ServiceStatus.SUCCESS, status);
    Bitmap testBimap = Bitmap.createBitmap(createColors(), 0, STRIDE, WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
    ContactDetail cd = new ContactDetail();
    cd.localContactID = contact.localContactID;
    cd.photo = testBimap;
    status = mDatabaseHelper.addContactDetail(cd);
    status = ContactSummaryTable.modifyPictureLoadedFlag(contact.localContactID, false, mDatabaseHelper.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, status);
    int numOfThumbnails = mDatabaseHelper.fetchThumbnailUrlCount();
    assertEquals(1, numOfThumbnails);
    List<ThumbnailInfo> thumbInfoList = new ArrayList<ThumbnailInfo>();
    status = mDatabaseHelper.fetchThumbnailUrls(thumbInfoList, 0, 1);
    assertEquals(ServiceStatus.SUCCESS, status);
    shutdown();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Bitmap(android.graphics.Bitmap) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) ThumbnailInfo(com.vodafone360.people.database.DatabaseHelper.ThumbnailInfo) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 25 with ContactDetail

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

the class NowPlusNativeChangeTableTest method testServerDeleteContactDetail.

/*
	@MediumTest
    public void testServerAddContactDetail() {
		final String fnName = "testServerAddContactDetail";
		mTestStep = 1;

		Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
		Log.i(LOG_TAG, "Add new contact details to the change log, validating all the way");
		
		startSubTest(fnName, "Creating table");
		createTable();

		startSubTest(fnName, "Check change log is empty");
		long noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add contact detail with null local contact ID to change log (error expected)");
		final Integer nativeId = mTestModule.GenerateRandomInt();
		ContactDetail testDetail = mTestModule.createDummyDetailsName();
		ContactDetail testDetail2 = new ContactDetail();
		testDetail.localDetailID = mTestModule.GenerateRandomLong();
		testDetail.nativeContactId = nativeId;
		testDetail2.localDetailID = testDetail.localDetailID;
		testDetail2.key = testDetail.key;
		testDetail2.nativeContactId = testDetail.nativeContactId;
		assertFalse(NativeChangeLogTable.addNewContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add contact detail with null local detail ID to change log (error expected)");
		testDetail.localContactID = mTestModule.GenerateRandomLong();
		testDetail2.localDetailID = null;
		assertFalse(NativeChangeLogTable.addNewContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add contact detail with null key to change log (error expected)");
		testDetail2.localDetailID = testDetail.localDetailID;
		testDetail2.key = null;
		assertFalse(NativeChangeLogTable.addNewContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log is still empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add valid contact detail to change log");
		final List<Long> changeIdxList = new ArrayList<Long>();
		assertTrue(NativeChangeLogTable.addNewContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		Cursor cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_DETAIL, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		ContactChangeInfo info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertEquals(info.mNativeContactId, testDetail.nativeContactId);
		assertEquals(info.mNativeDetailId, testDetail.nativeDetailId);
		assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.NEW_DETAIL);
		assertTrue(testDetail.nativeDetailId == null);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add contact detail with null native ID to change log when add contact is not in list (should add a new contact change)");
		assertTrue(NativeChangeLogTable.addNewContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_DETAIL, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertEquals(info.mNativeContactId, testDetail.nativeContactId);
		assertTrue(info.mNativeDetailId == null);
		assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.NEW_DETAIL);
		assertTrue(testDetail.nativeDetailId == null);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add new contact log...");
		assertTrue(NativeChangeLogTable.addNewContactChange(testDetail.localContactID, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by new detail log with no server ID");
		assertTrue(NativeChangeLogTable.addNewContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 2);

		startSubTest(fnName, "Fetching change log");
		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_CONTACT, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Fetching change log");
		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_DETAIL, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add contact deleted log...");
		assertTrue(NativeChangeLogTable.addDeletedContactChange(testDetail.localContactID, nativeId, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by new detail log (error expected)");
		assertFalse(NativeChangeLogTable.addNewContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_CONTACT, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		Log.i(LOG_TAG, "*************************************************************************");
		Log.i(LOG_TAG, fnName + " has completed successfully");
		Log.i(LOG_TAG, "*************************************************************************");
		Log.i(LOG_TAG, "");
    }

	@MediumTest
    public void testServerModifyContactDetail() {
		final String fnName = "testServerModifyContactDetail";
		mTestStep = 1;

		Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
		Log.i(LOG_TAG, "Add contact details modifications to the change log, validating all the way");
		
		startSubTest(fnName, "Creating table");
		createTable();

		startSubTest(fnName, "Check change log is empty");
		long noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add contact detail with null local contact ID to change log (error expected)");
		ContactDetail testDetail = mTestModule.createDummyDetailsName();
		ContactDetail testDetail2 = new ContactDetail();
		testDetail.localDetailID = mTestModule.GenerateRandomLong();
		final int nativeId = mTestModule.GenerateRandomInt();
		testDetail.nativeContactId = nativeId;
		testDetail2.localDetailID = testDetail.localDetailID;
		testDetail2.key = testDetail.key;
		testDetail2.nativeContactId = testDetail.nativeContactId;
		assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add contact detail with null local detail ID to change log (error expected)");
		testDetail.localContactID = mTestModule.GenerateRandomLong();
		testDetail2.localDetailID = null;
		assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add contact detail with null key to change log (error expected)");
		testDetail2.localDetailID = testDetail.localDetailID;
		testDetail2.key = null;
		assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log is still empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add modified contact detail change to change log with no native detail id");
		final List<Long> changeIdxList = new ArrayList<Long>();
		assertTrue(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		Cursor cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		ContactChangeInfo info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertEquals(info.mNativeContactId, testDetail.nativeContactId);
		assertEquals(info.mNativeDetailId, testDetail.nativeDetailId);
		assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL);
		assertTrue(testDetail.nativeDetailId == null);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add modified contact detail change to change log with native detail ID");
		testDetail.nativeDetailId = mTestModule.GenerateRandomInt();
		assertTrue(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertEquals(info.mNativeContactId, testDetail.nativeContactId);
		assertEquals(info.mNativeDetailId, testDetail.nativeDetailId);
		assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add contact detail with null native contact ID to change log when add contact is not in list (should add a new contact change)");
		testDetail.nativeContactId = null;
		assertTrue(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_CONTACT, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add new contact log...");
		assertTrue(NativeChangeLogTable.addNewContactChange(testDetail.localContactID, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by modified detail log with no native ID");
		testDetail.nativeContactId = null;
		testDetail.nativeDetailId = null;
		assertTrue(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 2 entries");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 2);

		startSubTest(fnName, "Fetching change log");
		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertTrue(info.mNativeContactId == null);
		assertTrue(info.mNativeDetailId == null);
		assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.MODIFY_DETAIL);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_CONTACT, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add contact deleted log...");
		assertTrue(NativeChangeLogTable.addDeletedContactChange(testDetail.localContactID, nativeId, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by modify detail log");
		testDetail.nativeContactId = nativeId;
		assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_CONTACT, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add contact detail deleted log...");
		assertTrue(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by modify detail log (error expected)");
		assertFalse(NativeChangeLogTable.addModifiedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_DETAIL, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking log data");
		info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();

		startSubTest(fnName, "Clear change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
		changeIdxList.clear();

		startSubTest(fnName, "Verify change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		Log.i(LOG_TAG, "*************************************************************************");
		Log.i(LOG_TAG, fnName + " has completed successfully");
		Log.i(LOG_TAG, "*************************************************************************");
		Log.i(LOG_TAG, "");
    }
*/
@MediumTest
public void testServerDeleteContactDetail() {
    final String fnName = "testServerDeleteContactDetail";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "Add contact details deletions to the change log, validating all the way");
    startSubTest(fnName, "Creating table");
    createTable();
    startSubTest(fnName, "Check change log is empty");
    long noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    ContactDetail testDetail = mTestModule.createDummyDetailsName();
    ContactDetail testDetail2 = new ContactDetail();
    final int nativeId = TestModule.generateRandomInt();
    testDetail.nativeContactId = nativeId;
    testDetail.localContactID = TestModule.generateRandomLong();
    testDetail.localDetailID = TestModule.generateRandomLong();
    testDetail2.localDetailID = testDetail.localDetailID;
    testDetail2.key = testDetail.key;
    testDetail2.nativeContactId = nativeId;
    startSubTest(fnName, "Add contact detail deletion with null local contact ID to change log (error expected)");
    assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Add contact detail deletion with null local detail ID to change log (error expected)");
    testDetail2.localContactID = testDetail.localContactID;
    testDetail2.localDetailID = null;
    assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Add contact detail deletion with null key to change log (error expected)");
    testDetail2.localDetailID = testDetail.localDetailID;
    testDetail2.key = null;
    assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail2, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Add deleted contact detail change to change log with no unique ID");
    assertTrue(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    Cursor cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_DETAIL, mTestDatabase.getReadableDatabase());
    assertTrue(cursor != null);
    assertTrue(cursor.getCount() == 1);
    assertTrue(cursor.moveToFirst());
    startSubTest(fnName, "Checking log data");
    final List<Long> changeIdxList = new ArrayList<Long>();
    ContactChangeInfo info = NativeChangeLogTable.getQueryData(cursor);
    assertTrue(info.mNativeChangeId != null);
    assertEquals(info.mLocalContactId, testDetail.localContactID);
    assertEquals(info.mLocalDetailId, testDetail.localDetailID);
    assertEquals(info.mNativeContactId, testDetail.nativeContactId);
    assertTrue(info.mNativeDetailId == null);
    assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.DELETE_DETAIL);
    changeIdxList.add(info.mNativeChangeId);
    cursor.close();
    startSubTest(fnName, "Clear change log");
    assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
    changeIdxList.clear();
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add deleted contact detail change to change log with unique ID");
    testDetail.nativeDetailId = TestModule.generateRandomInt();
    assertTrue(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_DETAIL, mTestDatabase.getReadableDatabase());
    assertTrue(cursor != null);
    assertTrue(cursor.getCount() == 1);
    assertTrue(cursor.moveToFirst());
    startSubTest(fnName, "Checking log data");
    info = NativeChangeLogTable.getQueryData(cursor);
    assertTrue(info.mNativeChangeId != null);
    assertEquals(info.mLocalContactId, testDetail.localContactID);
    assertEquals(info.mLocalDetailId, testDetail.localDetailID);
    assertEquals(info.mNativeContactId, testDetail.nativeContactId);
    assertEquals(info.mNativeDetailId, testDetail.nativeDetailId);
    assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.DELETE_DETAIL);
    changeIdxList.add(info.mNativeChangeId);
    cursor.close();
    startSubTest(fnName, "Clear change log");
    assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
    changeIdxList.clear();
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact deleted log...");
    testDetail.nativeContactId = nativeId;
    assertTrue(NativeChangeLogTable.addDeletedContactChange(testDetail.localContactID, testDetail.nativeContactId, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Followed by delete detail log (error expected)");
    assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_CONTACT, mTestDatabase.getReadableDatabase());
    assertTrue(cursor != null);
    assertTrue(cursor.getCount() == 1);
    assertTrue(cursor.moveToFirst());
    startSubTest(fnName, "Checking log data");
    info = NativeChangeLogTable.getQueryData(cursor);
    assertTrue(info.mNativeChangeId != null);
    assertEquals(info.mLocalContactId, testDetail.localContactID);
    changeIdxList.add(info.mNativeChangeId);
    cursor.close();
    startSubTest(fnName, "Clear change log");
    assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
    changeIdxList.clear();
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact detail deleted log...");
    assertTrue(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Followed by detail deleted log again");
    assertFalse(NativeChangeLogTable.addDeletedContactDetailChange(testDetail, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_DETAIL, mTestDatabase.getReadableDatabase());
    assertTrue(cursor != null);
    assertTrue(cursor.getCount() == 1);
    assertTrue(cursor.moveToFirst());
    startSubTest(fnName, "Checking log data");
    info = NativeChangeLogTable.getQueryData(cursor);
    assertTrue(info.mNativeChangeId != null);
    assertEquals(info.mLocalContactId, testDetail.localContactID);
    changeIdxList.add(info.mNativeChangeId);
    cursor.close();
    startSubTest(fnName, "Clear change log");
    assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
    changeIdxList.clear();
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChangeInfo(com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

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