Search in sources :

Example 81 with Contact

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

Example 82 with Contact

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

the class ActivitiesEngineTest method testMessageLog.

/*
     * @MediumTest public void testGetTimelineEvent(){ boolean testPass = true;
     * mState = ActivityTestState.GET_TIMELINE_EVENT_FROM_SERVER; Contact
     * meProfile = mTestModule.createDummyContactData(); ServiceStatus status =
     * mApplication.getDatabase().setMeProfile(meProfile); if(status !=
     * ServiceStatus.SUCCESS){ throw(new
     * RuntimeException("Could not access db")); }
     * mEng.addUiGetActivitiesRequest(); status = mEngineTester.waitForEvent();
     * if(status != ServiceStatus.SUCCESS){ throw(new
     * RuntimeException("Expected SUCCESS")); } Object data =
     * mEngineTester.data(); assertTrue(data==null);
     * mEng.addUiGetActivitiesRequest(); status = mEngineTester.waitForEvent();
     * if(status != ServiceStatus.SUCCESS){ throw(new
     * RuntimeException("Expected SUCCESS")); } data = mEngineTester.data();
     * assertTrue(data==null); assertTrue("testPushMessage() failed", testPass);
     * Log.i(LOG_TAG, "**** testGetTimelineEvent (SUCCESS) ****\n"); }
     */
@MediumTest
// Takes too long.
@Suppress
public void testMessageLog() {
    final String ADDRESS = "address";
    // final String PERSON = "person";
    final String DATE = "date";
    final String READ = "read";
    final String STATUS = "status";
    final String TYPE = "type";
    final String BODY = "body";
    ContentValues values = new ContentValues();
    values.put(ADDRESS, "+61408219690");
    values.put(DATE, "1630000000000");
    values.put(READ, 1);
    values.put(STATUS, -1);
    values.put(TYPE, 2);
    values.put(BODY, "SMS inserting test");
    /* Uri inserted = */
    mApplication.getContentResolver().insert(Uri.parse("content://sms"), values);
    mState = ActivityTestState.GET_ACTIVITIES_SUCCESS;
    // re-test with valid Me profile
    Contact meProfile = mTestModule.createDummyContactData();
    assertEquals("Could not access db", ServiceStatus.SUCCESS, SyncMeDbUtils.setMeProfile(mApplication.getDatabase(), meProfile));
    mEng.addStatusesSyncRequest();
    assertEquals("Expected SUCCESS, not timeout", ServiceStatus.SUCCESS, mEngineTester.waitForEvent());
    Object data = mEngineTester.data();
    assertTrue(data == null);
    values.put(DATE, "1650000000000");
    /* inserted = */
    mApplication.getContentResolver().insert(Uri.parse("content://mms"), values);
    mEng.addStatusesSyncRequest();
    assertEquals("Could not access db", ServiceStatus.SUCCESS, mEngineTester.waitForEvent());
    Log.i(LOG_TAG, "**** testGetActivities (SUCCESS) ****\n");
}
Also used : ContentValues(android.content.ContentValues) ActivityContact(com.vodafone360.people.datatypes.ActivityContact) Contact(com.vodafone360.people.datatypes.Contact) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 83 with Contact

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

the class ContactChangeHelper method generatedUpdatedContact.

public static ContactChange[] generatedUpdatedContact(ContactChange[] contact, ContactChange[] update) {
    if (update == null || update.length == 0) {
        return contact;
    }
    final List<ContactChange> updatedContact = new ArrayList<ContactChange>();
    final int contactSize = contact.length;
    final int updateSize = update.length;
    for (int i = 0; i < contactSize; i++) {
        ContactChange cc = contact[i];
        int updateType = ContactChange.TYPE_UNKNOWN;
        if (updateSize > i) {
            updateType = update[i].getType();
        }
        if (updateType == ContactChange.TYPE_UPDATE_DETAIL) {
            cc = update[i];
        } else if (updateType == ContactChange.TYPE_DELETE_DETAIL) {
            continue;
        }
        updatedContact.add(cc);
    }
    for (int i = 0; i < updateSize; i++) {
        final ContactChange cc = update[i];
        // final int key = cc.getKey();
        if (cc.getType() == ContactChange.TYPE_ADD_DETAIL) {
            // updatedContact.add(lastIndexForKeyInCcList(key, updatedContact) + 1, cc);
            // Since we are using areUnsortedChangeListsEqual to compare we can just add instead of above
            updatedContact.add(cc);
        }
    }
    return updatedContact.toArray(new ContactChange[updatedContact.size()]);
}
Also used : ArrayList(java.util.ArrayList) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 84 with Contact

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

the class SyncMeEngine method downloadMeProfileThumbnail.

/**
 * The call to download the thumbnail picture for the me profile.
 * @param url String - picture url of Me Profile (comes with getMyChanges())
 * @param localContactId long - local contact id of Me Profile
 */
private void downloadMeProfileThumbnail(final String url, final long localContactId) {
    if (NetworkAgent.getAgentState() == NetworkAgent.AgentState.CONNECTED) {
        Request request = new Request(url, ThumbnailUtils.REQUEST_THUMBNAIL_URI, engineId());
        newState(State.FETCHING_ME_PROFILE_THUMBNAIL);
        setReqId(QueueManager.getInstance().addRequestAndNotify(request));
    }
}
Also used : ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) Request(com.vodafone360.people.service.io.Request)

Example 85 with Contact

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

the class SyncMeEngine method uploadMeProfile.

/**
 * * Sends a SetMe request to the server in the case that the me profile has
 * been changed locally. If the me profile thumbnail has always been changed
 * it will also be uploaded to the server.
 */
private void uploadMeProfile() {
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        return;
    }
    newState(State.UPDATING_ME_PROFILE);
    Contact meProfile = new Contact();
    mDbHelper.fetchContact(SyncMeDbUtils.getMeProfileLocalContactId(mDbHelper), meProfile);
    mUploadedMeDetails = SyncMeDbUtils.saveContactDetailChanges(mDbHelper, meProfile);
    setReqId(Contacts.setMe(this, mUploadedMeDetails, meProfile.aboutMe, meProfile.gender));
}
Also used : Contact(com.vodafone360.people.datatypes.Contact)

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