diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/export/ExportTest.java')
-rw-r--r-- | tests/src/cgeo/geocaching/export/ExportTest.java | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/tests/src/cgeo/geocaching/export/ExportTest.java b/tests/src/cgeo/geocaching/export/ExportTest.java index 848a1f7..21c45a0 100644 --- a/tests/src/cgeo/geocaching/export/ExportTest.java +++ b/tests/src/cgeo/geocaching/export/ExportTest.java @@ -6,12 +6,14 @@ import cgeo.CGeoTestCase; import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.LogEntry; +import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.FileUtils; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -23,21 +25,38 @@ public class ExportTest extends CGeoTestCase { final Geocache cache = new Geocache(); cache.setGeocode("GCX1234"); final LogEntry log = new LogEntry(1353244820000L, LogType.FOUND_IT, "Hidden in a tree"); - FieldNotes fieldNotes = new FieldNotes(); + final FieldNotes fieldNotes = new FieldNotes(); fieldNotes.add(cache, log); assertEquals("Non matching export " + fieldNotes.getContent(), "GCX1234,2012-11-18T13:20:20Z,Found it,\"Hidden in a tree\"\n", fieldNotes.getContent()); } - public static void testGpxExportSmilies() throws InterruptedException, ExecutionException { + public static void testGpxExportSmilies() throws InterruptedException, ExecutionException, IOException { final Geocache cache = new Geocache(); cache.setGeocode("GCX1234"); cache.setCoords(new Geopoint("N 49 44.000 E 8 37.000")); final LogEntry log = new LogEntry(1353244820000L, LogType.FOUND_IT, "Smile: \ud83d\ude0a"); DataStore.saveCache(cache, LoadFlags.SAVE_ALL); - DataStore.saveLogsWithoutTransaction(cache.getGeocode(), Collections.singletonList(log)); - ArrayList<Geocache> exportList = new ArrayList<Geocache>(); - exportList.add(cache); - GpxExportTester gpxExport = new GpxExportTester(); + DataStore.saveLogs(cache.getGeocode(), Collections.singletonList(log)); + assertCanExport(cache); + } + + public static void testGpxExportUnknownConnector() throws InterruptedException, ExecutionException, IOException { + final Geocache cache = new Geocache(); + cache.setGeocode("ABC123"); + cache.setCoords(new Geopoint("N 49 44.000 E 8 37.000")); + DataStore.saveCache(cache, LoadFlags.SAVE_ALL); + + assertThat(ConnectorFactory.getConnector(cache).getName()).isEqualTo("Unknown caches"); + assertCanExport(cache); + } + + private static void assertCanExport(final Geocache cache) throws InterruptedException, ExecutionException, IOException { + // enforce storing in database, as GPX will not take information from cache + cache.setDetailed(true); + DataStore.saveCache(cache, LoadFlags.SAVE_ALL); + + final List<Geocache> exportList = Collections.singletonList(cache); + final GpxExportTester gpxExport = new GpxExportTester(); File result = null; try { result = gpxExport.testExportSync(exportList); @@ -47,13 +66,23 @@ public class ExportTest extends CGeoTestCase { assertThat(result).isNotNull(); + // make sure we actually exported waypoints + final String gpx = org.apache.commons.io.FileUtils.readFileToString(result); + assertThat(gpx).contains("<wpt"); + assertThat(gpx).contains(cache.getGeocode()); + if (cache.getUrl() != null) { + assertThat(gpx).contains("<url>"); + } else { + assertThat(gpx).doesNotContain("<url>"); + } + FileUtils.deleteIgnoringFailure(result); } private static class GpxExportTester extends GpxExport { - public File testExportSync(List<Geocache> caches) throws InterruptedException, ExecutionException { - final ArrayList<String> geocodes = new ArrayList<String>(caches.size()); + public File testExportSync(final List<Geocache> caches) throws InterruptedException, ExecutionException { + final ArrayList<String> geocodes = new ArrayList<>(caches.size()); for (final Geocache cache : caches) { geocodes.add(cache.getGeocode()); } |