Skip to content

Commit 9fc21ac

Browse files
committed
Fix #687: use develop db for notes test
1 parent 7ef5ee3 commit 9fc21ac

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

app/src/main/java/net/osmtracker/osm/OpenStreetMapConstants.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,50 @@
22

33
public class OpenStreetMapConstants {
44

5-
private static final boolean DEV_MODE = false;
5+
public static boolean DEV_MODE = false;
66
private static final String OSM_API_URL_DEV = "https://master.apis.dev.openstreetmap.org";
77
private static final String OSM_API_URL_PROD = "https://www.openstreetmap.org";
8-
private static final String OSM_API_URL = (DEV_MODE) ? OSM_API_URL_DEV : OSM_API_URL_PROD;
8+
public static String OSM_API_URL = (DEV_MODE) ? OSM_API_URL_DEV : OSM_API_URL_PROD;
99

1010
public static class Api {
1111

12-
public static final String OSM_API_URL_PATH = OSM_API_URL + "/api/0.6/";
12+
public static String OSM_API_URL_PATH = OSM_API_URL + "/api/0.6/";
1313

1414
}
1515

1616
public static class OAuth2 {
1717
public static final String CLIENT_ID_PROD = "6s8TuIQoPeq89ZWUFOXU7EZ-ZaCUVtUoNZFIKCMdU-E";
1818
public static final String CLIENT_ID_DEV = "94Ht-oVBJ2spydzfk18s1RV2z7NS98SBwMfzSCqLQLE"; // DEV
1919

20-
public static final String CLIENT_ID = (DEV_MODE) ? CLIENT_ID_DEV : CLIENT_ID_PROD;
20+
public static String CLIENT_ID = (DEV_MODE) ? CLIENT_ID_DEV : CLIENT_ID_PROD;
2121

2222
public static final String SCOPE = "write_gpx write_notes";
2323
public static final String USER_AGENT = "OSMTracker for Android™";
2424

2525
public static class Urls {
26-
public static final String AUTHORIZATION_ENDPOINT = OSM_API_URL + "/oauth2/authorize";
27-
public static final String TOKEN_ENDPOINT = OSM_API_URL + "/oauth2/token";
26+
public static String AUTHORIZATION_ENDPOINT = OSM_API_URL + "/oauth2/authorize";
27+
public static String TOKEN_ENDPOINT = OSM_API_URL + "/oauth2/token";
2828
}
2929

3030
}
3131

32+
/**
33+
* Updates the environment mode and refreshes dependent URL paths.
34+
*
35+
* @param enabled True for Dev/Master API, False for Production
36+
*/
37+
public static void setDevelopmentMode(boolean enabled) {
38+
DEV_MODE = enabled;
39+
OSM_API_URL = (DEV_MODE) ? OSM_API_URL_DEV : OSM_API_URL_PROD;
40+
41+
// Update the nested Api class variable
42+
Api.OSM_API_URL_PATH = OSM_API_URL + "/api/0.6/";
43+
44+
// Update OAuth2 constants as well to ensure total environment consistency
45+
OAuth2.Urls.AUTHORIZATION_ENDPOINT = OSM_API_URL + "/oauth2/authorize";
46+
OAuth2.Urls.TOKEN_ENDPOINT = OSM_API_URL + "/oauth2/token";
47+
OAuth2.CLIENT_ID = (DEV_MODE) ? OAuth2.CLIENT_ID_DEV : OAuth2.CLIENT_ID_PROD;
48+
}
49+
3250

3351
}

app/src/main/java/net/osmtracker/osm/UploadToOpenStreetMapNotesTask.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public void run() {
7272
// 1. Prepare UI (Equivalent to onPreExecute)
7373
activity.runOnUiThread(() -> progressDialog = createProgressDialog(activity));
7474

75+
Log.d(TAG, "DEV_MODE=" + OpenStreetMapConstants.DEV_MODE
76+
+ ", OAuth2.USER_AGENT=" + OpenStreetMapConstants.OAuth2.USER_AGENT
77+
+ ", API_URL=" + OpenStreetMapConstants.Api.OSM_API_URL_PATH);
78+
7579
// 2. Execute Network Logic (Equivalent to doInBackground)
7680
OsmConnection osm = new OsmConnection(
7781
OpenStreetMapConstants.Api.OSM_API_URL_PATH,

app/src/test/java/net/osmtracker/activity/OpenStreetMapNotesUploadTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import net.osmtracker.OSMTracker;
1414
import net.osmtracker.R;
15+
import net.osmtracker.osm.OpenStreetMapConstants;
1516

1617
import org.junit.Assert;
1718
import org.junit.Before;
@@ -21,22 +22,26 @@
2122
import org.robolectric.RobolectricTestRunner;
2223
import org.robolectric.annotation.Config;
2324
import org.robolectric.shadows.ShadowActivity;
25+
import org.robolectric.shadows.ShadowLog;
2426

2527
@RunWith(RobolectricTestRunner.class)
26-
@Config(sdk = 25)
28+
@Config(sdk = 25, shadows = {ShadowLog.class})
2729
public class OpenStreetMapNotesUploadTest {
2830

2931
private Intent intent;
3032

3133
@Before
3234
public void setUp() {
35+
ShadowLog.stream = System.out;
36+
// Switch to Dev/Master API for this test
37+
OpenStreetMapConstants.setDevelopmentMode(true);
3338
// Prepare a valid intent with extras
3439
intent = new Intent(ApplicationProvider.getApplicationContext(),
3540
OpenStreetMapNotesUpload.class);
3641
intent.putExtra("noteId", 123L);
3742
intent.putExtra("noteContent", "Test Note Content");
38-
intent.putExtra("latitude", 45.0);
39-
intent.putExtra("longitude", 9.0);
43+
intent.putExtra("latitude", 10.034071);
44+
intent.putExtra("longitude", -84.209481);
4045
intent.putExtra("version", "3.0.1");
4146
intent.putExtra("appName", "OSMTrackerTest");
4247

0 commit comments

Comments
 (0)