Changeset 9220 in josm
- Timestamp:
- 2015-12-30T03:21:52+01:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/.classpath
r9205 r9220 18 18 <classpathentry kind="lib" path="test/lib/fest/MRJToolkitStubs-1.0.jar"/> 19 19 <classpathentry kind="lib" path="test/lib/jfcunit.jar"/> 20 <classpathentry kind="lib" path="test/lib/equalsverifier-1.7.6.jar"/> 20 21 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_80"/> 21 22 <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/> … … 24 25 <classpathentry kind="lib" path="test/lib/unitils-core/commons-logging-1.1.jar"/> 25 26 <classpathentry kind="lib" path="test/lib/unitils-core/ognl-2.6.9.jar"/> 26 <classpathentry kind="lib" path="test/lib/unitils-core/unitils-core-3. 3.jar"/>27 <classpathentry kind="lib" path="test/lib/unitils-core/unitils-core-3.4.2.jar"/> 27 28 <classpathentry kind="lib" path="test/lib/fest/debug-1.0.jar"/> 28 29 <classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/> -
trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java
r9172 r9220 14 14 15 15 /** 16 * This class manages a set of OAuth parameters.16 * This class manages an immutable set of OAuth parameters. 17 17 * @since 2747 18 18 */ … … 40 40 public static final String DEFAULT_AUTHORISE_URL = Main.getOSMWebsite() + "/oauth/authorize"; 41 41 42 43 42 /** 44 43 * Replies a set of default parameters for a consumer accessing the standard OSM server … … 61 60 */ 62 61 public static OAuthParameters createDefault(String apiUrl) { 63 OAuthParameters parameters = new OAuthParameters(); 64 parameters.setConsumerKey(DEFAULT_JOSM_CONSUMER_KEY); 65 parameters.setConsumerSecret(DEFAULT_JOSM_CONSUMER_SECRET); 66 parameters.setRequestTokenUrl(DEFAULT_REQUEST_TOKEN_URL); 67 parameters.setAccessTokenUrl(DEFAULT_ACCESS_TOKEN_URL); 68 parameters.setAuthoriseUrl(DEFAULT_AUTHORISE_URL); 62 String host = ""; 69 63 if (!OsmApi.DEFAULT_API_URL.equals(apiUrl)) { 70 64 try { 71 String host = new URL(apiUrl).getHost(); 72 if (host.endsWith("dev.openstreetmap.org")) { 73 parameters.setRequestTokenUrl(DEFAULT_REQUEST_TOKEN_URL.replace("www.openstreetmap.org", host)); 74 parameters.setAccessTokenUrl(DEFAULT_ACCESS_TOKEN_URL.replace("www.openstreetmap.org", host)); 75 parameters.setAuthoriseUrl(DEFAULT_AUTHORISE_URL.replace("www.openstreetmap.org", host)); 76 } 65 host = new URL(apiUrl).getHost(); 77 66 } catch (MalformedURLException e) { 78 67 // Ignored … … 82 71 } 83 72 } 84 return parameters; 73 boolean osmDevServer = host.endsWith("dev.openstreetmap.org"); 74 return new OAuthParameters( 75 DEFAULT_JOSM_CONSUMER_KEY, 76 DEFAULT_JOSM_CONSUMER_SECRET, 77 osmDevServer ? DEFAULT_REQUEST_TOKEN_URL.replace("www.openstreetmap.org", host) : DEFAULT_REQUEST_TOKEN_URL, 78 osmDevServer ? DEFAULT_ACCESS_TOKEN_URL.replace("www.openstreetmap.org", host) : DEFAULT_ACCESS_TOKEN_URL, 79 osmDevServer ? DEFAULT_AUTHORISE_URL.replace("www.openstreetmap.org", host) : DEFAULT_AUTHORISE_URL); 85 80 } 86 81 … … 93 88 public static OAuthParameters createFromPreferences(Preferences pref) { 94 89 OAuthParameters parameters = createDefault(pref.get("osm-server.url")); 95 parameters.setConsumerKey(pref.get("oauth.settings.consumer-key", parameters.getConsumerKey())); 96 parameters.setConsumerSecret(pref.get("oauth.settings.consumer-secret", parameters.getConsumerSecret())); 97 parameters.setRequestTokenUrl(pref.get("oauth.settings.request-token-url", parameters.getRequestTokenUrl())); 98 parameters.setAccessTokenUrl(pref.get("oauth.settings.access-token-url", parameters.getAccessTokenUrl())); 99 parameters.setAuthoriseUrl(pref.get("oauth.settings.authorise-url", parameters.getAuthoriseUrl())); 100 return parameters; 101 } 102 103 private String consumerKey; 104 private String consumerSecret; 105 private String requestTokenUrl; 106 private String accessTokenUrl; 107 private String authoriseUrl; 108 109 /** 110 * Constructs a new, unitialized, {@code OAuthParameters}. 90 return new OAuthParameters( 91 pref.get("oauth.settings.consumer-key", parameters.getConsumerKey()), 92 pref.get("oauth.settings.consumer-secret", parameters.getConsumerSecret()), 93 pref.get("oauth.settings.request-token-url", parameters.getRequestTokenUrl()), 94 pref.get("oauth.settings.access-token-url", parameters.getAccessTokenUrl()), 95 pref.get("oauth.settings.authorise-url", parameters.getAuthoriseUrl()) 96 ); 97 } 98 99 private final String consumerKey; 100 private final String consumerSecret; 101 private final String requestTokenUrl; 102 private final String accessTokenUrl; 103 private final String authoriseUrl; 104 105 /** 106 * Constructs a new {@code OAuthParameters}. 107 * @param consumerKey consumer key 108 * @param consumerSecret consumer secret 109 * @param requestTokenUrl request token URL 110 * @param accessTokenUrl access token URL 111 * @param authoriseUrl authorise URL 111 112 * 112 113 * @see #createDefault 113 114 * @see #createFromPreferences 114 */ 115 public OAuthParameters() { 116 // contents can be set later with setters 115 * @since 9220 116 */ 117 public OAuthParameters(String consumerKey, String consumerSecret, 118 String requestTokenUrl, String accessTokenUrl, String authoriseUrl) { 119 this.consumerKey = consumerKey; 120 this.consumerSecret = consumerSecret; 121 this.requestTokenUrl = requestTokenUrl; 122 this.accessTokenUrl = accessTokenUrl; 123 this.authoriseUrl = authoriseUrl; 117 124 } 118 125 … … 141 148 142 149 /** 143 * Sets the consumer key.144 * @param consumerKey The consumer key145 */146 public void setConsumerKey(String consumerKey) {147 this.consumerKey = consumerKey;148 }149 150 /**151 150 * Gets the consumer secret. 152 151 * @return The consumer secret … … 157 156 158 157 /** 159 * Sets the consumer secret.160 * @param consumerSecret The consumer secret161 */162 public void setConsumerSecret(String consumerSecret) {163 this.consumerSecret = consumerSecret;164 }165 166 /**167 158 * Gets the request token URL. 168 159 * @return The request token URL … … 173 164 174 165 /** 175 * Sets the request token URL.176 * @param requestTokenUrl the request token URL177 */178 public void setRequestTokenUrl(String requestTokenUrl) {179 this.requestTokenUrl = requestTokenUrl;180 }181 182 /**183 166 * Gets the access token URL. 184 167 * @return The access token URL … … 189 172 190 173 /** 191 * Sets the access token URL.192 * @param accessTokenUrl The access token URL193 */194 public void setAccessTokenUrl(String accessTokenUrl) {195 this.accessTokenUrl = accessTokenUrl;196 }197 198 /**199 174 * Gets the authorise URL. 200 175 * @return The authorise URL … … 202 177 public String getAuthoriseUrl() { 203 178 return authoriseUrl; 204 }205 206 /**207 * Sets the authorise URL.208 * @param authoriseUrl The authorise URL209 */210 public void setAuthoriseUrl(String authoriseUrl) {211 this.authoriseUrl = authoriseUrl;212 179 } 213 180 -
trunk/src/org/openstreetmap/josm/gui/oauth/AdvancedOAuthPropertiesPanel.java
r9075 r9220 193 193 if (cbUseDefaults.isSelected()) 194 194 return OAuthParameters.createDefault(apiUrl); 195 OAuthParameters parameters = new OAuthParameters(); 196 parameters.setConsumerKey(tfConsumerKey.getText()); 197 parameters.setConsumerSecret(tfConsumerSecret.getText()); 198 parameters.setRequestTokenUrl(tfRequestTokenURL.getText()); 199 parameters.setAccessTokenUrl(tfAccessTokenURL.getText()); 200 parameters.setAuthoriseUrl(tfAuthoriseURL.getText()); 201 return parameters; 195 return new OAuthParameters( 196 tfConsumerKey.getText(), 197 tfConsumerSecret.getText(), 198 tfRequestTokenURL.getText(), 199 tfAccessTokenURL.getText(), 200 tfAuthoriseURL.getText()); 202 201 } 203 202 -
trunk/test/unit/org/openstreetmap/josm/data/oauth/OAuthParametersTest.java
r9201 r9220 5 5 import static org.junit.Assert.assertNotEquals; 6 6 import static org.junit.Assert.assertNotNull; 7 import nl.jqno.equalsverifier.EqualsVerifier; 7 8 8 9 import org.junit.Test; 10 import org.openstreetmap.josm.Main; 9 11 import org.openstreetmap.josm.io.OsmApi; 10 12 … … 25 27 assertNotNull(dev); 26 28 assertNotEquals(def, dev); 29 Main.logLevel = 5; // enable trace for line coverage 27 30 assertEquals(def, OAuthParameters.createDefault("wrong_url")); 28 31 } 29 32 30 33 /** 31 * Unit test of method {@link OAuthParameters#equals}.34 * Unit test of methods {@link OAuthParameters#equals} and {@link OAuthParameters#hashCode}. 32 35 */ 33 36 @Test 34 public void testEquals() { 35 OAuthParameters dev = OAuthParameters.createDefault("http://master.apis.dev.openstreetmap.org/api"); 36 OAuthParameters dev2 = new OAuthParameters(dev); 37 assertEquals(dev, dev2); 37 public void equalsContract() { 38 EqualsVerifier.forClass(OAuthParameters.class).usingGetClass().verify(); 38 39 } 39 40 } -
trunk/test/unit/org/openstreetmap/josm/data/oauth/OAuthTokenTest.java
r9201 r9220 4 4 import static org.junit.Assert.assertEquals; 5 5 import static org.junit.Assert.assertNotNull; 6 import nl.jqno.equalsverifier.EqualsVerifier; 6 7 import oauth.signpost.OAuthConsumer; 7 8 … … 27 28 28 29 /** 29 * Unit test of method {@link OAuthToken#equals}.30 * Unit test of methods {@link OAuthToken#equals} and {@link OAuthToken#hashCode}. 30 31 */ 31 32 @Test 32 public void testEquals() { 33 OAuthToken tok = new OAuthToken( 34 OAuthParameters.DEFAULT_JOSM_CONSUMER_KEY, 35 OAuthParameters.DEFAULT_JOSM_CONSUMER_SECRET); 36 OAuthToken tok2 = new OAuthToken(tok); 37 assertEquals(tok, tok2); 33 public void equalsContract() { 34 EqualsVerifier.forClass(OAuthToken.class).usingGetClass().verify(); 38 35 } 39 36 }
Note:
See TracChangeset
for help on using the changeset viewer.