public static void testGetOCCache() {
   String geoCode = "OU0331";
   cgCache cache = OkapiClient.getCache(geoCode);
   assertNotNull(cache);
   assertEquals(geoCode, cache.getGeocode());
   assertEquals("Oshkosh Municipal Tank", cache.getName());
 }
  /**
   * Test {@link cgBase#parseCache(String, int) with "mocked" data
   * @param base
   */
  @MediumTest
  public void testParseCache() {
    List<MockedCache> cachesToTest = new ArrayList<MockedCache>();
    cachesToTest.add(new GC2CJPF());
    cachesToTest.add(new GC1ZXX2());

    for (MockedCache cache : cachesToTest) {
      cgCacheWrap caches = base.parseCache(cache.getData(), 0);
      cgCache cacheParsed = caches.cacheList.get(0);
      Assert.assertEquals(cacheParsed.getGeocode(), cache.getGeocode());
      Assert.assertEquals(cacheParsed.getType(), cache.getType());
      Assert.assertEquals(cacheParsed.getOwner(), cache.getOwner());
      Assert.assertEquals(cacheParsed.getDifficulty(), cache.getDifficulty());
      Assert.assertEquals(cacheParsed.getTerrain(), cache.getTerrain());
      Assert.assertEquals(cacheParsed.getLatitude(), cache.getLatitude());
      Assert.assertEquals(cacheParsed.getLongitude(), cache.getLongitude());
      Assert.assertEquals(cacheParsed.isDisabled(), cache.isDisabled());
      Assert.assertEquals(cacheParsed.isOwn(), cache.isOwn());
      Assert.assertEquals(cacheParsed.isArchived(), cache.isArchived());
      Assert.assertEquals(cacheParsed.isMembersOnly(), cache.isMembersOnly());
      Assert.assertEquals(cacheParsed.getOwnerReal(), cache.getOwnerReal());
      Assert.assertEquals(cacheParsed.getSize(), cache.getSize());
      Assert.assertEquals(cacheParsed.getHint(), cache.getHint());
      Assert.assertTrue(cacheParsed.getDescription().startsWith(cache.getDescription()));
      Assert.assertEquals(cacheParsed.getShortDescription(), cache.getShortDescription());
      Assert.assertEquals(cacheParsed.getName(), cache.getName());
    }
  }
    @Override
    protected Boolean doInBackground(Void... params) {
      // quick check for being able to write the GPX file
      if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        return false;
      }

      try {
        final File exportLocation = new File(Settings.getGpxExportDir());
        exportLocation.mkdirs();

        final SimpleDateFormat fileNameDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        exportFile =
            new File(
                Settings.getGpxExportDir()
                    + File.separatorChar
                    + "export_"
                    + fileNameDateFormat.format(new Date())
                    + ".gpx");

        gpx = new BufferedWriter(new FileWriter(exportFile));

        gpx.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        gpx.write(
            "<gpx version=\"1.0\" creator=\"c:geo - http://www.cgeo.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/0\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0/1 http://www.groundspeak.com/cache/1/0/1/cache.xsd\">");

        for (int i = 0; i < caches.size(); i++) {
          // reload the cache. otherwise logs, attributes and other detailed information is not
          // available
          final cgCache cache =
              cgeoapplication
                  .getInstance()
                  .loadCache(caches.get(i).getGeocode(), LoadFlags.LOAD_ALL_DB_ONLY);

          gpx.write("<wpt ");
          gpx.write("lat=\"");
          gpx.write(Double.toString(cache.getCoords().getLatitude()));
          gpx.write("\" ");
          gpx.write("lon=\"");
          gpx.write(Double.toString(cache.getCoords().getLongitude()));
          gpx.write("\">");

          final Date hiddenDate = cache.getHiddenDate();
          if (hiddenDate != null) {
            gpx.write("<time>");
            gpx.write(StringEscapeUtils.escapeXml(dateFormatZ.format(hiddenDate)));
            gpx.write("</time>");
          }

          gpx.write("<name>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getGeocode()));
          gpx.write("</name>");

          gpx.write("<desc>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getName()));
          gpx.write("</desc>");

          gpx.write("<url>");
          gpx.write(cache.getUrl());
          gpx.write("</url>");

          gpx.write("<urlname>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getName()));
          gpx.write("</urlname>");

          gpx.write("<sym>");
          gpx.write(cache.isFound() ? "Geocache Found" : "Geocache");
          gpx.write("</sym>");

          gpx.write("<type>");
          gpx.write(StringEscapeUtils.escapeXml("Geocache|" + cache.getType().pattern));
          gpx.write("</type>");

          gpx.write("<groundspeak:cache ");
          gpx.write("id=\"");
          gpx.write(cache.getCacheId());
          gpx.write("\" available=\"");
          gpx.write(!cache.isDisabled() ? "True" : "False");
          gpx.write("\" archived=\"");
          gpx.write(cache.isArchived() ? "True" : "False");
          gpx.write("\" ");
          gpx.write("xmlns:groundspeak=\"http://www.groundspeak.com/cache/1/0/1\">");

          gpx.write("<groundspeak:name>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getName()));
          gpx.write("</groundspeak:name>");

          gpx.write("<groundspeak:placed_by>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getOwnerDisplayName()));
          gpx.write("</groundspeak:placed_by>");

          gpx.write("<groundspeak:owner>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getOwnerUserId()));
          gpx.write("</groundspeak:owner>");

          gpx.write("<groundspeak:type>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getType().pattern));
          gpx.write("</groundspeak:type>");

          gpx.write("<groundspeak:container>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getSize().id));
          gpx.write("</groundspeak:container>");

          writeAttributes(cache);

          gpx.write("<groundspeak:difficulty>");
          gpx.write(Float.toString(cache.getDifficulty()));
          gpx.write("</groundspeak:difficulty>");

          gpx.write("<groundspeak:terrain>");
          gpx.write(Float.toString(cache.getTerrain()));
          gpx.write("</groundspeak:terrain>");

          gpx.write("<groundspeak:country>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getLocation()));
          gpx.write("</groundspeak:country>");

          gpx.write(
              "<groundspeak:state></groundspeak:state>"); // c:geo cannot manage 2 separate fields,
                                                          // so we export as country

          gpx.write("<groundspeak:short_description html=\"");
          gpx.write(BaseUtils.containsHtml(cache.getShortDescription()) ? "True" : "False");
          gpx.write("\">");
          gpx.write(StringEscapeUtils.escapeXml(cache.getShortDescription()));
          gpx.write("</groundspeak:short_description>");

          gpx.write("<groundspeak:long_description html=\"");
          gpx.write(BaseUtils.containsHtml(cache.getDescription()) ? "True" : "False");
          gpx.write("\">");
          gpx.write(StringEscapeUtils.escapeXml(cache.getDescription()));
          gpx.write("</groundspeak:long_description>");

          gpx.write("<groundspeak:encoded_hints>");
          gpx.write(StringEscapeUtils.escapeXml(cache.getHint()));
          gpx.write("</groundspeak:encoded_hints>");

          writeLogs(cache);

          gpx.write("</groundspeak:cache>");

          gpx.write("</wpt>");

          writeWaypoints(cache);

          publishProgress(i + 1);
        }

        gpx.write("</gpx>");

        gpx.close();
      } catch (Exception e) {
        Log.e("GpxExport.ExportTask export", e);

        if (gpx != null) {
          try {
            gpx.close();
          } catch (IOException ee) {
          }
        }

        // delete partial gpx file on error
        if (exportFile.exists()) {
          exportFile.delete();
        }

        return false;
      }

      return true;
    }