Search in sources :

Example 1 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo 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 2 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo in project 360-Engine-for-Android by 360.

the class NowPlusChangeLogTest method testServerDeleteGroupRel.

@MediumTest
public void testServerDeleteGroupRel() {
    final String fnName = "testServerDeleteGroupRel";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "Delete group relations from the change log, validating all the way");
    startSubTest(fnName, "Creating table");
    createTable();
    startSubTest(fnName, "Check change log is empty");
    long noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Check change log is empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add group rel deletion to change log with group ID");
    final Long localContactId = TestModule.generateRandomLong();
    final List<Long> groupList = new ArrayList<Long>();
    mTestModule.addRandomGroup(groupList);
    final Long groupId = groupList.get(0);
    final Long serverContactId = TestModule.generateRandomLong();
    assertTrue(ContactChangeLogTable.deleteGroupRel(localContactId, serverContactId, groupId, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    final List<ContactChangeInfo> contactChangeList = new ArrayList<ContactChangeInfo>();
    assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_GROUP_REL, 0, 1000, mTestDatabase.getReadableDatabase()));
    assertTrue(contactChangeList.size() == 1);
    startSubTest(fnName, "Checking change log data");
    ContactChangeInfo info = contactChangeList.get(0);
    assertTrue(info.mContactChangeId != null);
    assertEquals(info.mGroupOrRelId, groupId);
    assertEquals(info.mLocalContactId, localContactId);
    assertTrue(info.mLocalDetailId == null);
    assertEquals(info.mServerContactId, serverContactId);
    assertTrue(info.mServerDetailId == null);
    assertTrue(info.mServerDetailKey == null);
    assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.DELETE_GROUP_REL);
    startSubTest(fnName, "Clear change log");
    assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log is now empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add deleted contact detail change to change log with no group ID (error expected)");
    assertFalse(ContactChangeLogTable.deleteGroupRel(localContactId, serverContactId, null, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log is empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact deleted log...");
    assertTrue(ContactChangeLogTable.addDeletedContactChange(localContactId, serverContactId, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Followed by delete group rel (error expected)");
    assertFalse(ContactChangeLogTable.deleteGroupRel(localContactId, serverContactId, groupId, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
    assertTrue(contactChangeList.size() == 1);
    startSubTest(fnName, "Clear delete contact from change log");
    assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(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, "");
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 3 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo in project 360-Engine-for-Android by 360.

the class SyncMeDbUtils method populateWithDeletedContactDetails.

/**
     * This method adds the deleted details to the detail list sent to server...
     * @param dbHelper DatabaseHelper - database 
     * @param contactDetails List<ContactDetail> - the deleted details list 
     * @param contactId Long - Me Profile local contact id.
     */
private static void populateWithDeletedContactDetails(final DatabaseHelper dbHelper, final List<ContactDetail> contactDetails, final Long contactId) {
    List<ContactChangeInfo> deletedDetails = new ArrayList<ContactChangeInfo>();
    if (!ContactChangeLogTable.fetchMeProfileChangeLog(deletedDetails, ContactChangeType.DELETE_DETAIL, dbHelper.getReadableDatabase(), contactId)) {
        LogUtils.logE("UploadServerContacts populateWithDeletedContactDetails -" + " Unable to fetch contact changes from database");
        return;
    }
    for (int i = 0; i < deletedDetails.size(); i++) {
        ContactChangeInfo info = deletedDetails.get(i);
        final ContactDetail detail = new ContactDetail();
        detail.localDetailID = info.mLocalDetailId;
        detail.key = info.mServerDetailKey;
        detail.unique_id = info.mServerDetailId;
        detail.deleted = true;
        contactDetails.add(detail);
    }
    dbHelper.deleteContactChanges(deletedDetails);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList)

Example 4 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo in project 360-Engine-for-Android by 360.

the class UploadServerContacts method processDeletedDetailsResp.

/**
     * Called when a server response is received during a deleted contact detail
     * sync. The server change log is updated. Possibly server errors are also
     * handled.
     * 
     * @param resp Response from server.
     */
private void processDeletedDetailsResp(final DecodedResponse resp) {
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_DETAIL_DELETION_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactDetailDeletion result = (ContactDetailDeletion) resp.mDataTypes.get(0);
        if (result.mDetails != null) {
            LogUtils.logV("UploadServerContacts." + "processDeletedDetailsResp() Deleted details " + result.mDetails.size());
        }
        ListIterator<ContactChangeInfo> infoIt = mContactChangeInfoList.listIterator();
        if (result.mContactId == null || result.mContactId == -1) {
            boolean first = true;
            while (infoIt.hasNext()) {
                ContactChangeInfo info = infoIt.next();
                if (first) {
                    first = false;
                    LogUtils.logE("UploadServerContacts." + "processDeletedDetailsResp() The server " + "failed to delete detail from the following " + "contact: LocalId = " + info.mLocalContactId + ", ServerId = " + info.mServerContactId);
                }
                mFailureList += "Failed to delete detail: " + info.mLocalDetailId + "\n";
            }
        } else if (result.mDetails != null) {
            for (ContactDetail d : result.mDetails) {
                if (!infoIt.hasNext()) {
                    complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
                    return;
                }
                ContactChangeInfo info = infoIt.next();
                if (!d.key.equals(info.mServerDetailKey)) {
                    LogUtils.logE("UploadServerContacts." + "processDeletedDetailsResp() The server " + "failed to delete the following detail: " + "LocalId = " + info.mLocalContactId + ", " + "ServerId = " + info.mServerContactId + ", key = " + info.mServerDetailKey + ", detail ID = " + info.mServerDetailId);
                    mFailureList += "Failed to delete detail: " + info.mLocalDetailId + "\n";
                }
            }
        }
        long startTime = System.nanoTime();
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        mContactChangeInfoList.clear();
        updateProgress();
        sendNextDeleteDetailsPage();
        return;
    }
    LogUtils.logE("UploadServerContacts.processModifiedDetailsResp() " + "Error requesting contact changes, error = " + status);
    complete(status);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ContactDetailDeletion(com.vodafone360.people.datatypes.ContactDetailDeletion) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 5 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo in project 360-Engine-for-Android by 360.

the class UploadServerContacts method sendNextDeleteContactsPage.

/**
     * Sends the next page of deleted contacts to the server.
     */
private void sendNextDeleteContactsPage() {
    mContactChangeInfoList.clear();
    long startTime = System.nanoTime();
    if (!ContactChangeLogTable.fetchContactChangeLog(mContactChangeInfoList, ContactChangeType.DELETE_CONTACT, 0, MAX_UP_PAGE_SIZE, mDb.getReadableDatabase())) {
        LogUtils.logE("UploadServerContacts.sendNextDeleteContactsPage() " + "Unable to fetch contact changes from database");
        complete(ServiceStatus.ERROR_DATABASE_CORRUPT);
        return;
    }
    mDbSyncTime += (System.nanoTime() - startTime);
    if (mContactChangeInfoList.size() == 0) {
        moveToNextState();
        return;
    }
    mContactIdList.clear();
    for (ContactChangeInfo info : mContactChangeInfoList) {
        if (info.mServerContactId != null) {
            mContactIdList.add(info.mServerContactId);
        }
    }
    if (mContactIdList.size() == 0) {
        startTime = System.nanoTime();
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        moveToNextState();
        return;
    }
    /** Debug output. **/
    if (Settings.ENABLED_CONTACTS_SYNC_TRACE) {
        LogUtils.logI("UploadServerContacts.sendNextDeleteContactsPage() " + "Contacts deleted:");
        for (Long id : mContactIdList) {
            LogUtils.logI("UploadServerContacts." + "sendNextDeleteContactsPage() Contact Id: " + id);
        }
    }
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        complete(NetworkAgent.getServiceStatusfromDisconnectReason());
        return;
    }
    mNoOfItemsSent = mContactIdList.size();
    setReqId(Contacts.deleteContacts(getEngine(), mContactIdList));
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)

Aggregations

ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)11 ArrayList (java.util.ArrayList)10 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 Cursor (android.database.Cursor)2 ContactChangeInfo (com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo)2 ServiceStatus (com.vodafone360.people.service.ServiceStatus)2 Contact (com.vodafone360.people.datatypes.Contact)1 ContactDetailDeletion (com.vodafone360.people.datatypes.ContactDetailDeletion)1 ContactListResponse (com.vodafone360.people.datatypes.ContactListResponse)1 GroupItem (com.vodafone360.people.datatypes.GroupItem)1