Ejemplo n.º 1
0
 public static void testGetOCCache() {
   final String geoCode = "OU0331";
   Geocache cache = OkapiClient.getCache(geoCode);
   assertThat(cache).as("Cache from OKAPI").isNotNull();
   assertEquals("Unexpected geo code", geoCode, cache.getGeocode());
   assertThat(cache.getName()).isEqualTo("Oshkosh Municipal Tank");
   assertThat(cache.isDetailed()).isTrue();
   // cache should be stored to DB (to listID 0) when loaded above
   cache = DataStore.loadCache(geoCode, LoadFlags.LOAD_ALL_DB_ONLY);
   assert cache != null;
   assertThat(cache).isNotNull();
   assertThat(cache.getGeocode()).isEqualTo(geoCode);
   assertThat(cache.getName()).isEqualTo("Oshkosh Municipal Tank");
   assertThat(cache.isDetailed()).isTrue();
   assertThat(cache.getOwnerDisplayName()).isNotEmpty();
   assertThat(cache.getOwnerUserId()).isEqualTo(cache.getOwnerDisplayName());
 }
Ejemplo n.º 2
0
 public static void testOCSearchMustWorkWithoutOAuthAccessTokens() {
   final String geoCode = "OC1234";
   final Geocache cache = OkapiClient.getCache(geoCode);
   assertThat(cache)
       .overridingErrorMessage(
           "You must have a valid OKAPI key installed for running this test (but you do not need to set credentials in the app).")
       .isNotNull();
   assertThat(cache.getName()).isEqualTo("Wupper-Schein");
 }
Ejemplo n.º 3
0
  /**
   * This method constructs a <code>Point</code> for displaying in Locus
   *
   * @param cache
   * @param withWaypoints whether to give waypoints to Locus or not
   * @param withCacheDetails whether to give cache details (description, hint) to Locus or not
   *     should be false for all if more then 200 Caches are transferred
   * @return null, when the <code>Point</code> could not be constructed
   */
  private static Point getCachePoint(
      Geocache cache, boolean withWaypoints, boolean withCacheDetails) {
    if (cache == null || cache.getCoords() == null) {
      return null;
    }

    // create one simple point with location
    final Location loc = new Location("cgeo");
    loc.setLatitude(cache.getCoords().getLatitude());
    loc.setLongitude(cache.getCoords().getLongitude());

    final Point p = new Point(cache.getName(), loc);
    final PointGeocachingData pg = new PointGeocachingData();
    p.setGeocachingData(pg);

    // set data in Locus' cache
    pg.cacheID = cache.getGeocode();
    pg.available = !cache.isDisabled();
    pg.archived = cache.isArchived();
    pg.premiumOnly = cache.isPremiumMembersOnly();
    pg.name = cache.getName();
    pg.placedBy = cache.getOwnerDisplayName();
    final Date hiddenDate = cache.getHiddenDate();
    if (hiddenDate != null) {
      pg.hidden = ISO8601DATE.format(hiddenDate);
    }
    int locusId = toLocusType(cache.getType());
    if (locusId != NO_LOCUS_ID) {
      pg.type = locusId;
    }
    locusId = toLocusSize(cache.getSize());
    if (locusId != NO_LOCUS_ID) {
      pg.container = locusId;
    }
    if (cache.getDifficulty() > 0) {
      pg.difficulty = cache.getDifficulty();
    }
    if (cache.getTerrain() > 0) {
      pg.terrain = cache.getTerrain();
    }
    pg.found = cache.isFound();

    if (withWaypoints && cache.hasWaypoints()) {
      pg.waypoints = new ArrayList<>();
      for (Waypoint waypoint : cache.getWaypoints()) {
        if (waypoint == null || waypoint.getCoords() == null) {
          continue;
        }
        PointGeocachingDataWaypoint wp = new PointGeocachingDataWaypoint();
        wp.code = waypoint.getGeocode();
        wp.name = waypoint.getName();
        String locusWpId = toLocusWaypoint(waypoint.getWaypointType());
        if (locusWpId != null) {
          wp.type = locusWpId;
        }
        wp.lat = waypoint.getCoords().getLatitude();
        wp.lon = waypoint.getCoords().getLongitude();
        pg.waypoints.add(wp);
      }
    }

    // Other properties of caches. When there are many caches to be displayed
    // in Locus, using these properties can lead to Exceptions in Locus.
    // Should not be used if caches count > 200

    if (withCacheDetails) {
      pg.shortDescription = cache.getShortDescription();
      pg.longDescription = cache.getDescription();
      pg.encodedHints = cache.getHint();
    }

    return p;
  }