summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAnthony Lee <anthonylee@google.com>2014-04-07 11:15:14 -0700
committerAnthony Lee <anthonylee@google.com>2014-04-07 21:18:00 -0700
commit102e1cf9d34fceebbad64356e58e3427ee4e6da4 (patch)
tree15d7a3ee223829f676508d83d6e8613c0732b0ec /tests
parent73d62f3d0a2e625006c4119f9bd5d330eb38086e (diff)
downloadandroid_packages_apps_Exchange-102e1cf9d34fceebbad64356e58e3427ee4e6da4.tar.gz
android_packages_apps_Exchange-102e1cf9d34fceebbad64356e58e3427ee4e6da4.tar.bz2
android_packages_apps_Exchange-102e1cf9d34fceebbad64356e58e3427ee4e6da4.zip
b/11435875. Add support for fileAs when uploading new contacts.
When a new contact is created on the device, we do not push a fileAs up to Exchange and that causes problems when you view the contact via OWA to check the results. The challenge is to not push a fileAs if one was already created (i.e. the contact was created on the server). We handle this by actually syncing the fileAs from the server and being smart enough not to overwrite if it exists on the upload. Generation of the fileAs string is done in 1 of 2 methods. The first is to use the alternative display name stored in the RawContacts information for this contact. The fallback method is to generate a fileAs string using a combination of structured name fields and available email addresses. Unit tests are included. Change-Id: I957071da758801d2e5c2799fc1f0b4fdbe0b4e4d
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/exchange/eas/EasSyncContactsTests.java190
1 files changed, 190 insertions, 0 deletions
diff --git a/tests/src/com/android/exchange/eas/EasSyncContactsTests.java b/tests/src/com/android/exchange/eas/EasSyncContactsTests.java
new file mode 100644
index 00000000..8958d046
--- /dev/null
+++ b/tests/src/com/android/exchange/eas/EasSyncContactsTests.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.exchange.eas;
+
+import android.content.ContentValues;
+import android.provider.ContactsContract.CommonDataKinds.Email;
+import android.provider.ContactsContract.CommonDataKinds.StructuredName;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.exchange.utility.ExchangeTestCase;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * You can run this entire test case with:
+ * runtest -c com.android.exchange.eas.EasSyncContactsTests exchange
+ */
+@SmallTest
+public class EasSyncContactsTests extends ExchangeTestCase {
+
+ // Return null.
+ public void testTryGetStringDataEverythingNull() throws IOException {
+ final String result = EasSyncContacts.tryGetStringData(null, null);
+ assertNull(result);
+ }
+
+ // Return null.
+ public void testTryGetStringDataNullContentValues() throws IOException {
+ final String result = EasSyncContacts.tryGetStringData(null, "TestColumn");
+ assertNull(result);
+ }
+
+ // Return null.
+ public void testTryGetStringDataNullColumnName() throws IOException {
+ final ContentValues contentValues = new ContentValues();
+ contentValues.put("test_column", "test_value");
+ final String result = EasSyncContacts.tryGetStringData(contentValues, null);
+ assertNull(result);
+ }
+
+ // Return null.
+ public void testTryGetStringDataDoesNotContainColumn() throws IOException {
+ final ContentValues contentValues = new ContentValues();
+ contentValues.put("test_column", "test_value");
+ final String result = EasSyncContacts.tryGetStringData(contentValues, "does_not_exist");
+ assertNull(result);
+ }
+
+ // Return null.
+ public void testTryGetStringDataEmptyColumnValue() throws IOException {
+ final String columnName = "test_column";
+ final ContentValues contentValues = new ContentValues();
+ contentValues.put(columnName, "");
+ final String result = EasSyncContacts.tryGetStringData(contentValues, columnName);
+ assertNull(result);
+ }
+
+ // Return the data type forced to be a string.
+ // TODO: Test other data types.
+ public void testTryGetStringDataWrongType() throws IOException {
+ final String columnName = "test_column";
+ final Integer columnValue = new Integer(10);
+ final String columnValueAsString = columnValue.toString();
+ final ContentValues contentValues = new ContentValues();
+ contentValues.put(columnName, columnValue);
+ final String result = EasSyncContacts.tryGetStringData(contentValues, columnName);
+ assert(result.equals(columnValueAsString));
+ }
+
+ // Return the value as a string.
+ public void testTryGetStringDataSuccess() throws IOException {
+ final String columnName = "test_column";
+ final String columnValue = "test_value";
+ final ContentValues contentValues = new ContentValues();
+ contentValues.put(columnName, columnValue);
+ final String result = EasSyncContacts.tryGetStringData(contentValues, columnName);
+ assertTrue(result.equals(columnValue));
+ }
+
+ // Return null.
+ public void testGenerateFileAsNullParameters() throws IOException {
+ final String result = EasSyncContacts.generateFileAs(null, null);
+ assertNull(result);
+ }
+
+ // Should still return null because there is no name and no email.
+ public void testGenerateFileAsNullNameValuesAndEmptyList() throws IOException {
+ final ArrayList<ContentValues> emailList = new ArrayList<ContentValues>();
+ final String result = EasSyncContacts.generateFileAs(null, emailList);
+ assertNull(result);
+ }
+
+ // Just return the first email address that was passed in.
+ public void testGenerateFileAsNullNameValues() throws IOException {
+ final ArrayList<ContentValues> emailList = new ArrayList<ContentValues>();
+ final ContentValues emailValue = new ContentValues();
+ final String emailString = "anthonylee@google.com";
+ emailValue.put(Email.DATA, emailString);
+ emailList.add(emailValue);
+ final String result = EasSyncContacts.generateFileAs(null, emailList);
+ assertTrue(result.equals(emailString));
+ }
+
+ // Just return the formatted name.
+ public void testGenerateFileAsNullEmailValues() throws IOException {
+ final ContentValues nameValues = new ContentValues();
+ final String firstName = "Joe";
+ final String middleName = "Bob";
+ final String lastName = "Smith";
+ final String suffix = "Jr.";
+ nameValues.put(StructuredName.GIVEN_NAME, firstName);
+ nameValues.put(StructuredName.FAMILY_NAME, lastName);
+ nameValues.put(StructuredName.MIDDLE_NAME, middleName);
+ nameValues.put(StructuredName.SUFFIX, suffix);
+ final String result = EasSyncContacts.generateFileAs(nameValues, null);
+ final String generatedName = lastName + " " + suffix + ", " + firstName + " " + middleName;
+ assertTrue(generatedName.equals(result));
+ }
+
+ // This will generate a string that is similar to the full string but with no first name.
+ public void testGenerateFileAsNullFirstName() throws IOException {
+ final ContentValues nameValues = new ContentValues();
+ final String middleName = "Bob";
+ final String lastName = "Smith";
+ final String suffix = "Jr.";
+ nameValues.put(StructuredName.FAMILY_NAME, lastName);
+ nameValues.put(StructuredName.MIDDLE_NAME, middleName);
+ nameValues.put(StructuredName.SUFFIX, suffix);
+ final String result = EasSyncContacts.generateFileAs(nameValues, null);
+ final String generatedName = lastName + " " + suffix + ", " + middleName;
+ assertTrue(generatedName.equals(result));
+ }
+
+ // This will generate a string that is missing both the last name and the suffix.
+ public void testGenerateFileAsNullLastName() throws IOException {
+ final ContentValues nameValues = new ContentValues();
+ final String firstName = "Joe";
+ final String middleName = "Bob";
+ final String suffix = "Jr.";
+ nameValues.put(StructuredName.GIVEN_NAME, firstName);
+ nameValues.put(StructuredName.MIDDLE_NAME, middleName);
+ nameValues.put(StructuredName.SUFFIX, suffix);
+ final String result = EasSyncContacts.generateFileAs(nameValues, null);
+ final String generatedName = firstName + " " + middleName;
+ assertTrue(generatedName.equals(result));
+ }
+
+ // This will generate a string that is similar to the full name but missing the middle name.
+ public void testGenerateFileAsNullMiddleName() throws IOException {
+ final ContentValues nameValues = new ContentValues();
+ final String firstName = "Joe";
+ final String lastName = "Smith";
+ final String suffix = "Jr.";
+ nameValues.put(StructuredName.GIVEN_NAME, firstName);
+ nameValues.put(StructuredName.FAMILY_NAME, lastName);
+ nameValues.put(StructuredName.SUFFIX, suffix);
+ final String result = EasSyncContacts.generateFileAs(nameValues, null);
+ final String generatedName = lastName + " " + suffix + ", " + firstName;
+ assertTrue(generatedName.equals(result));
+ }
+
+ // Similar to the full name but no suffix.
+ public void testGenerateFileAsNullSuffix() throws IOException {
+ final ContentValues nameValues = new ContentValues();
+ final String firstName = "Joe";
+ final String middleName = "Bob";
+ final String lastName = "Smith";
+ nameValues.put(StructuredName.GIVEN_NAME, firstName);
+ nameValues.put(StructuredName.FAMILY_NAME, lastName);
+ nameValues.put(StructuredName.MIDDLE_NAME, middleName);
+ final String result = EasSyncContacts.generateFileAs(nameValues, null);
+ final String generatedName = lastName + ", " + firstName + " " + middleName;
+ assertTrue(generatedName.equals(result));
+ }
+}