Remove spreadsheet for the test activity on Google Drive.

This commit is contained in:
youtaol
2012-11-09 13:52:25 +08:00
parent 4c457c093c
commit 8458825932
2 changed files with 36 additions and 0 deletions
@@ -207,6 +207,40 @@ public class GoogleUtils {
return null;
}
/**
* Delete spreadsheet which name is title.
*
* @param title the name of spreadsheet
* @param activity to get context
*/
public static void deleteSpreadsheetByTitle(String title, Activity activity) {
Context context = activity.getApplicationContext();
DocumentsClient documentsClient = new DocumentsClient(
GDataClientFactory.getGDataClient(context), new XmlDocsGDataParserFactory(
new AndroidXmlParserFactory()));
try {
String documentsAuthToken = AccountManager.get(context).blockingGetAuthToken(
getAccount(context), documentsClient.getServiceName(), false);
String uri = String.format(Locale.US, SendDocsUtils.GET_SPREADSHEET_BY_TITLE_URI,
URLEncoder.encode(title, "utf-8"));
GDataParser gDataParser = documentsClient.getParserForFeed(Entry.class, uri,
documentsAuthToken);
gDataParser.init();
while (gDataParser.hasMoreData()) {
Entry entry = gDataParser.readNextEntry(null);
String entryTitle = entry.getTitle();
if (entryTitle.equals(title)) {
documentsClient.deleteEntry(entry.getEditUri(), documentsAuthToken);
Log.d(EndToEndTestUtils.LOG_TAG, "Delete one spreadsheet.");
}
}
} catch (Exception e) {
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to fetch spreadsheet.", e);
}
}
/**
* Searches docs in user's Google Documents.
*
@@ -76,6 +76,8 @@ public class SendToGoogleTest extends ActivityInstrumentationTestCase2<TrackList
public void testSendTwoTracksWithSameActivity() {
String testActivity = "(TestActivity)";
EndToEndTestUtils.activityType = testActivity;
GoogleUtils.deleteSpreadsheetByTitle("My Tracks-" + EndToEndTestUtils.activityType,
EndToEndTestUtils.activityMytracks);
EndToEndTestUtils.createSimpleTrack(1, false);
boolean result = sendToGoogle();
result = result && sendToGoogle();