aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/connector/opencaching/OCXMLTest.java
blob: ca2e3029e0f5d1238ba8e7fbcb2468f700be0d61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package cgeo.geocaching.connector.opencaching;

import cgeo.CGeoTestCase;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.Settings;
import cgeo.geocaching.connector.oc.OCXMLClient;
import cgeo.geocaching.enumerations.CacheType;

import java.util.Collection;

public class OCXMLTest extends CGeoTestCase {

    public static void testOCGetCache() {
        final String geoCode = "OCDE76";

        final Geocache cache = OCXMLClient.getCache(geoCode);
        assertNotNull(cache);
        assertEquals(geoCode, cache.getGeocode());
        assertEquals("Gitarrenspielplatz", cache.getName());
        assertEquals(CacheType.TRADITIONAL, cache.getType());
        assertEquals(2.0, cache.getDifficulty(), 0.1);
        assertEquals(2.0, cache.getTerrain(), 0.1);
    }

    public static void testOCLogAttendedAsFound() {

        final String oldOCName = Settings.getOCConnectorUserName();
        try {
            Settings.setOCConnectorUserName("ra_sch");
            final String geoCode = "OCD541";
            final Geocache cache = OCXMLClient.getCache(geoCode);
            assertNotNull(cache);

            assertTrue(cache.isFound());
        } finally {
            Settings.setOCConnectorUserName(oldOCName);
        }
    }

    public static void testOCOwner() {
        final String oldOCName = Settings.getOCConnectorUserName();
        try {
            Settings.setOCConnectorUserName("andi12.2");
            final String geoCode = "OCC9BE";
            final Geocache cache = OCXMLClient.getCache(geoCode);
            assertNotNull(cache);

            assertTrue(cache.isOwner());
            assertEquals("180571", cache.getOwnerUserId());
        } finally {
            Settings.setOCConnectorUserName(oldOCName);
        }
    }

    public static void testOC0537Description() {
        final String geoCode = "OC0537";
        final Geocache cache = OCXMLClient.getCache(geoCode);
        assertNotNull(cache);

        assertFalse(cache.getDescription().length() < 100);
    }

    public static void testNoArchivedInNearby() {

        final boolean oldExcludeDisabled = Settings.isExcludeDisabledCaches();
        final boolean oldExcludeMine = Settings.isExcludeMyCaches();
        try {
            Settings.setExcludeDisabledCaches(false);
            Settings.setExcludeMine(false);
            // get an archived cache
            final Geocache cache = OCXMLClient.getCache("OCD541");
            assertNotNull(cache);
            assertTrue(cache.isArchived());
            // Get nearby for this cache
            final Collection<Geocache> caches = OCXMLClient.getCachesAround(cache.getCoords(), 0.5);
            // Should not be in the result!
            assertFalse(caches.contains(cache));
        } finally {
            Settings.setExcludeDisabledCaches(oldExcludeDisabled);
            Settings.setExcludeMine(oldExcludeMine);
        }
    }
}