Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions app/src/main/java/net/osmtracker/osm/OpenStreetMapConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,50 @@

public class OpenStreetMapConstants {

private static final boolean DEV_MODE = false;
public static boolean DEV_MODE = false;
private static final String OSM_API_URL_DEV = "https://master.apis.dev.openstreetmap.org";
private static final String OSM_API_URL_PROD = "https://www.openstreetmap.org";
private static final String OSM_API_URL = (DEV_MODE) ? OSM_API_URL_DEV : OSM_API_URL_PROD;
public static String OSM_API_URL = (DEV_MODE) ? OSM_API_URL_DEV : OSM_API_URL_PROD;

public static class Api {

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

}

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

public static final String CLIENT_ID = (DEV_MODE) ? CLIENT_ID_DEV : CLIENT_ID_PROD;
public static String CLIENT_ID = (DEV_MODE) ? CLIENT_ID_DEV : CLIENT_ID_PROD;

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

public static class Urls {
public static final String AUTHORIZATION_ENDPOINT = OSM_API_URL + "/oauth2/authorize";
public static final String TOKEN_ENDPOINT = OSM_API_URL + "/oauth2/token";
public static String AUTHORIZATION_ENDPOINT = OSM_API_URL + "/oauth2/authorize";
public static String TOKEN_ENDPOINT = OSM_API_URL + "/oauth2/token";
}

}

/**
* Updates the environment mode and refreshes dependent URL paths.
*
* @param enabled True for Dev/Master API, False for Production
*/
public static void setDevelopmentMode(boolean enabled) {
DEV_MODE = enabled;
OSM_API_URL = (DEV_MODE) ? OSM_API_URL_DEV : OSM_API_URL_PROD;

// Update the nested Api class variable
Api.OSM_API_URL_PATH = OSM_API_URL + "/api/0.6/";

// Update OAuth2 constants as well to ensure total environment consistency
OAuth2.Urls.AUTHORIZATION_ENDPOINT = OSM_API_URL + "/oauth2/authorize";
OAuth2.Urls.TOKEN_ENDPOINT = OSM_API_URL + "/oauth2/token";
OAuth2.CLIENT_ID = (DEV_MODE) ? OAuth2.CLIENT_ID_DEV : OAuth2.CLIENT_ID_PROD;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public void run() {
// 1. Prepare UI (Equivalent to onPreExecute)
activity.runOnUiThread(() -> progressDialog = createProgressDialog(activity));

Log.d(TAG, "DEV_MODE=" + OpenStreetMapConstants.DEV_MODE
+ ", OAuth2.USER_AGENT=" + OpenStreetMapConstants.OAuth2.USER_AGENT
+ ", API_URL=" + OpenStreetMapConstants.Api.OSM_API_URL_PATH);

// 2. Execute Network Logic (Equivalent to doInBackground)
OsmConnection osm = new OsmConnection(
OpenStreetMapConstants.Api.OSM_API_URL_PATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.osm.OpenStreetMapConstants;

import org.junit.Assert;
import org.junit.Before;
Expand All @@ -21,22 +22,26 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;
import org.robolectric.shadows.ShadowLog;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 25)
@Config(sdk = 25, shadows = {ShadowLog.class})
public class OpenStreetMapNotesUploadTest {

private Intent intent;

@Before
public void setUp() {
ShadowLog.stream = System.out;
// Switch to Dev/Master API for this test
OpenStreetMapConstants.setDevelopmentMode(true);
// Prepare a valid intent with extras
intent = new Intent(ApplicationProvider.getApplicationContext(),
OpenStreetMapNotesUpload.class);
intent.putExtra("noteId", 123L);
intent.putExtra("noteContent", "Test Note Content");
intent.putExtra("latitude", 45.0);
intent.putExtra("longitude", 9.0);
intent.putExtra("latitude", 10.034071);
intent.putExtra("longitude", -84.209481);
intent.putExtra("version", "3.0.1");
intent.putExtra("appName", "OSMTrackerTest");

Expand Down