Make Gtasks sync unit tests compile and pass

pull/14/head
Sam Bosley 14 years ago
parent 2d22778505
commit 338e818933

@ -5,8 +5,5 @@
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry combineaccessrules="false" kind="src" path="/astrid"/> <classpathentry combineaccessrules="false" kind="src" path="/astrid"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry combineaccessrules="false" kind="src" path="/astridApi"/>
<classpathentry combineaccessrules="false" kind="src" path="/facebook"/>
<classpathentry combineaccessrules="false" kind="src" path="/GreenDroid"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

@ -9,5 +9,3 @@
# Project target. # Project target.
target=android-14 target=android-14
android.library.reference.1=../api
android.library.reference.2=../facebook/facebook

@ -24,16 +24,16 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.api.GtasksApiUtilities; import com.todoroo.astrid.gtasks.api.GtasksApiUtilities;
import com.todoroo.astrid.gtasks.api.GtasksInvoker; import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import com.todoroo.astrid.gtasks.auth.GtasksTokenValidator; import com.todoroo.astrid.gtasks.auth.GtasksTokenValidator;
import com.todoroo.astrid.gtasks.sync.GtasksSyncProvider; import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider;
import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.sync.SyncResultCallbackAdapter;
import com.todoroo.astrid.test.DatabaseTestCase; import com.todoroo.astrid.test.DatabaseTestCase;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class GtasksNewSyncTest extends DatabaseTestCase { public class GtasksNewSyncTest extends DatabaseTestCase {
private static GtasksInvoker gtasksService; private static GtasksInvoker gtasksService;
private GtasksSyncProvider syncProvider;
private static boolean initialized = false; private static boolean initialized = false;
private boolean bypassTests = false; private boolean bypassTests = false;
@ -473,8 +473,21 @@ public class GtasksNewSyncTest extends DatabaseTestCase {
//Perform a synchronization //Perform a synchronization
private void whenInvokeSync() { private void whenInvokeSync() {
syncProvider.synchronize(getContext()); new GtasksSyncV2Provider().synchronizeActiveTasks(true, new SyncResultCallbackAdapter() {
gtasksService = syncProvider.getGtasksService(); //This is to prevent token mismatch; the sync provider invalidates the old one @Override
public void finished() {
synchronized(GtasksNewSyncTest.this) {
GtasksNewSyncTest.this.notify();
}
}
});
try {
synchronized(this) {
wait();
}
} catch (InterruptedException e) {
fail("Interrupted while waiting for sync to finish");
}
} }
@Override @Override
@ -486,8 +499,6 @@ public class GtasksNewSyncTest extends DatabaseTestCase {
} }
setupTestList(); setupTestList();
syncProvider = new GtasksSyncProvider();
} }
private void initializeTestService() throws Exception { private void initializeTestService() throws Exception {

@ -33,7 +33,7 @@ public class GtasksSyncOnSaveTest extends DatabaseTestCase {
@Autowired GtasksMetadataService gtasksMetadataService; @Autowired GtasksMetadataService gtasksMetadataService;
@Autowired GtasksPreferenceService gtasksPreferenceService; @Autowired GtasksPreferenceService gtasksPreferenceService;
private GtasksInvoker gtasksService; private static GtasksInvoker gtasksService;
private boolean initialized = false; private boolean initialized = false;
private boolean bypassTests = false; private boolean bypassTests = false;
private static final String TEST_ACCOUNT = "sync_tester2@astrid.com"; private static final String TEST_ACCOUNT = "sync_tester2@astrid.com";

@ -1,131 +0,0 @@
/*package com.todoroo.astrid.gtasks;
import java.util.ArrayList;
import java.util.List;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.sync.GtasksSyncProvider;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.test.DatabaseTestCase;
public class GtasksSyncTest extends DatabaseTestCase {
private static final String TEST_USERNAME = "astridtasktest@gmail.com";
private static final String TEST_PASSWORD = "tasktest0000";
private static boolean initialized = false;
private static GoogleTaskService testService;
private static GoogleTaskListInfo taskList;
@Autowired TaskService taskService;
@Autowired GtasksPreferenceService gtasksPreferenceService;
// --- tests
// !!! This test is disabled until it works :(
public void DISABLED_testBasicTaskCreation() throws Exception {
Task task = givenTask("wasabi");
whenSynchronizing();
thenAssertTaskExistsRemotely(task);
}
public void DISABLED_testTaskWithDueDate() throws Exception {
Task task = givenTask("wasabi");
task.setValue(Task.DUE_DATE, task.createDueDate(Task.URGENCY_SPECIFIC_DAY,
DateUtilities.now()));
whenSynchronizing();
GoogleTaskTask remote = thenAssertTaskExistsRemotely(task);
assertTrue(remote.getTask_date() > DateUtilities.now() - DateUtilities.ONE_DAY);
assertEquals(task.getValue(Task.DUE_DATE), refetchLocal(task).getValue(Task.DUE_DATE));
}
public void DISABLED_testTaskWithDueTime() throws Exception {
Task task = givenTask("wasabi");
task.setValue(Task.DUE_DATE, task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME,
DateUtilities.now()));
whenSynchronizing();
GoogleTaskTask remote = thenAssertTaskExistsRemotely(task);
assertTrue(remote.getTask_date() > DateUtilities.now() - DateUtilities.ONE_DAY);
assertEquals(task.getValue(Task.DUE_DATE), refetchLocal(task).getValue(Task.DUE_DATE));
}
// --- helpers
private Task refetchLocal(Task task) {
return taskService.fetchById(task.getId(), Task.PROPERTIES);
}
private GoogleTaskTask thenAssertTaskExistsRemotely(Task task) throws Exception {
List<GoogleTaskTask> tasks = testService.getTasks(taskList.getId());
for(GoogleTaskTask remote : tasks) {
if(remote.getName().equals(task.getValue(Task.TITLE)))
return remote;
}
fail("Task didn't exist remotely: " + task);
return null;
}
private void whenSynchronizing() {
new GtasksSyncProvider().synchronize(getContext());
}
private Task givenTask(String title) {
Task task = new Task();
task.setValue(Task.TITLE, title + System.currentTimeMillis());
taskService.save(task);
return task;
}
// --- setup stuff
// set up task list and clean it out
protected void DISABLED_setUp() throws Exception {
super.setUp();
if(!initialized)
initializeTestService();
ArrayList<ListAction> actions = new ArrayList<ListAction>();
ListActions l = new ListActions();
for(GoogleTaskTask task : testService.getTasks(taskList.getId())) {
actions.add(l.modifyTask(task.getId()).deleted(true).done());
}
testService.executeListActions(taskList.getId(), actions.toArray(new ListAction[actions.size()]));
}
public void initializeTestService() throws Exception {
GoogleConnectionManager gcm = new GoogleConnectionManager(TEST_USERNAME, TEST_PASSWORD);
testService = new GoogleTaskService(gcm);
GoogleTaskView taskView = testService.getTaskView();
GoogleTaskListInfo[] lists = taskView.getAllLists();
outer: {
for(GoogleTaskListInfo list : lists) {
if("AstridUnitTests".equals(list.getName())) {
taskList = list;
break outer;
}
}
fail("could not find the main list");
}
initialized = true;
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, taskList.getId());
Preferences.setString(GtasksPreferenceService.PREF_USER_NAME, TEST_USERNAME);
Preferences.setString(GtasksPreferenceService.PREF_PASSWORD, TEST_PASSWORD);
gtasksPreferenceService.setToken(gcm.getToken());
}
}//*/

@ -21,6 +21,7 @@ import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.repeats.RepeatTaskCompleteListener; import com.todoroo.astrid.repeats.RepeatTaskCompleteListener;
import com.todoroo.astrid.test.DatabaseTestCase; import com.todoroo.astrid.test.DatabaseTestCase;
@ -38,11 +39,11 @@ abstract public class AbstractSyncRepeatTests<REMOTE_MODEL> extends DatabaseTest
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
Preferences.setStringFromInteger(R.string.p_default_urgency_key, 0); Preferences.setStringFromInteger(R.string.p_default_urgency_key, 0);
RepeatTaskCompleteListener.setSkipActFmCheck(true);
} }
private void saveAndTriggerRepeatListener(Task task) { private void saveAndTriggerRepeatListener(Task task) {
Flags.set(Flags.ACTFM_SUPPRESS_SYNC); task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
if(task.isSaved()) if(task.isSaved())
taskDao.saveExisting(task); taskDao.saveExisting(task);
else else

@ -18,13 +18,13 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmDataService; import com.todoroo.astrid.actfm.sync.ActFmDataService;
import com.todoroo.astrid.actfm.sync.ActFmInvoker; import com.todoroo.astrid.actfm.sync.ActFmInvoker;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncProvider;
import com.todoroo.astrid.actfm.sync.ActFmSyncService; import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.actfm.sync.ActFmSyncV2Provider;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.repeats.RepeatTaskCompleteListener;
import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.sync.SyncResultCallbackAdapter;
public class RepeatTestsActFmSync extends AbstractSyncRepeatTests<Task> { public class RepeatTestsActFmSync extends AbstractSyncRepeatTests<Task> {
@ -42,7 +42,6 @@ public class RepeatTestsActFmSync extends AbstractSyncRepeatTests<Task> {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
Preferences.setStringFromInteger(R.string.p_default_urgency_key, 0); Preferences.setStringFromInteger(R.string.p_default_urgency_key, 0);
RepeatTaskCompleteListener.setSkipActFmCheck(false);
if (!initialized) { if (!initialized) {
initializeTestService(); initializeTestService();
@ -53,7 +52,7 @@ public class RepeatTestsActFmSync extends AbstractSyncRepeatTests<Task> {
private void initializeTestService() throws Exception { private void initializeTestService() throws Exception {
invoker = new ActFmInvoker(); invoker = new ActFmInvoker();
authenticate(TEST_ACCOUNT, null, ActFmInvoker.PROVIDER_PASSWORD, TEST_PASSWORD); authenticate(TEST_ACCOUNT, null, null, ActFmInvoker.PROVIDER_PASSWORD, TEST_PASSWORD);
initialized = true; initialized = true;
} }
@ -70,9 +69,9 @@ public class RepeatTestsActFmSync extends AbstractSyncRepeatTests<Task> {
} }
} }
private void authenticate(String email, String name, String provider, String secret) { private void authenticate(String email, String firstName, String lastName, String provider, String secret) {
try { try {
JSONObject result = invoker.authenticate(email, name, provider, secret); JSONObject result = invoker.authenticate(email, firstName, lastName, provider, secret);
String token = invoker.getToken(); String token = invoker.getToken();
postAuthenticate(result, token); postAuthenticate(result, token);
} catch (IOException e) { } catch (IOException e) {
@ -96,7 +95,21 @@ public class RepeatTestsActFmSync extends AbstractSyncRepeatTests<Task> {
@Override @Override
protected void waitAndSync() { protected void waitAndSync() {
AndroidUtilities.sleepDeep(3000L); AndroidUtilities.sleepDeep(3000L);
new ActFmSyncProvider().synchronize(null); new ActFmSyncV2Provider().synchronizeActiveTasks(true, new SyncResultCallbackAdapter() {
@Override
public void finished() {
synchronized(RepeatTestsActFmSync.this) {
RepeatTestsActFmSync.this.notify();
}
}
});
try {
synchronized(this) {
wait();
}
} catch (InterruptedException e) {
fail("Interrupted while waiting for sync to finish");
}
AndroidUtilities.sleepDeep(3000L); AndroidUtilities.sleepDeep(3000L);
} }

@ -25,9 +25,9 @@ import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.api.GtasksApiUtilities; import com.todoroo.astrid.gtasks.api.GtasksApiUtilities;
import com.todoroo.astrid.gtasks.api.GtasksInvoker; import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import com.todoroo.astrid.gtasks.auth.GtasksTokenValidator; import com.todoroo.astrid.gtasks.auth.GtasksTokenValidator;
import com.todoroo.astrid.gtasks.sync.GtasksSyncProvider; import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider;
import com.todoroo.astrid.repeats.RepeatTaskCompleteListener;
import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.sync.SyncResultCallbackAdapter;
public class RepeatTestsGtasksSync extends AbstractSyncRepeatTests<com.google.api.services.tasks.model.Task> { public class RepeatTestsGtasksSync extends AbstractSyncRepeatTests<com.google.api.services.tasks.model.Task> {
@ -45,7 +45,6 @@ public class RepeatTestsGtasksSync extends AbstractSyncRepeatTests<com.google.ap
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
Preferences.setStringFromInteger(R.string.p_default_urgency_key, 0); Preferences.setStringFromInteger(R.string.p_default_urgency_key, 0);
RepeatTaskCompleteListener.setSkipActFmCheck(true);
if (!initialized) { if (!initialized) {
initializeTestService(); initializeTestService();
@ -57,7 +56,21 @@ public class RepeatTestsGtasksSync extends AbstractSyncRepeatTests<com.google.ap
@Override @Override
protected void waitAndSync() { protected void waitAndSync() {
AndroidUtilities.sleepDeep(3000L); AndroidUtilities.sleepDeep(3000L);
new GtasksSyncProvider().synchronize(null); new GtasksSyncV2Provider().synchronizeActiveTasks(true, new SyncResultCallbackAdapter() {
@Override
public void finished() {
synchronized(RepeatTestsGtasksSync.this) {
RepeatTestsGtasksSync.this.notify();
}
}
});
try {
synchronized(this) {
wait();
}
} catch (InterruptedException e) {
fail("Interrupted while waiting for sync to finish");
}
AndroidUtilities.sleepDeep(3000L); AndroidUtilities.sleepDeep(3000L);
} }

Loading…
Cancel
Save