Search in sources :

Example 1 with NativeContactsApiMockup

use of com.vodafone360.people.tests.engine.contactsync.NativeImporterTest.NativeContactsApiMockup in project 360-Engine-for-Android by 360.

the class NativeExporterTest method testExportToNativeWithUpdatedContacts_deletedDetails.

/**
     * Tests export to native with added details to a existing contacts.
     */
@Suppress
public void testExportToNativeWithUpdatedContacts_deletedDetails() {
    // add contacts on People side and sync them to native side
    final int NEW_CONTACTS_COUNT = 30;
    final NativeContactsApiMockup nativeMockup = new NativeContactsApiMockup();
    final PeopleContactsApiMockup peopleMockup = new PeopleContactsApiMockup(null);
    // add new contacts syncable contact on People side
    feedPeopleContactsApiWithNewSyncableContacts(peopleMockup, NEW_CONTACTS_COUNT);
    long[] nativeIdsFromPeople = peopleMockup.getNativeContactsIds();
    // shall be null because our PeopleContactsApiMockup will add them once synced
    assertEquals(null, nativeIdsFromPeople);
    long[] localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(NEW_CONTACTS_COUNT, localIds.length);
    long[] nativeIds = nativeMockup.getContactIds(null);
    assertEquals(null, nativeIds);
    // perform the export to native
    runNativeExporter(nativeMockup, peopleMockup);
    // check both sides are updated correctly
    nativeIdsFromPeople = peopleMockup.getNativeContactsIds();
    assertEquals(NEW_CONTACTS_COUNT, nativeIdsFromPeople.length);
    nativeIds = nativeMockup.getContactIds(null);
    assertEquals(NEW_CONTACTS_COUNT, nativeIds.length);
    localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(null, localIds);
    assertTrue(NativeImporterTest.compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
    // pick few contacts and add details to them
    ContactChange[][] addedDetails = new ContactChange[3][];
    addedDetails[0] = getNewDetails(peopleMockup, 1);
    peopleMockup.updateNativeContact(addedDetails[0]);
    addedDetails[1] = getNewDetails(peopleMockup, 2);
    peopleMockup.updateNativeContact(addedDetails[1]);
    addedDetails[2] = getNewDetails(peopleMockup, 5);
    peopleMockup.updateNativeContact(addedDetails[2]);
    // perform the export to native
    runNativeExporter(nativeMockup, peopleMockup);
    // check both sides are equivalent
    localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(null, localIds);
    assertTrue(NativeImporterTest.compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
    // remove the previously added details
    for (int i = 0; i < addedDetails.length; i++) {
        forceDetailsAsDeleteType(addedDetails[i]);
        peopleMockup.updateNativeContact(addedDetails[i]);
    }
    // perform the export to native
    runNativeExporter(nativeMockup, peopleMockup);
    // check both sides are equivalent
    localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(null, localIds);
    assertTrue(NativeImporterTest.compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
}
Also used : NativeContactsApiMockup(com.vodafone360.people.tests.engine.contactsync.NativeImporterTest.NativeContactsApiMockup) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 2 with NativeContactsApiMockup

use of com.vodafone360.people.tests.engine.contactsync.NativeImporterTest.NativeContactsApiMockup in project 360-Engine-for-Android by 360.

the class NativeExporterTest method testMultipleExportsToNativeWithNewContacts.

/**
     * Tests multiple exports to native with only new contacts.
     */
@Suppress
public void testMultipleExportsToNativeWithNewContacts() {
    final int NEW_CONTACTS_COUNT = 30;
    final NativeContactsApiMockup nativeMockup = new NativeContactsApiMockup();
    final PeopleContactsApiMockup peopleMockup = new PeopleContactsApiMockup(null);
    // add new contacts syncable contact on People side
    feedPeopleContactsApiWithNewSyncableContacts(peopleMockup, NEW_CONTACTS_COUNT);
    long[] nativeIdsFromPeople = peopleMockup.getNativeContactsIds();
    // shall be null because our PeopleContactsApiMockup will add them once synced
    assertEquals(null, nativeIdsFromPeople);
    long[] localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(NEW_CONTACTS_COUNT, localIds.length);
    long[] nativeIds = nativeMockup.getContactIds(null);
    assertEquals(null, nativeIds);
    // perform the export to native
    runNativeExporter(nativeMockup, peopleMockup);
    // check both sides are updated correctly
    nativeIdsFromPeople = peopleMockup.getNativeContactsIds();
    assertEquals(NEW_CONTACTS_COUNT, nativeIdsFromPeople.length);
    nativeIds = nativeMockup.getContactIds(null);
    assertEquals(NEW_CONTACTS_COUNT, nativeIds.length);
    localIds = peopleMockup.getNativeSyncableContactIds();
    assertEquals(null, localIds);
    assertTrue(NativeImporterTest.compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
}
Also used : NativeContactsApiMockup(com.vodafone360.people.tests.engine.contactsync.NativeImporterTest.NativeContactsApiMockup) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 3 with NativeContactsApiMockup

use of com.vodafone360.people.tests.engine.contactsync.NativeImporterTest.NativeContactsApiMockup in project 360-Engine-for-Android by 360.

the class NativeImporterTest method addDetails.

/**
     * Adds details to the provided contact.
     * 
     * @param contact
     * @return
     */
private ContactChange[] addDetails(NativeContactsApiMockup ncam, ContactChange[] contact) {
    long nativeId = contact[0].getNabContactId();
    int index = contact.length;
    // create the new Contact
    ContactChange[] newContact = new ContactChange[contact.length + 2];
    // copy original info into it
    System.arraycopy(contact, 0, newContact, 0, contact.length);
    // add extra details
    newContact[index] = new ContactChange(ContactChange.KEY_VCARD_EMAIL, "xxxxx@xxxxx.xx", ContactChange.FLAG_WORK);
    newContact[index].setNabContactId(nativeId);
    newContact[index].setNabDetailId(ncam.getAndIncNabDetailId());
    index++;
    newContact[index] = new ContactChange(ContactChange.KEY_VCARD_PHONE, "+9912345678", ContactChange.FLAG_WORK);
    newContact[index].setNabContactId(nativeId);
    newContact[index].setNabDetailId(ncam.getAndIncNabDetailId());
    index++;
    return newContact;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 4 with NativeContactsApiMockup

use of com.vodafone360.people.tests.engine.contactsync.NativeImporterTest.NativeContactsApiMockup in project 360-Engine-for-Android by 360.

the class NativeImporterTest method testMultipleImportsFromNativeWithUpdatedContact_updatedDetails.

/**
     * Tests multiple imports from native with an updated contact via updated details.
     */
public void testMultipleImportsFromNativeWithUpdatedContact_updatedDetails() {
    final NativeContactsApiMockup nativeMockup = new NativeContactsApiMockup();
    final PeopleContactsApiMockup peopleMockup = new PeopleContactsApiMockup(null);
    // add new contacts on native side
    feedNativeContactsApi(nativeMockup, 20, null);
    long[] nativeIds = nativeMockup.getContactIds(null);
    assertEquals(20, nativeIds.length);
    // import the new contacts
    runNativeImporter(nativeMockup, peopleMockup);
    // compare contacts on both sides
    assertTrue(compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
    // pick an existing contact
    final ContactChange[] originalContact = nativeMockup.getContact(10);
    // modify its details
    for (int i = 0; i < originalContact.length; i++) {
        final ContactChange originalChange = originalContact[i];
        originalContact[i] = alterContactChangeValue(originalChange, originalChange.getValue() + "x9x");
    }
    nativeMockup.setContact(10, originalContact);
    // import the new contacts
    runNativeImporter(nativeMockup, peopleMockup);
    // compare contacts on both sides
    assertTrue(compareNativeAndPeopleContactsList(nativeMockup, null, peopleMockup));
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 5 with NativeContactsApiMockup

use of com.vodafone360.people.tests.engine.contactsync.NativeImporterTest.NativeContactsApiMockup in project 360-Engine-for-Android by 360.

the class NativeImporterTest method performNativeImport.

/**
     * Performs a native import and checks that the needed ticks are as expected.
     * 
     * @param ncam the NativeContactsApiMockup instance
     * @param pcam the PeopleContactsApiMockup instance
     * @param contactsCount the number of native contacts to setup and import
     */
private void performNativeImport(NativeContactsApiMockup ncam, PeopleContactsApiMockup pcam, float contactsCount) {
    final NativeImporter nativeImporter = new NativeImporter(pcam, ncam, false);
    final float requiredTicks = 1 + (contactsCount / NATIVE_IMPORTER_MAX_OPERATION_COUNT) + (contactsCount % NATIVE_IMPORTER_MAX_OPERATION_COUNT > 0 ? 1 : 0);
    // feed the native side
    feedNativeContactsApi(ncam, contactsCount, null);
    final long[] nativeIds = ncam.getContactIds(null);
    assertEquals(contactsCount, nativeIds.length);
    // setup the people client side
    long[] peopleIds = pcam.getNativeContactsIds();
    assertNull(peopleIds);
    for (int i = 0; i < requiredTicks; i++) {
        // check the importer state
        assertEquals(NativeImporter.RESULT_UNDEFINED, nativeImporter.getResult());
        assertTrue(!nativeImporter.isDone());
        // perform an import tick
        nativeImporter.tick();
    }
    // check the importer state, it shall have finished the import
    assertEquals(NativeImporter.RESULT_OK, nativeImporter.getResult());
    assertTrue(nativeImporter.isDone());
    // check that all the native contacts are on the people client side
    peopleIds = pcam.getNativeContactsIds();
    assertEquals(contactsCount, peopleIds.length);
    for (int i = 0; i < peopleIds.length; i++) {
        final ContactChange[] peopleContact = pcam.getContact(peopleIds[i]);
        final ContactChange[] nativeContact = pcam.getContact(nativeIds[i]);
        assertTrue(ContactChangeHelper.areChangeListsEqual(peopleContact, nativeContact, false));
    }
}
Also used : NativeImporter(com.vodafone360.people.engine.contactsync.NativeImporter) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Aggregations

NativeContactsApiMockup (com.vodafone360.people.tests.engine.contactsync.NativeImporterTest.NativeContactsApiMockup)6 Suppress (android.test.suitebuilder.annotation.Suppress)5 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)4 Account (com.vodafone360.people.engine.contactsync.NativeContactsApi.Account)1 NativeImporter (com.vodafone360.people.engine.contactsync.NativeImporter)1