use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.
the class NowPlusContactsTableTest method testServerSyncMethods.
@MediumTest
public void testServerSyncMethods() {
final String fnName = "testServerSyncMethods";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "Validates server sync methods");
SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
startSubTest(fnName, "Creating table");
createTable();
// add contacts and populate contactServerIdList
List<ServerIdInfo> contactServerIdList = new ArrayList<ServerIdInfo>();
final long contactIdBase = TestModule.generateRandomLong();
for (int i = 0; i < NUM_OF_CONTACTS; i++) {
Contact c = mTestModule.createDummyContactData();
if (i == 2) {
// Add duplicate server ID in database
c.contactID = contactIdBase;
}
c.userID = TestModule.generateRandomLong();
ServiceStatus status = ContactsTable.addContact(c, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
ServerIdInfo serverInfo = new ServerIdInfo();
serverInfo.localId = c.localContactID;
serverInfo.serverId = contactIdBase + i;
serverInfo.userId = c.userID;
contactServerIdList.add(serverInfo);
}
// Add duplicate server ID in list from server
Contact duplicateContact = mTestModule.createDummyContactData();
duplicateContact.userID = TestModule.generateRandomLong();
ServiceStatus status = ContactsTable.addContact(duplicateContact, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
ServerIdInfo serverInfo = new ServerIdInfo();
serverInfo.localId = duplicateContact.localContactID;
serverInfo.serverId = contactIdBase + 1;
serverInfo.userId = duplicateContact.userID;
contactServerIdList.add(serverInfo);
List<ContactIdInfo> dupList = new ArrayList<ContactIdInfo>();
status = ContactsTable.syncSetServerIds(contactServerIdList, dupList, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
// fetch server ids
HashSet<Long> serverIds = new HashSet<Long>();
status = ContactsTable.fetchContactServerIdList(serverIds, readableDb);
assertEquals(ServiceStatus.SUCCESS, status);
// validate if lists have the same sizes
assertEquals(2, dupList.size());
assertEquals(contactServerIdList.size() - 2, serverIds.size());
assertEquals(Long.valueOf(dupList.get(0).localId), contactServerIdList.get(0).localId);
assertEquals(contactServerIdList.get(0).serverId, dupList.get(0).serverId);
assertEquals(duplicateContact.localContactID, Long.valueOf(dupList.get(1).localId));
assertEquals(Long.valueOf(contactIdBase + 1), dupList.get(1).serverId);
// Need to convert HashSet into an Arraylist, otherwise it's not possible to compare
// HashSet is not sorted!
ArrayList<Long> serverIdsArrayList = new ArrayList<Long>(serverIds);
Collections.sort(serverIdsArrayList);
final Iterator<Long> serverIdsIt = serverIdsArrayList.iterator();
for (int i = 1; i < contactServerIdList.size() - 1; i++) {
Long actServerId = serverIdsIt.next();
assertEquals(contactServerIdList.get(i).serverId, actServerId);
}
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, "");
}
use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.
the class NowPlusContactsTableTest method testFetchContactFormNativeId.
@MediumTest
public void testFetchContactFormNativeId() {
final String fnName = "testFetchContactFormNativeId";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "tests fetchContactFormNativeId a contact id");
SQLiteDatabase writableDb = mTestDatabase.getWritableDatabase();
startSubTest(fnName, "Creating table");
createTable();
startSubTest(fnName, "Add Contact");
Contact contact = mTestModule.createDummyContactData();
contact.userID = TestModule.generateRandomLong();
contact.nativeContactId = TestModule.generateRandomInt();
Long serverId = TestModule.generateRandomLong();
ServiceStatus status = ContactsTable.addContact(contact, writableDb);
assertEquals(ServiceStatus.SUCCESS, status);
assertTrue(ContactsTable.modifyContactServerId(contact.localContactID, serverId, contact.userID, writableDb));
ContactIdInfo idInfo = ContactsTable.fetchContactIdFromNative(contact.nativeContactId, writableDb);
assertTrue(idInfo.localId == contact.localContactID);
assertEquals(serverId, idInfo.serverId);
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, "");
}
use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.
the class NowPlusContactsTest method testOnUpgrade.
@SmallTest
public void testOnUpgrade() {
assertTrue(initialise());
mDatabaseHelper.removeUserData();
ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
assertEquals(ServiceStatus.SUCCESS, status);
int oldVersion = TestModule.generateRandomInt();
int newVersion = TestModule.generateRandomInt();
SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
mDatabaseHelper.onUpgrade(db, oldVersion, newVersion);
shutdown();
}
use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.
the class NowPlusContactsTest method testAddContactDetail.
@SmallTest
@Suppress
public void testAddContactDetail() {
assertTrue(initialise());
mDatabaseHelper.removeUserData();
ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
assertEquals(ServiceStatus.SUCCESS, status);
Contact addedContact = new Contact();
status = mDatabaseHelper.addContact(addedContact);
assertEquals(ServiceStatus.SUCCESS, status);
ContactDetail detail = new ContactDetail();
mTestModule.createDummyDetailsData(detail);
detail.localContactID = addedContact.localContactID;
status = mDatabaseHelper.addContactDetail(detail);
assertEquals(ServiceStatus.SUCCESS, status);
ContactDetail fetchedDetail = new ContactDetail();
status = mDatabaseHelper.fetchContactDetail(detail.localDetailID, fetchedDetail);
assertEquals(ServiceStatus.SUCCESS, status);
assertTrue(DatabaseHelper.doDetailsMatch(detail, fetchedDetail));
assertTrue(!DatabaseHelper.hasDetailChanged(detail, fetchedDetail));
assertEquals(ServiceStatus.SUCCESS, mDatabaseHelper.deleteAllGroups());
List<ServerIdInfo> serverIdList = new ArrayList<ServerIdInfo>();
ServerIdInfo info = new ServerIdInfo();
info.localId = fetchedDetail.localDetailID;
info.serverId = fetchedDetail.localDetailID + 1;
serverIdList.add(info);
status = ContactDetailsTable.syncSetServerIds(serverIdList, mDatabaseHelper.getWritableDatabase());
assertEquals(ServiceStatus.SUCCESS, status);
status = mDatabaseHelper.fetchContactDetail(detail.localDetailID, fetchedDetail);
assertEquals(ServiceStatus.SUCCESS, status);
assertEquals(info.serverId, fetchedDetail.unique_id);
shutdown();
}
use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.
the class GroupsEngine method processCommsResponse.
@Override
protected void processCommsResponse(DecodedResponse resp) {
LogUtils.logD("DownloadGroups.processCommsResponse()");
ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.ITEM_LIST_DATA_TYPE, resp.mDataTypes);
if (status == ServiceStatus.SUCCESS) {
final List<GroupItem> tempGroupList = new ArrayList<GroupItem>();
for (int i = 0; i < resp.mDataTypes.size(); i++) {
ItemList itemList = (ItemList) resp.mDataTypes.get(i);
if (itemList.mType != ItemList.Type.group_privacy) {
completeUiRequest(ServiceStatus.ERROR_UNEXPECTED_RESPONSE);
return;
}
// TODO: why cloning the list?
for (int j = 0; j < itemList.mItemList.size(); j++) {
tempGroupList.add((GroupItem) itemList.mItemList.get(j));
}
}
LogUtils.logI("DownloadGroups.processCommsResponse() - No of groups " + tempGroupList.size());
if (mPageNo == 0) {
// clear old groups if we request the first groups page
mDb.deleteAllGroups();
}
status = GroupsTable.addGroupList(tempGroupList, mDb.getWritableDatabase());
if (ServiceStatus.SUCCESS != status) {
completeUiRequest(status);
return;
}
mNoOfGroupsFetched += tempGroupList.size();
if (tempGroupList.size() < MAX_DOWN_PAGE_SIZE) {
completeUiRequest(ServiceStatus.SUCCESS);
return;
}
mPageNo++;
requestNextGroupsPage();
return;
}
LogUtils.logE("DownloadGroups.processCommsResponse() - Error requesting Zyb groups, error = " + status);
completeUiRequest(status);
}
Aggregations