From 453dd019282ee8630d3ed7020a8a6a281e29a421 Mon Sep 17 00:00:00 2001 From: youtaol Date: Thu, 5 Jul 2012 18:49:58 +0800 Subject: [PATCH] Add code to drop the maps data, fusion table table of a track after send it Google. Change some code to make end-to-end tests run more stable. --- .../endtoendtest/CreateAndSendTrackTest.java | 4 +- .../endtoendtest/EndToEndTestUtils.java | 3 + .../mytracks/endtoendtest/GoogleUtils.java | 62 ++++++++++++++++++- .../mytracks/endtoendtest/SettingTest.java | 6 +- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java index a96f168fd..5c62165e6 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java @@ -124,7 +124,7 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2(); @@ -118,8 +122,6 @@ public class GoogleUtils { * @return true means find the map */ static boolean searchMapByTitle(String title, Activity activity) { - account = AccountManager.get(activity.getApplicationContext()).getAccountsByType( - Constants.ACCOUNT_TYPE)[0]; if (getMaps(activity.getApplicationContext())) { for (MapsMapMetadata oneData : mapData) { if (oneData.getTitle().indexOf(title) > -1) { @@ -129,6 +131,36 @@ public class GoogleUtils { } return false; } + + /** + * Drops map which contain the string in title and is created by My Tracks on Google Maps. + * + * @param title the title of track to drop + * @param activity activity to get context + */ + static void dropMaps(String title, Activity activity) { + Context context = activity.getApplicationContext(); + // Get all maps at first. + getMaps(context); + + // Drop maps. + MapsClient mapsClient = new MapsClient(GDataClientFactory.getGDataClient(context), + new XmlMapsGDataParserFactory(new AndroidXmlParserFactory())); + for (MapsMapMetadata oneData : mapData) { + // Only drop maps created by My Tracks. + if (oneData.getDescription().indexOf("My Tracks") > -1 && oneData.getTitle().indexOf(title) > -1) { + try { + account = AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE)[0]; + authToken = AccountManager.get(context).blockingGetAuthToken(account, + MapsConstants.SERVICE_NAME, false); + + mapsClient.deleteEntry(oneData.getGDataEditUri(), authToken); + } catch (Exception e) { + Log.d(LOG_TAG, "Unable to drop map", e); + } + } + } + } /** * Searches a doc in user's Google Documents. @@ -217,7 +249,6 @@ public class GoogleUtils { */ static boolean searchFusionTableByTitle(String title, Activity activity) { Context context = activity.getApplicationContext(); - account = AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE)[0]; try { HttpResponse response = sendFusionTableQuery("SHOW TABLES", context); // We can use index of method to check new table for every track name is unique. @@ -230,6 +261,31 @@ public class GoogleUtils { return false; } + /** + * Remove one fusion table which contain the string in title of current user. + * + * @param title the title of a track to drop + * @param activity to get context + */ + static void dropFusionTables(String title, Activity activity) { + Context context = activity.getApplicationContext(); + + HttpResponse response = sendFusionTableQuery("SHOW TABLES", context); + String[] rowsTable; + try { + rowsTable = response.parseAsString().split("\n"); + for (String string : rowsTable) { + // If the first column is all figure, it is the table id. + String regularExpression = "^[0-9]*$"; + if (string.split(",")[0].matches(regularExpression) && string.indexOf(title) > -1) { + sendFusionTableQuery("DROP TABLE " + string.split(",")[0], context); + } + } + } catch (IOException e) { + Log.d(LOG_TAG, "Failed when delete all fusion tables.", e); + } + } + /** * Sends query to operate fusion tables. * diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SettingTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SettingTest.java index dbac0b1dd..22787e4e8 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SettingTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SettingTest.java @@ -91,9 +91,11 @@ public class SettingTest extends ActivityInstrumentationTestCase2